File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
packages/service-library/src/servicelib/fastapi Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1313from opentelemetry .instrumentation .fastapi import FastAPIInstrumentor
1414from opentelemetry .instrumentation .httpx import HTTPXClientInstrumentor
1515from opentelemetry .sdk .resources import Resource
16- from opentelemetry .sdk .trace import TracerProvider
16+ from opentelemetry .sdk .trace import SpanProcessor , TracerProvider
1717from opentelemetry .sdk .trace .export import BatchSpanProcessor
1818from servicelib .logging_utils import log_context
1919from servicelib .tracing import get_trace_id_header
7272 HAS_AIOPIKA_INSTRUMENTOR = False
7373
7474
75+ def _create_span_processor (tracing_destination : str ) -> SpanProcessor :
76+ otlp_exporter = OTLPSpanExporterHTTP (endpoint = tracing_destination )
77+ return BatchSpanProcessor (otlp_exporter )
78+
79+
7580def _startup (tracing_settings : TracingSettings , service_name : str ) -> None :
7681 if (
7782 not tracing_settings .TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT
@@ -98,10 +103,10 @@ def _startup(tracing_settings: TracingSettings, service_name: str) -> None:
98103 service_name ,
99104 tracing_destination ,
100105 )
101- # Configure OTLP exporter to send spans to the collector
102- otlp_exporter = OTLPSpanExporterHTTP ( endpoint = tracing_destination )
103- span_processor = BatchSpanProcessor ( otlp_exporter )
104- global_tracer_provider . add_span_processor ( span_processor )
106+ # Add the span processor to the tracer provider
107+ global_tracer_provider . add_span_processor (
108+ _create_span_processor ( tracing_destination )
109+ )
105110
106111 if HAS_AIOPG :
107112 with log_context (
You can’t perform that action at this time.
0 commit comments