Skip to content

Commit 28753ec

Browse files
OpenTelemetry monitoring (#106)
* chore: update submodules * chore: update submodules * OpenTelementry monitoring * perf: loki logging on start * fix: hanging docker stop * chore: update submodules * perf: enhance monitoring
1 parent 705c64f commit 28753ec

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

app.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: utf-8 -*-
1+
import os
2+
import logging
23
from fastapi import FastAPI, responses, status, Request
34
from pydantic import BaseModel
45
from typing import List, Optional, Dict, Any, Union
@@ -7,11 +8,26 @@
78
general,
89
playground_question as playground_question_db_bo,
910
)
10-
from submodules.model import session
11+
from submodules.model import session, telemetry
1112

1213
import traceback
1314

14-
app = FastAPI()
15+
OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317")
16+
17+
app_name = "refinery-neural-search"
18+
app = FastAPI(title=app_name)
19+
20+
if telemetry.ENABLE_TELEMETRY:
21+
print("WARNING: Running telemetry.", flush=True)
22+
telemetry.setting_app_name(app_name)
23+
telemetry.setting_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT)
24+
app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name)
25+
app.add_route("/metrics", telemetry.metrics)
26+
27+
# Filter out /metrics
28+
logging.getLogger("uvicorn.access").addFilter(
29+
lambda record: "GET /metrics" not in record.getMessage()
30+
)
1531

1632

1733
@app.middleware("http")

start

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
DEBUG_MODE=false
44
DEBUG_PORT=15676
5+
ENABLE_TELEMETRY=false
56

6-
while getopts d flag
7+
while getopts dg flag
78
do
89
case "${flag}" in
910
d) DEBUG_MODE=true;;
11+
g) ENABLE_TELEMETRY=true;;
1012
esac
1113
done
1214

@@ -32,6 +34,7 @@ docker run -d --rm \
3234
-p 7063:80 \
3335
-e POSTGRES=postgresql://postgres:kern@graphql-postgres:5432 \
3436
-e QDRANT_PORT=6333 \
37+
-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \
3538
--mount type=bind,source="$(pwd)"/,target=/app \
3639
-v /var/run/docker.sock:/var/run/docker.sock \
3740
--network dev-setup_default \

0 commit comments

Comments
 (0)