Skip to content

Commit 7ebbae2

Browse files
committed
add basic otel config
1 parent 9944c7c commit 7ebbae2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

infrastructure/aws/lambda/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
55

66
WORKDIR /tmp
77

8+
RUN dnf install -y gcc-c++
9+
810
COPY uv.lock .python-version pyproject.toml LICENSE README.md ./
911
COPY titiler/ ./titiler/
1012

11-
RUN dnf install -y gcc-c++
1213
RUN uv export --locked --no-editable --no-dev --extra lambda --extra telemetry --format requirements.txt -o requirements.txt && \
1314
uv pip install --compile-bytecode --no-binary pydantic --target /asset -r requirements.txt
1415

infrastructure/aws/lambda/handler.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
import earthaccess
88
from mangum import Mangum
9+
from opentelemetry import trace
10+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
11+
from opentelemetry.instrumentation.logging import LoggingInstrumentor
12+
from opentelemetry.sdk.resources import SERVICE_NAME, SERVICE_VERSION, Resource
13+
from opentelemetry.sdk.trace import TracerProvider
914

1015
from titiler.cmr.main import app
1116
from titiler.cmr.settings import AuthSettings
@@ -16,6 +21,25 @@
1621
logging.getLogger("mangum.http").setLevel(logging.ERROR)
1722

1823

24+
LoggingInstrumentor().instrument(set_logging_format=True)
25+
FastAPIInstrumentor.instrument_app(app)
26+
27+
resource = Resource.create(
28+
{
29+
SERVICE_NAME: "titiler-cmr",
30+
SERVICE_VERSION: "0.1.0",
31+
}
32+
)
33+
34+
provider = TracerProvider(resource=resource)
35+
36+
# uses the OTEL_EXPORTER_OTLP_ENDPOINT env var
37+
# processor = BatchSpanProcessor(OTLPSpanExporter())
38+
# provider.add_span_processor(processor)
39+
40+
trace.set_tracer_provider(provider)
41+
42+
1943
@app.on_event("startup")
2044
async def startup_event() -> None:
2145
"""startup."""

0 commit comments

Comments
 (0)