lite-bootstrap 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lite_bootstrap/__init__.py +0 -0
- lite_bootstrap/fastapi_bootstrap.py +34 -0
- lite_bootstrap/opentelemetry_bootstrap.py +46 -0
- lite_bootstrap/py.typed +0 -0
- lite_bootstrap/sentry_bootstrap.py +32 -0
- lite_bootstrap-0.1.0.dist-info/METADATA +46 -0
- lite_bootstrap-0.1.0.dist-info/RECORD +8 -0
- lite_bootstrap-0.1.0.dist-info/WHEEL +4 -0
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
|
|
3
|
+
import fastapi
|
|
4
|
+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
5
|
+
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
|
6
|
+
|
|
7
|
+
from lite_bootstrap.opentelemetry_bootstrap import OpenTelemetryBootstrap
|
|
8
|
+
from lite_bootstrap.sentry_bootstrap import SentryBootstrap
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclasses.dataclass(kw_only=True, slots=True)
|
|
12
|
+
class FastAPIBootstrap:
|
|
13
|
+
app: fastapi.FastAPI
|
|
14
|
+
opentelemetry: OpenTelemetryBootstrap
|
|
15
|
+
sentry: SentryBootstrap
|
|
16
|
+
opentelemetry_excluded_urls: list[str] = dataclasses.field(default_factory=list)
|
|
17
|
+
|
|
18
|
+
def bootstrap_init(self) -> None:
|
|
19
|
+
if self.sentry.sentry_dsn:
|
|
20
|
+
self.sentry.start_tracing()
|
|
21
|
+
self.app.add_middleware(SentryAsgiMiddleware)
|
|
22
|
+
|
|
23
|
+
self.opentelemetry.start_tracing()
|
|
24
|
+
if self.opentelemetry.endpoint:
|
|
25
|
+
FastAPIInstrumentor.instrument_app(
|
|
26
|
+
app=self.app,
|
|
27
|
+
tracer_provider=self.opentelemetry.tracer_provider,
|
|
28
|
+
excluded_urls=",".join(self.opentelemetry_excluded_urls),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def teardown(self) -> None:
|
|
32
|
+
self.opentelemetry.teardown()
|
|
33
|
+
if self.opentelemetry.endpoint:
|
|
34
|
+
FastAPIInstrumentor.uninstrument_app(self.app)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
|
|
3
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
4
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined]
|
|
5
|
+
from opentelemetry.sdk import resources
|
|
6
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
7
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
8
|
+
from opentelemetry.trace import set_tracer_provider
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclasses.dataclass(kw_only=True, slots=True)
|
|
12
|
+
class OpenTelemetryBootstrap:
|
|
13
|
+
endpoint: str
|
|
14
|
+
service_name: str
|
|
15
|
+
instruments: list[BaseInstrumentor] = dataclasses.field(default_factory=list)
|
|
16
|
+
tracer_provider: TracerProvider | None = dataclasses.field(init=False)
|
|
17
|
+
|
|
18
|
+
def start_tracing(self) -> None:
|
|
19
|
+
if not self.endpoint:
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
self.tracer_provider: TracerProvider = TracerProvider(
|
|
23
|
+
resource=resources.Resource.create({resources.SERVICE_NAME: self.service_name}),
|
|
24
|
+
)
|
|
25
|
+
self.tracer_provider.add_span_processor(
|
|
26
|
+
BatchSpanProcessor(
|
|
27
|
+
OTLPSpanExporter(
|
|
28
|
+
endpoint=self.endpoint,
|
|
29
|
+
insecure=True,
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
for instrument in self.instruments:
|
|
35
|
+
instrument.instrument(
|
|
36
|
+
tracer_provider=self.tracer_provider,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
set_tracer_provider(self.tracer_provider)
|
|
40
|
+
|
|
41
|
+
def teardown(self) -> None:
|
|
42
|
+
if not self.endpoint:
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
for instrument in self.instruments:
|
|
46
|
+
instrument.uninstrument()
|
lite_bootstrap/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
import typing
|
|
3
|
+
|
|
4
|
+
import sentry_sdk
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclasses.dataclass(kw_only=True, slots=True)
|
|
8
|
+
class SentryBootstrap:
|
|
9
|
+
sentry_dsn: str
|
|
10
|
+
environment: str | None = None
|
|
11
|
+
release: str | None = None
|
|
12
|
+
max_breadcrumbs: int = 15
|
|
13
|
+
attach_stacktrace: bool = True
|
|
14
|
+
default_integrations: bool = True
|
|
15
|
+
sentry_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
|
|
16
|
+
tags: dict[str, str] | None = None
|
|
17
|
+
|
|
18
|
+
def start_tracing(self) -> None:
|
|
19
|
+
if not self.sentry_dsn:
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
sentry_sdk.init(
|
|
23
|
+
dsn=self.sentry_dsn,
|
|
24
|
+
environment=self.environment,
|
|
25
|
+
max_breadcrumbs=self.max_breadcrumbs,
|
|
26
|
+
attach_stacktrace=self.attach_stacktrace,
|
|
27
|
+
default_integrations=self.default_integrations,
|
|
28
|
+
release=self.release,
|
|
29
|
+
**self.sentry_params,
|
|
30
|
+
)
|
|
31
|
+
tags: dict[str, str] = self.tags or {}
|
|
32
|
+
sentry_sdk.set_tags(tags)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: lite-bootstrap
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lite package for bootstrapping new microservices
|
|
5
|
+
Project-URL: repository, https://github.com/modern-python/lite-bootstrap
|
|
6
|
+
Author-email: Artur Shiriev <me@shiriev.ru>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Keywords: bootstrap,error-tracing,fastapi,microservice,opentelemetry,python,sentry
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: <4,>=3.10
|
|
15
|
+
Provides-Extra: fastapi
|
|
16
|
+
Requires-Dist: fastapi; extra == 'fastapi'
|
|
17
|
+
Requires-Dist: opentelemetry-api; extra == 'fastapi'
|
|
18
|
+
Requires-Dist: opentelemetry-exporter-otlp; extra == 'fastapi'
|
|
19
|
+
Requires-Dist: opentelemetry-instrumentation; extra == 'fastapi'
|
|
20
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'fastapi'
|
|
21
|
+
Requires-Dist: opentelemetry-sdk; extra == 'fastapi'
|
|
22
|
+
Requires-Dist: sentry-sdk; extra == 'fastapi'
|
|
23
|
+
Provides-Extra: tracing
|
|
24
|
+
Requires-Dist: opentelemetry-api; extra == 'tracing'
|
|
25
|
+
Requires-Dist: opentelemetry-exporter-otlp; extra == 'tracing'
|
|
26
|
+
Requires-Dist: opentelemetry-instrumentation; extra == 'tracing'
|
|
27
|
+
Requires-Dist: opentelemetry-sdk; extra == 'tracing'
|
|
28
|
+
Requires-Dist: sentry-sdk; extra == 'tracing'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
Lite-Bootstrap package
|
|
32
|
+
==
|
|
33
|
+
[](https://codecov.io/gh/modern-python/lite-bootstrap)
|
|
34
|
+
[](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)
|
|
35
|
+
[](https://pypi.python.org/pypi/lite-bootstrap)
|
|
36
|
+
[](https://pypistats.org/packages/lite-bootstrap)
|
|
37
|
+
[](https://github.com/modern-python/lite-bootstrap/stargazers)
|
|
38
|
+
|
|
39
|
+
This package helps to build new microservices
|
|
40
|
+
|
|
41
|
+
## Quickstart:
|
|
42
|
+
### Installation
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ pip install lite-bootstrap
|
|
46
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
lite_bootstrap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
lite_bootstrap/fastapi_bootstrap.py,sha256=0s8h9nPhevd2S0_chCi5UIXj5oWxwF1pj_qVpNePiaw,1217
|
|
3
|
+
lite_bootstrap/opentelemetry_bootstrap.py,sha256=rBZmjdiScJ41bDEN5K4CTERETb1mY1d7W_yQQemBOBY,1544
|
|
4
|
+
lite_bootstrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
lite_bootstrap/sentry_bootstrap.py,sha256=gM7E4kYYwhzm2iCwB7KKipAhTCFHUV3HIwggKr-qSUk,950
|
|
6
|
+
lite_bootstrap-0.1.0.dist-info/METADATA,sha256=GFKHDR6pX4-xPN_HJN257EXjK14ZsB8EjOr_nGwHHUY,2207
|
|
7
|
+
lite_bootstrap-0.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
8
|
+
lite_bootstrap-0.1.0.dist-info/RECORD,,
|