Trust-Link Backend uses OpenTelemetry to trace service request lifecycles across production clusters. Traces flow from inbound HTTP requests through NestJS handlers and database operations, with W3C Trace Context propagation for cross-service correlation.
Client / Gateway
│ traceparent header
▼
┌─────────────────────────────────────────┐
│ HTTP auto-instrumentation (Express) │
│ TracingMiddleware (workflow metadata) │
│ TracingInterceptor (handler spans) │
└─────────────────┬───────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ PrismaService (db.* spans per op) │
│ Redis / outbound HTTP (auto-instr.) │
└─────────────────┬───────────────────────┘
│ OTLP HTTP
▼
Jaeger / Tempo / Datadog
| Variable | Default | Description |
|---|---|---|
OTEL_ENABLED |
true |
Set to false to disable tracing |
OTEL_SERVICE_NAME |
trustlink-backend |
Service name in trace backend |
OTEL_SERVICE_VERSION |
1.0.0 |
Service version attribute |
OTEL_EXPORTER_OTLP_ENDPOINT |
(none) | OTLP collector base URL (e.g. http://jaeger:4318) |
Tracing is automatically disabled when NODE_ENV=test.
Start the stack with Jaeger included:
docker compose up -dOpen the Jaeger UI at http://localhost:16686 and search for service trustlink-backend.
| Span name pattern | Description |
|---|---|
GET /escrow/... |
HTTP span (auto-instrumentation) |
workflow.escrow.get |
API workflow span (grouped by route family) |
handler.EscrowController.findOne |
NestJS handler span |
db.escrow.findUnique |
Database operation with duration |
Every db.* span includes:
db.system:postgresqldb.operation: e.g.findUnique,create,updatedb.sql.table: model name (escrow,dispute, etc.)
Incoming requests with a traceparent header continue the parent trace. Outbound calls can inject context via TracingService.injectTraceHeaders().
- Deploy an OTLP-compatible collector (Jaeger, Grafana Tempo, Datadog Agent, AWS ADOT).
- Set
OTEL_EXPORTER_OTLP_ENDPOINTto the collector's OTLP HTTP endpoint. - Ensure pod/service name via
OTEL_SERVICE_NAME. - Correlate traces with structured JSON logs using the
trace_idfield when log-trace correlation is enabled in your log stack.
| File | Role |
|---|---|
src/tracing/tracing.bootstrap.ts |
SDK initialization (imported first in main.ts) |
src/tracing/tracing.service.ts |
Span helpers |
src/tracing/tracing.middleware.ts |
Workflow metadata on HTTP spans |
src/tracing/tracing.interceptor.ts |
Per-handler workflow spans |
src/tracing/prisma-tracing.wrapper.ts |
Database operation spans |