|
22 | 22 | from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR |
23 | 23 | from starlette.types import ASGIApp |
24 | 24 |
|
| 25 | + |
| 26 | +APP_NAME = os.getenv("APP_NAME") |
25 | 27 | ENABLE_TELEMETRY = os.getenv("ENABLE_TELEMETRY", "false") == "true" |
26 | 28 |
|
27 | 29 | INFO = Gauge("fastapi_app_info", "FastAPI application information.", ["app_name"]) |
|
50 | 52 | "Gauge of requests by method and path currently being processed", |
51 | 53 | ["method", "path", "app_name"], |
52 | 54 | ) |
| 55 | +TASKS_IN_PROGRESS = Gauge( |
| 56 | + "cognition_tasks_in_progress", |
| 57 | + "Indicates if the task master thread is running (1) or not (0)", |
| 58 | + ["task_name", "app_name"], |
| 59 | +) |
| 60 | +TASKS_PROCESSED = Counter( |
| 61 | + "cognition_task_processed_total", |
| 62 | + "Total items processed by the task", |
| 63 | + ["task_name", "app_name"], |
| 64 | +) |
| 65 | +TASKS_ERRORS = Counter( |
| 66 | + "cognition_task_errors_total", |
| 67 | + "Total errors encountered by the task", |
| 68 | + ["task_name", "app_name"], |
| 69 | +) |
| 70 | +WEBSOCKET_EXTERNAL_SUCCESS = Counter( |
| 71 | + "cognition_websocket_external_success_total", |
| 72 | + "Total successful external websocket connections", |
| 73 | + ["app_name", "org_id", "project_id"], |
| 74 | +) |
| 75 | +WEBSOCKET_EXTERNAL_FAILURE = Counter( |
| 76 | + "cognition_websocket_external_failure_total", |
| 77 | + "Total failed external websocket connections", |
| 78 | + ["app_name", "org_id", "project_id"], |
| 79 | +) |
| 80 | +WEBSOCKET_INTERNAL_SUCCESS = Counter( |
| 81 | + "cognition_websocket_internal_success_total", |
| 82 | + "Total successful internal websocket connections", |
| 83 | + ["app_name", "org_id", "project_id"], |
| 84 | +) |
| 85 | +WEBSOCKET_INTERNAL_FAILURE = Counter( |
| 86 | + "cognition_websocket_internal_failure_total", |
| 87 | + "Total failed internal websocket connections", |
| 88 | + ["app_name", "org_id", "project_id"], |
| 89 | +) |
53 | 90 |
|
54 | 91 |
|
55 | 92 | class PrometheusMiddleware(BaseHTTPMiddleware): |
@@ -122,12 +159,20 @@ def metrics(request: Request) -> Response: |
122 | 159 | ) |
123 | 160 |
|
124 | 161 |
|
| 162 | +def setting_app_name(app_name: str) -> None: |
| 163 | + global APP_NAME |
| 164 | + if APP_NAME is None: |
| 165 | + APP_NAME = app_name |
| 166 | + |
| 167 | + |
125 | 168 | def setting_otlp( |
126 | 169 | app: ASGIApp, app_name: str, endpoint: str, log_correlation: bool = True |
127 | 170 | ) -> None: |
128 | 171 | # Setting OpenTelemetry |
129 | 172 | # set the service name to show in traces |
130 | | - resource = Resource.create(attributes={"service.name": app_name}) |
| 173 | + resource = Resource.create( |
| 174 | + attributes={"service.name": app_name, "compose_service": app_name} |
| 175 | + ) |
131 | 176 |
|
132 | 177 | # set the tracer provider |
133 | 178 | tracer = TracerProvider(resource=resource) |
|
0 commit comments