Skip to content

Commit

Permalink
Merge pull request #298 from TranslatorSRI/otlp
Browse files Browse the repository at this point in the history
JaegerExporter is deprecated and the thrift protocol it uses causes issues due to the UDP packet size limitations. This uses OTLP over gRPC instead.
  • Loading branch information
gaurav authored Nov 4, 2024
2 parents 3687a04 + 116756e commit 13ba01e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
26 changes: 14 additions & 12 deletions node_normalizer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ async def get_curie_prefixes_handler(
if os.environ.get('OTEL_ENABLED', 'false') == 'true':
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, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
Expand All @@ -407,20 +407,22 @@ async def get_curie_prefixes_handler(
# these supresses such warnings.
logging.captureWarnings(capture=True)
warnings.filterwarnings("ignore", category=ResourceWarning)
plater_service_name = os.environ.get('SERVER_NAME', 'infores:sri-node-normalizer')
assert plater_service_name and isinstance(plater_service_name, str)

jaeger_exporter = JaegerExporter(
agent_host_name=os.environ.get("JAEGER_HOST", "localhost"),
agent_port=int(os.environ.get("JAEGER_PORT", "6831")),
)
resource = Resource(attributes={
SERVICE_NAME: os.environ.get("JAEGER_SERVICE_NAME", plater_service_name),
otel_service_name = os.environ.get('SERVER_NAME', 'infores:sri-node-normalizer')
assert otel_service_name and isinstance(otel_service_name, str)

otlp_host = os.environ.get("JAEGER_HOST", "http://localhost/").rstrip('/')
otlp_port = os.environ.get("JAEGER_PORT", "4317")
otlp_endpoint = f'{otlp_host}:{otlp_port}'
otlp_exporter = OTLPSpanExporter(endpoint=f'{otlp_endpoint}')
processor = BatchSpanProcessor(otlp_exporter)
# processor = BatchSpanProcessor(ConsoleSpanExporter())

resource = Resource.create(attributes={
SERVICE_NAME: os.environ.get("JAEGER_SERVICE_NAME", otel_service_name),
})
provider = TracerProvider(resource=resource)
# processor = BatchSpanProcessor(ConsoleSpanExporter())
processor = BatchSpanProcessor(jaeger_exporter)
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
FastAPIInstrumentor.instrument_app(app, tracer_provider=provider, excluded_urls="docs,openapi.json")
HTTPXClientInstrumentor().instrument()
HTTPXClientInstrumentor().instrument()
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ orjson==3.9.15
httpx==0.23.0

# To support Open Telemetry
opentelemetry-sdk==1.21.0
opentelemetry-exporter-jaeger==1.21.0
opentelemetry-instrumentation-fastapi==0.42b0
opentelemetry-instrumentation-httpx==0.42b0
opentelemetry-sdk==1.27.0
opentelemetry-exporter-otlp-proto-grpc==1.27.0
opentelemetry-instrumentation-fastapi==0.48b0
opentelemetry-instrumentation-httpx==0.48b0

0 comments on commit 13ba01e

Please sign in to comment.