microbootstrap 1.5.1__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.1 → microbootstrap-1.5.2}/PKG-INFO +1 -1
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/faststream.py +37 -1
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/middlewares/fastapi.py +1 -4
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/pyproject.toml +1 -1
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/pyproject.toml.orig +1 -1
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/README.md +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/__init__.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/__init__.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/base.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/fastapi.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/fastmcp.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/bootstrappers/litestar.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/config/__init__.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/config/fastapi.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/config/fastmcp.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/config/faststream.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/config/litestar.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/console_writer.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/exceptions.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/granian_server.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/helpers.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/__init__.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/base.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/cors_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/health_checks_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/instrument_box.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/logging_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/opentelemetry_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/prometheus_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/pyroscope_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/sentry_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/swagger_instrument.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments_setupper.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/middlewares/__init__.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/middlewares/fastmcp.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/middlewares/litestar.py +0 -0
- {microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/py.typed +0 -0
- {microbootstrap-1.5.1 → 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
|
|
@@ -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
|
|
|
@@ -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
|
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/health_checks_instrument.py
RENAMED
|
File without changes
|
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/logging_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/opentelemetry_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/prometheus_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/pyroscope_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.1 → microbootstrap-1.5.2}/microbootstrap/instruments/sentry_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-1.5.1 → 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
|