feat(server): add OpenTelemetry tracing and metrics support

Adds comprehensive OpenTelemetry instrumentation for better observability:

Tracing:
- HTTP requests via @opentelemetry/instrumentation-http
- NestJS controllers via @opentelemetry/instrumentation-nestjs-core
- Redis operations via @opentelemetry/instrumentation-ioredis
- BullMQ job queues via bullmq-otel
- Database queries via Kysely log callback with accurate timing
- File operations (send, stream, read)
- Media processing (thumbnails, thumbhash, EXIF operations)
- Metadata extraction

Metrics:
- Database connection pool usage (used/idle connections)

The SDK is initialized in telemetry-preload.ts which is preloaded via
--require before the main app starts. This ensures http instrumentation
hooks are in place before any http module is imported.

Enable tracing by setting OTEL_EXPORTER_OTLP_ENDPOINT environment variable.

Also adds TraceContext to IBaseJob for future distributed trace propagation
across BullMQ job boundaries.
This commit is contained in:
midzelis
2026-01-27 16:54:23 +00:00
parent d6c5a382f8
commit e03ed9b387
21 changed files with 3270 additions and 249 deletions
+4 -1
View File
@@ -45,14 +45,16 @@
"@nestjs/websockets": "^11.0.4",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^2.0.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.211.0",
"@opentelemetry/exporter-prometheus": "^0.210.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.211.0",
"@opentelemetry/instrumentation-http": "^0.210.0",
"@opentelemetry/instrumentation-ioredis": "^0.58.0",
"@opentelemetry/instrumentation-nestjs-core": "^0.56.0",
"@opentelemetry/instrumentation-pg": "^0.62.0",
"@opentelemetry/resources": "^2.0.1",
"@opentelemetry/sdk-metrics": "^2.0.1",
"@opentelemetry/sdk-node": "^0.210.0",
"@opentelemetry/sdk-trace-base": "^2.5.0",
"@opentelemetry/semantic-conventions": "^1.34.0",
"@react-email/components": "^0.5.0",
"@react-email/render": "^1.1.2",
@@ -63,6 +65,7 @@
"bcrypt": "^6.0.0",
"body-parser": "^2.2.0",
"bullmq": "^5.51.0",
"bullmq-otel": "^1.1.0",
"chokidar": "^4.0.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",