From f534cf0fa04ee6ce9c1dda5b6f300511bf35d61c Mon Sep 17 00:00:00 2001 From: Max Wang Date: Fri, 23 Aug 2024 12:14:46 -0400 Subject: [PATCH] Update otel code for newer versions --- strider/server.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/strider/server.py b/strider/server.py index adbaed0f..e3f2e563 100644 --- a/strider/server.py +++ b/strider/server.py @@ -155,7 +155,7 @@ async def catch_exceptions_middleware(request: Request, call_next): from opentelemetry import trace from opentelemetry.exporter.jaeger.thrift import JaegerExporter from opentelemetry.sdk.resources import ( - SERVICE_NAME as telemetery_service_name_key, + SERVICE_NAME, Resource, ) from opentelemetry.sdk.trace import TracerProvider @@ -168,19 +168,17 @@ async def catch_exceptions_middleware(request: Request, call_next): logging.captureWarnings(capture=True) warnings.filterwarnings("ignore", category=ResourceWarning) service_name = os.environ.get("OTEL_SERVICE_NAME", "STRIDER") - trace.set_tracer_provider( - TracerProvider( - resource=Resource.create({telemetery_service_name_key: service_name}) - ) - ) jaeger_exporter = JaegerExporter( agent_host_name=settings.jaeger_host, agent_port=int(settings.jaeger_port), ) - trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(jaeger_exporter)) - tracer = trace.get_tracer(__name__) + resource = Resource(attributes={SERVICE_NAME: service_name}) + provider = TracerProvider(resource=resource) + processor = BatchSpanProcessor(jaeger_exporter) + provider.add_span_processor(processor) + trace.set_tracer_provider(provider) FastAPIInstrumentor.instrument_app( - APP, tracer_provider=trace, excluded_urls="docs,openapi.json" + APP, tracer_provider=provider, excluded_urls="docs,openapi.json" ) HTTPXClientInstrumentor().instrument()