Skip to content

Commit 5763661

Browse files
committed
feat: instrument micro-service entrypoints with OpenTelemetry (refs #4)
1 parent 19f3e95 commit 5763661

7 files changed

Lines changed: 50 additions & 0 deletions

File tree

app/main_comment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from app.api.v1.endpoints.comments_ratings import (
1212
router as comments_ratings_router,
1313
)
14+
from app.utils.observability import configure_observability
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -30,6 +31,9 @@
3031

3132
service_app.include_router(comments_ratings_router, prefix=settings.API_V1_STR)
3233

34+
# Initialise observability
35+
configure_observability(service_app)
36+
3337

3438
@service_app.on_event("startup")
3539
async def startup_event() -> None:

app/main_moderation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from app.db.astra_client import init_astra_db
1010
from app.models.common import ProblemDetail
1111
from app.api.v1.endpoints.moderation import router as moderation_router
12+
from app.utils.observability import configure_observability
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -27,6 +28,9 @@
2728

2829
service_app.include_router(moderation_router, prefix=settings.API_V1_STR)
2930

31+
# Initialise observability
32+
configure_observability(service_app)
33+
3034

3135
@service_app.on_event("startup")
3236
async def startup_event() -> None:

app/main_reco.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
router as recommendations_feed_router,
1313
)
1414
from app.api.v1.endpoints.reco_internal import router as reco_internal_router
15+
from app.utils.observability import configure_observability
1516

1617
logger = logging.getLogger(__name__)
1718

@@ -32,6 +33,9 @@
3233
service_app.include_router(recommendations_feed_router, prefix=settings.API_V1_STR)
3334
service_app.include_router(reco_internal_router, prefix=settings.API_V1_STR)
3435

36+
# Initialise observability
37+
configure_observability(service_app)
38+
3539

3640
@service_app.on_event("startup")
3741
async def startup_event() -> None:

app/main_search.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from app.api.v1.endpoints.search_catalog import (
1212
router as search_catalog_router,
1313
)
14+
from app.utils.observability import configure_observability
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -29,6 +30,9 @@
2930

3031
service_app.include_router(search_catalog_router, prefix=settings.API_V1_STR)
3132

33+
# Initialise observability
34+
configure_observability(service_app)
35+
3236

3337
@service_app.on_event("startup")
3438
async def startup_event() -> None:

app/main_user.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from app.api.v1.endpoints.account_management import (
1212
router as account_management_router,
1313
)
14+
from app.utils.observability import configure_observability
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -32,6 +33,9 @@
3233
# Include router(s)
3334
service_app.include_router(account_management_router, prefix=settings.API_V1_STR)
3435

36+
# Initialise observability (metrics, traces, logs) if enabled
37+
configure_observability(service_app)
38+
3539

3640
@service_app.on_event("startup")
3741
async def startup_event() -> None:

app/main_video.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from app.models.common import ProblemDetail
1111
from app.api.v1.endpoints.video_catalog import router as video_catalog_router
1212
from app.api.v1.endpoints.flags import router as flags_router
13+
from app.utils.observability import configure_observability
1314

1415
logger = logging.getLogger(__name__)
1516

@@ -30,6 +31,9 @@
3031
service_app.include_router(video_catalog_router, prefix=settings.API_V1_STR)
3132
service_app.include_router(flags_router, prefix=settings.API_V1_STR)
3233

34+
# Initialise observability
35+
configure_observability(service_app)
36+
3337

3438
@service_app.on_event("startup")
3539
async def startup_event() -> None:

env.example

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ SECRET_KEY=please-change-me-to-a-long-random-string
4848
# migrations & backfill jobs have run successfully.
4949
VECTOR_SEARCH_ENABLED=false
5050

51+
# --------------------------------------------------------------------
52+
# Observability / Telemetry
53+
# --------------------------------------------------------------------
54+
# Enable or disable all observability integrations (Prometheus, OpenTelemetry, Loki).
55+
OBSERVABILITY_ENABLED=true
56+
57+
# --- OpenTelemetry (Traces & Metrics) --------------------------------
58+
# Base OTLP endpoint; for local docker-compose stack use http://localhost:4318
59+
OTEL_EXPORTER_OTLP_ENDPOINT=http://replace-me:4318
60+
61+
# Protocol can be "grpc" (4317) or "http" (4318). Only grpc supported right now.
62+
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc
63+
64+
# Example auth header – uncomment if your collector expects mcp-token header.
65+
# OTEL_EXPORTER_OTLP_HEADERS=mcp-token=REPLACE_ME_TOKEN
66+
67+
# Toggle traces / metrics export (true/false)
68+
OTEL_TRACES_ENABLED=true
69+
OTEL_METRICS_ENABLED=false
70+
71+
# --- Loki -------------------------------------------------------------
72+
# Ship structured logs to Loki. Ensure logging-loki dependency installed.
73+
# LOKI_ENABLED=false
74+
# LOKI_ENDPOINT=http://loki:3100/loki/api/v1
75+
# LOKI_EXTRA_LABELS=team=backend,feature=killrvideo
76+
5177
#######################################################################
5278
# End of file
5379
#######################################################################

0 commit comments

Comments
 (0)