Instrument the API, the relay and the worker
Start the telemetry in create_app, which gunicorn runs in every worker after fork because preload_app is off, and in the relay and worker processes with their own service names, and stop it after the rest of the shutdown within TELEMETRY_SHUTDOWN_SECONDS. The API gets server spans and the http.server.request.duration histogram in seconds from the FastAPI instrumentation with stable HTTP semantic conventions, without /health probes and without the internal send and receive spans, and the request pipeline puts X-Request-Id on the server span as messenger.request_id. The worker broker gets the FastStream RabbitTelemetryMiddleware, so every delivery runs inside a consumer span. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e2ec3fe9af
commit
a8836ce8b5
@@ -38,7 +38,9 @@ from messenger.shared.entrypoints import errors, health
|
||||
from messenger.shared.entrypoints.config import TransportSettings
|
||||
from messenger.shared.entrypoints.ioc import PlatformProvider
|
||||
from messenger.shared.entrypoints.pipeline import RequestPipeline
|
||||
from messenger.shared.entrypoints.telemetry import instrument_http
|
||||
from messenger.shared.infrastructure.logging import PLATFORM_FIELDS, StructlogLogger
|
||||
from messenger.shared.infrastructure.telemetry import start_telemetry
|
||||
|
||||
TRANSPORT_FIELDS = frozenset({"dropped_total", "queue", "instance"})
|
||||
|
||||
@@ -106,6 +108,7 @@ def create_app(
|
||||
messaging = messaging or MessagingSettings()
|
||||
attachments = attachments or AttachmentsSettings()
|
||||
logger = StructlogLogger(level=platform.log_level, allowed_fields=LOG_FIELDS)
|
||||
telemetry = start_telemetry(platform, LOG_FIELDS, "messenger-api")
|
||||
container = make_async_container(
|
||||
PlatformProvider(platform, logger),
|
||||
IdentityProvider(identity),
|
||||
@@ -131,6 +134,8 @@ def create_app(
|
||||
await bus.stop()
|
||||
await container.close()
|
||||
logger.info("service.stopped")
|
||||
if telemetry is not None:
|
||||
telemetry.shutdown(platform.telemetry_shutdown_seconds)
|
||||
|
||||
app = FastAPI(
|
||||
title="MTUSI Messenger",
|
||||
@@ -158,5 +163,7 @@ def create_app(
|
||||
app.include_router(uploads_router)
|
||||
app.include_router(attachments_router)
|
||||
setup_dishka(container, app)
|
||||
if telemetry is not None:
|
||||
instrument_http(app)
|
||||
app.state.sweeper = sweeper
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user