microbootstrap 1.5.0__tar.gz → 1.5.2__tar.gz
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.
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/PKG-INFO +1 -1
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/__init__.py +2 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/faststream.py +37 -1
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/opentelemetry_instrument.py +21 -1
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/middlewares/fastapi.py +1 -4
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/pyproject.toml +1 -1
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/pyproject.toml.orig +1 -1
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/README.md +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/__init__.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/base.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/fastapi.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/fastmcp.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/litestar.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/config/__init__.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/config/fastapi.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/config/fastmcp.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/config/faststream.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/config/litestar.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/console_writer.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/exceptions.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/granian_server.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/helpers.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/__init__.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/base.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/cors_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/health_checks_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/instrument_box.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/logging_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/prometheus_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/pyroscope_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/sentry_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/swagger_instrument.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments_setupper.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/middlewares/__init__.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/middlewares/fastmcp.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/middlewares/litestar.py +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/py.typed +0 -0
- {microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/settings.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: microbootstrap
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.2
|
|
4
4
|
Summary: Package for bootstrapping new micro-services
|
|
5
5
|
Keywords: python,microservice,bootstrap,opentelemetry,logging,error-tracing,litestar,fastapi,fastmcp,mcp
|
|
6
6
|
Author: community-of-python
|
|
@@ -5,6 +5,7 @@ from microbootstrap.instruments.opentelemetry_instrument import (
|
|
|
5
5
|
FastStreamOpentelemetryConfig,
|
|
6
6
|
FastStreamTelemetryMiddlewareProtocol,
|
|
7
7
|
OpentelemetryConfig,
|
|
8
|
+
opentelemetry_baggage_scope,
|
|
8
9
|
)
|
|
9
10
|
from microbootstrap.instruments.prometheus_instrument import (
|
|
10
11
|
FastApiPrometheusConfig,
|
|
@@ -45,4 +46,5 @@ __all__ = (
|
|
|
45
46
|
"PyroscopeConfig",
|
|
46
47
|
"SentryConfig",
|
|
47
48
|
"SwaggerConfig",
|
|
49
|
+
"opentelemetry_baggage_scope",
|
|
48
50
|
)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
import functools
|
|
2
3
|
import json
|
|
3
4
|
import typing
|
|
4
5
|
|
|
5
6
|
import prometheus_client
|
|
7
|
+
import sentry_sdk
|
|
6
8
|
import structlog
|
|
7
9
|
import typing_extensions
|
|
8
10
|
from faststream._internal.logger.logger_proxy import RealLoggerObject
|
|
@@ -26,6 +28,29 @@ from microbootstrap.settings import FastStreamSettings
|
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
tracer: typing.Final = trace.get_tracer(__name__)
|
|
31
|
+
MessageT = typing.TypeVar("MessageT")
|
|
32
|
+
ResponseT = typing.TypeVar("ResponseT")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _with_sentry_isolation_scope(
|
|
36
|
+
process_message: typing.Callable[[MessageT], typing.Awaitable[ResponseT]],
|
|
37
|
+
) -> typing.Callable[[MessageT], typing.Awaitable[ResponseT]]:
|
|
38
|
+
@functools.wraps(process_message)
|
|
39
|
+
async def isolated_process_message(message: MessageT) -> ResponseT:
|
|
40
|
+
with sentry_sdk.isolation_scope():
|
|
41
|
+
return await process_message(message)
|
|
42
|
+
|
|
43
|
+
return isolated_process_message
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _isolate_faststream_subscribers(application: AsgiFastStream) -> None:
|
|
47
|
+
for broker in application.brokers:
|
|
48
|
+
for subscriber in broker.subscribers:
|
|
49
|
+
object.__setattr__(
|
|
50
|
+
subscriber,
|
|
51
|
+
"process_message",
|
|
52
|
+
_with_sentry_isolation_scope(subscriber.process_message),
|
|
53
|
+
)
|
|
29
54
|
|
|
30
55
|
|
|
31
56
|
class KwargsAsgiFastStream(AsgiFastStream):
|
|
@@ -51,7 +76,18 @@ class FastStreamBootstrapper(ApplicationBootstrapper[FastStreamSettings, AsgiFas
|
|
|
51
76
|
}
|
|
52
77
|
|
|
53
78
|
|
|
54
|
-
FastStreamBootstrapper.use_instrument()
|
|
79
|
+
@FastStreamBootstrapper.use_instrument()
|
|
80
|
+
class FastStreamSentryInstrument(SentryInstrument):
|
|
81
|
+
def bootstrap_after(self, application: AsgiFastStream) -> AsgiFastStream: # type: ignore[override]
|
|
82
|
+
# FastStream logs handler errors after custom broker middlewares exit, so the isolation scope
|
|
83
|
+
# must enclose the subscriber's complete processing lifecycle.
|
|
84
|
+
if application.brokers:
|
|
85
|
+
_isolate_faststream_subscribers(application)
|
|
86
|
+
else:
|
|
87
|
+
application.on_startup(functools.partial(_isolate_faststream_subscribers, application))
|
|
88
|
+
return application
|
|
89
|
+
|
|
90
|
+
|
|
55
91
|
FastStreamBootstrapper.use_instrument()(PyroscopeInstrument)
|
|
56
92
|
|
|
57
93
|
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/opentelemetry_instrument.py
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
import contextlib
|
|
2
3
|
import dataclasses
|
|
3
4
|
import logging
|
|
4
5
|
import os
|
|
@@ -6,7 +7,7 @@ import typing
|
|
|
6
7
|
|
|
7
8
|
import pydantic
|
|
8
9
|
import structlog
|
|
9
|
-
from opentelemetry import baggage
|
|
10
|
+
from opentelemetry import baggage, context
|
|
10
11
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
11
12
|
from opentelemetry.instrumentation.dependencies import DependencyConflictError
|
|
12
13
|
from opentelemetry.instrumentation.environment_variables import OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
|
|
@@ -39,6 +40,25 @@ if typing.TYPE_CHECKING:
|
|
|
39
40
|
OpentelemetryConfigT = typing.TypeVar("OpentelemetryConfigT", bound="OpentelemetryConfig")
|
|
40
41
|
|
|
41
42
|
|
|
43
|
+
@contextlib.contextmanager
|
|
44
|
+
def opentelemetry_baggage_scope(
|
|
45
|
+
baggage_values: typing.Mapping[str, object | None],
|
|
46
|
+
) -> typing.Iterator[None]:
|
|
47
|
+
baggage_context = context.get_current()
|
|
48
|
+
for key, value in baggage_values.items():
|
|
49
|
+
baggage_context = (
|
|
50
|
+
baggage.set_baggage(key, value, context=baggage_context)
|
|
51
|
+
if value is not None
|
|
52
|
+
else baggage.remove_baggage(key, context=baggage_context)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
token: typing.Final = context.attach(baggage_context)
|
|
56
|
+
try:
|
|
57
|
+
yield
|
|
58
|
+
finally:
|
|
59
|
+
context.detach(token)
|
|
60
|
+
|
|
61
|
+
|
|
42
62
|
@dataclasses.dataclass()
|
|
43
63
|
class OpenTelemetryInstrumentor:
|
|
44
64
|
instrumentor: BaseInstrumentor
|
|
@@ -26,10 +26,7 @@ def build_fastapi_logging_middleware(
|
|
|
26
26
|
return await call_next(request)
|
|
27
27
|
|
|
28
28
|
start_time: typing.Final = time.perf_counter_ns()
|
|
29
|
-
|
|
30
|
-
response = await call_next(request)
|
|
31
|
-
except Exception: # noqa: BLE001
|
|
32
|
-
response = fastapi.Response(status_code=500)
|
|
29
|
+
response = await call_next(request)
|
|
33
30
|
|
|
34
31
|
fill_log_message(
|
|
35
32
|
"exception" if response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR else "info",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/health_checks_instrument.py
RENAMED
|
File without changes
|
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/logging_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/prometheus_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/pyroscope_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/sentry_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.0 → microbootstrap-1.5.2}/microbootstrap/instruments/swagger_instrument.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|