Skip to content

Commit

Permalink
Merge pull request #171 from TranslatorSRI/update-otel-to-grpc
Browse files Browse the repository at this point in the history
This PR copies over the code from TranslatorSRI/NodeNormalization#298 in order to replace Jaeger with gRPC in OTEL telemetry collection.
  • Loading branch information
gaurav authored Nov 4, 2024
2 parents 288ca5b + c3edf72 commit cb10b89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 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
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jsonlines

# For testing
pytest
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 cb10b89

Please sign in to comment.