Skip to main content
← Back to articles

OpenTelemetry in Production Microservices

Tracing, metrics, and logs with consistent correlation IDs across NestJS services and workers.

Nestlancer Editorial

Share

Distributed tracing only helps when every hop shares a trace ID. In NestJS microservice fleets, consistent OpenTelemetry instrumentation turns vague "it's slow" reports into span waterfalls you can act on.

Instrumentation baseline

  • Auto-instrument HTTP, gRPC, and database drivers
  • Propagate traceparent headers through the API gateway
  • Attach service.name, deployment.environment, and request.id attributes
  • Export to OTLP collector—avoid vendor-specific SDK lock-in at the edge

NestJS integration pattern

import { trace } from '@opentelemetry/api';

const tracer = trace.getTracer('blog-service');
const span = tracer.startSpan('posts.publish', { attributes: { postId } });
try {
  await this.outbox.enqueue(event);
} finally {
  span.end();
}

Wrap outbound HTTP calls and Prisma queries in child spans. Missing database spans hide 80% of latency.

Logs and metrics correlation

SignalCorrelation key
Logstrace_id, span_id
MetricsExemplars linking to traces
ErrorsStack trace + trace URL in alert

Sampling strategy

Head-based 100% sampling collapses under load. Use tail sampling in the collector for errors and high-latency traces. Keep always-on sampling for payment and auth paths.

Observability is production infrastructure—invest in correlation IDs before the next cross-service outage.

Comments

Loading comments…

Related posts