Skip to content

Commit

Permalink
upgrading otel implementation, using OTLP instead of jaeger client
Browse files Browse the repository at this point in the history
JaegerExporter is deprecated. This would send traces using the OTLP over gRPC.
  • Loading branch information
EvanDietzMorris committed Nov 4, 2024
1 parent 44be292 commit 926089a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ redis~=3.5.3
requests==2.28.1
uvicorn==0.17.6
uvloop==0.19.0
opentelemetry-sdk==1.16.0
opentelemetry-instrumentation-fastapi==0.37b0
opentelemetry-exporter-jaeger==1.16.0
opentelemetry-instrumentation-httpx==0.37b0
opentelemetry-sdk==1.25.0
opentelemetry-instrumentation-fastapi==0.48b0
opentelemetry-exporter-otlp-proto-grpc==1.27.0
opentelemetry-instrumentation-httpx==0.48b0
fakeredis<=2.10.2
networkx==3.2.1
26 changes: 10 additions & 16 deletions src/otel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def configure_otel(service_name, APP):

from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry import trace
from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME as telemetery_service_name_key, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
Expand All @@ -19,20 +19,14 @@ def configure_otel(service_name, APP):
# these supresses such warnings.
logging.captureWarnings(capture=True)
warnings.filterwarnings("ignore",category=ResourceWarning)
jaeger_host = os.environ.get('JAEGER_HOST', 'jaeger-otel-agent')
jaeger_port = int(os.environ.get('JAEGER_PORT', '6831'))
trace.set_tracer_provider(
TracerProvider(
resource=Resource.create({telemetery_service_name_key: service_name})
)
jaeger_host = os.environ.get('JAEGER_HOST', 'jaeger-otel-collector')
jaeger_port = int(os.environ.get('JAEGER_PORT', '4317'))
jaeger_endpoint = f'{jaeger_host}:{jaeger_port}'
otlp_exporter = OTLPSpanExporter(endpoint=jaeger_endpoint)
tracer_provider = TracerProvider(
resource=Resource.create({telemetery_service_name_key: service_name})
)
jaeger_exporter = JaegerExporter(
agent_host_name=jaeger_host,
agent_port=jaeger_port,
)
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(jaeger_exporter)
)
tracer = trace.get_tracer(__name__)
FastAPIInstrumentor.instrument_app(APP, tracer_provider=trace, excluded_urls="docs,openapi.json")
tracer_provider.add_span_processor(BatchSpanProcessor(otlp_exporter))
trace.set_tracer_provider(tracer_provider)
FastAPIInstrumentor.instrument_app(APP, tracer_provider=tracer_provider, excluded_urls="docs,openapi.json")
HTTPXClientInstrumentor().instrument()

0 comments on commit 926089a

Please sign in to comment.