Skip to content

Commit b0bf349

Browse files
committed
Adding OTLP
1 parent 8352a8e commit b0bf349

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lookup-service-server/app/main.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
from opentelemetry import trace
33
from opentelemetry.sdk.trace import TracerProvider
44
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
5+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
56
from opentelemetry.sdk.trace.export import BatchSpanProcessor
67
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
78
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
89
from .routers import records
10+
import os
911

1012
app = FastAPI()
1113

1214
# Acquire a tracer
1315
trace.set_tracer_provider(TracerProvider())
1416
tracer = trace.get_tracer(__name__)
17+
18+
if os.getenv('OTEL_APM_EXPORT'):
19+
trace_exporter = OTLPSpanExporter(endpoint="http://localhost:4318")
20+
else:
21+
trace_exporter = ConsoleSpanExporter()
1522
trace.get_tracer_provider().add_span_processor(
16-
BatchSpanProcessor(ConsoleSpanExporter()))
23+
BatchSpanProcessor(trace_exporter))
1724
FastAPIInstrumentor().instrument_app(app)
1825
ElasticsearchInstrumentor().instrument()
1926

lookup-service-server/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ opentelemetry-sdk
88
opentelemetry-instrumentation
99
opentelemetry-instrumentation-fastapi
1010
opentelemetry-instrumentation-elasticsearch
11-
slowapi
11+
opentelemetry-exporter-otlp-proto-http
1212
uvicorn

0 commit comments

Comments
 (0)