Skip to content

Commit

Permalink
Updated OTEL to use gRPC instead of Jaeger.
Browse files Browse the repository at this point in the history
Based on the changes made at TranslatorSRI/NodeNormalization#298
  • Loading branch information
gaurav committed Nov 4, 2024
1 parent 9084e47 commit 194a907
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ async def lookup(string: str,
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 @@ -508,19 +508,19 @@ async def lookup(string: str,
# these supresses such warnings.
logging.captureWarnings(capture=True)
warnings.filterwarnings("ignore", category=ResourceWarning)
plater_service_name = os.environ.get('SERVER_NAME', 'infores:sri-name-resolver')
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=
Expand Down

0 comments on commit 194a907

Please sign in to comment.