Skip to content

Commit f62a845

Browse files
authored
feat: OpenTelemetry tracing (#73)
1 parent 39f7067 commit f62a845

File tree

5 files changed

+312
-18
lines changed

5 files changed

+312
-18
lines changed

infrastructure/aws/lambda/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ 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++
12-
RUN uv export --locked --no-editable --no-dev --extra lambda --format requirements.txt -o requirements.txt && \
13+
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

1516
# copy libexpat.so.1 into /asset which is included in LD_LIBRARY_PATH
@@ -21,6 +22,8 @@ RUN cd /asset && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
2122
RUN cd /asset && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
2223
RUN find /asset -type d -a -name 'tests' -print0 | xargs -0 rm -rf
2324
RUN rm -rdf /asset/numpy/doc/ /asset/bin /asset/geos_license /asset/Misc
25+
RUN rm -rdf /asset/boto3*
26+
RUN rm -rdf /asset/botocore*
2427

2528
# Strip debug symbols from compiled C/C++ code (except for numpy.libs!)
2629
RUN cd /asset && \

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."""

pyproject.toml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ dependencies = [
2424
"titiler.core>=0.23.1,<0.24",
2525
"titiler.mosaic>=0.23.1,<0.24",
2626
"titiler.xarray>=0.23.1,<0.24",
27-
"aiobotocore>=2.20",
28-
"boto3>=1.34.145",
27+
"aiobotocore>=2.24.0",
28+
"boto3>=1.39.0",
2929
"cftime~=1.6.4",
3030
"earthaccess~=0.11.0",
31+
"geojson-pydantic>=2.0.0,<3.0",
3132
"h5netcdf~=1.1.0",
33+
"httpx>=0.27.2",
34+
"isodate>=0.7.2",
3235
"orjson~=3.10.7",
36+
"pillow>=11.0.0",
37+
"psutil>=6.0.0",
3338
"pydantic-settings~=2.0",
3439
"pydantic>=2.4,<3.0",
40+
"python-dateutil>=2.9.0.post0",
3541
"rio_tiler[s3]>=7.2.0,<8.0",
3642
"rioxarray~=0.13.4",
3743
"s3fs~=2025.9.0",
3844
"xarray~=2024.9.0",
39-
"geojson-pydantic>=2.0.0,<3.0",
40-
"python-dateutil>=2.9.0.post0",
41-
"httpx>=0.27.2",
42-
"pillow>=11.0.0",
43-
"isodate>=0.7.2",
44-
"psutil>=6.0.0",
4545
]
4646
dynamic = ["version"]
4747

@@ -50,8 +50,13 @@ uvicorn = [
5050
"uvicorn",
5151
]
5252

53-
lambda = ["mangum==0.19.0"]
54-
53+
lambda = [
54+
"mangum==0.19.0",
55+
"aiobotocore>=2.24.0,<2.24.2"
56+
]
57+
telemetry = [
58+
"titiler.core[telemetry]>=0.23.1,<0.24",
59+
]
5560
[dependency-groups]
5661
dev = [
5762
"folium>=0.17.0",

titiler/cmr/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Originaly from titiler-xarray
44
"""
55

6+
import os
67
import pickle
78
from typing import Any, Dict, Optional, Type
89
from urllib.parse import urlparse
910

1011
import attr
1112
import earthaccess
1213
import fsspec
13-
import os
1414
import s3fs
1515
import xarray
1616
from cachetools import TTLCache

0 commit comments

Comments
 (0)