Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrading otel implementation #298

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('/')
gaurav marked this conversation as resolved.
Show resolved Hide resolved
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