Skip to content

Commit

Permalink
Update otel code for newer versions
Browse files Browse the repository at this point in the history
  • Loading branch information
maximusunc committed Aug 23, 2024
1 parent 6a80eb6 commit f534cf0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions strider/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit f534cf0

Please sign in to comment.