Imagine a user clicks "Export report" and waits eight seconds. The React app logs the click. The NestJS API logs a 202 response in 40 milliseconds. A BullMQ worker logs "job completed" a few seconds later. PostgreSQL shows nothing unusual. Every service says it was fast, and nobody can say where the eight seconds went, because the three logs have no shared ID linking them.
Distributed tracing fixes exactly this. One trace ID follows the request from the browser through the API, into the queue, through the worker, and down to each database query. Each step records how long it took.
A trace that actually reaches the end comes down to a few decisions:
- Pick one setup: an Azure Monitor distro, plain OpenTelemetry, or a Collector.
- Start telemetry before NestJS loads, or you get empty traces.
- Add the instrumentations the Azure distros leave out, including the Redis client BullMQ uses.
- Configure BullMQ's telemetry on both the queue and the worker, so jobs join the trace.
- Check your sampling defaults before you go looking for one slow request.
- Keep personal data out of spans, because traces are stored like logs.
What a trace gives you that logs don't
A trace is a tree of spans. Each span is one operation with a start time, a duration, a status, and attributes: an HTTP request, a controller handler, a Redis command, a SQL query, a job being processed. Spans in different services share a trace ID, passed along in the traceparent header defined by the W3C Trace Context recommendation. The header carries a version, the trace ID, the parent span ID, and trace flags.
For the export example, a full trace would show:
- The browser's fetch call to the API.
- The NestJS request span, with the controller and handler inside it.
- A producer span for adding the BullMQ job.
- The worker's consumer span when it picks up the job, including any time the job waited in the queue.
- Each PostgreSQL query and Redis command inside those spans.
Logs still matter. A trace tells you where the time went, and a log line tells you what happened there. Later in this article they get linked.
Choose your setup: Azure distro, plain OpenTelemetry, or a Collector
As of November 2026, there are three realistic ways to get traces from Node.js into Azure Monitor:
- An Azure Monitor distro. Microsoft's enable OpenTelemetry guide now points new apps to the Microsoft OpenTelemetry Distro, the
@microsoft/opentelemetrypackage, which needs Node.js 22 or later. The older@azure/monitor-opentelemetrypackage (version 1.21.0 at the time of writing) is still supported, and existing users need no action. Microsoft says not to initialize both in the same app. - Plain OpenTelemetry with your own exporter. The NodeSDK and auto-instrumentations from opentelemetry.io, sending OTLP to a backend.
- An OpenTelemetry Collector in the middle. Your services send OTLP to a Collector, which filters, samples, and forwards. Azure Monitor documents native OTLP ingestion through the Collector, version 0.132.0 or later, with Microsoft Entra authentication. Check the current status of this path for your region before you rely on it.
On Azure Container Apps there's also a managed OpenTelemetry agent. As of November 2026 it's in preview, runs as a single replica, uses gRPC, is configured per environment rather than per app, and its Application Insights destination doesn't accept metrics.
For most small teams on Azure, a distro with direct export is the simplest start. Add a Collector when you need central redaction, tail sampling, or more than one backend. The Collector overview recommends running one in production for exactly those reasons.
If you've seen NestJS Observe, NestJS's own hosted monitoring product, note that its overview says it isn't a replacement for OpenTelemetry. This article sticks to vendor-neutral OpenTelemetry, so the same instrumentation works with Azure Monitor or any other backend.
Start telemetry before NestJS loads
The most common reason for missing spans is startup order. The OpenTelemetry JS instrumentation docs say you must initialize the SDK before any other module loads. If you initialize too late, libraries that already got a tracer receive no-op implementations, and nothing is recorded. The Azure distro documentation gives the same warning: call the setup function before importing anything else.
In practice, keep telemetry setup out of main.ts:
- Put the SDK or distro setup in its own file, such as
telemetry.js. - Load it with a flag before the app starts, for example
NODE_OPTIONS="--require ./dist/telemetry.js"in your container's environment, so it runs before@nestjs/core,pg, orioredisare imported. - Don't import it from
main.tsafter other imports. With compiled TypeScript, imports are hoisted, and instrumentation can end up running too late.
The OpenTelemetry docs assume the app runs as CommonJS. For ES modules, the ESM support notes require a loader hook and the --import flag. They describe ESM support as ongoing. Check which module format your NestJS build outputs before choosing the flag.
Fill the gaps the Azure distros leave
The Azure distros bundle a set of instrumentations. Per Microsoft's collected telemetry page, they cover:
- HTTP
- PostgreSQL through
pg - Redis through the
redisclient - MongoDB and MySQL
- Azure SDK calls
- Winston and Bunyan logs, which are off by default
Three pieces this stack needs are not in that list:
- NestJS. Without the NestJS instrumentation, you see an HTTP span but not which controller and handler ran.
- ioredis. BullMQ uses ioredis by default, per its connections guide. The bundled Redis instrumentation covers the other client, so BullMQ's Redis commands stay invisible.
- pino. If you log with pino, correlation needs its own instrumentation.
Register the matching packages from opentelemetry-js-contrib yourself, alongside the distro: the NestJS core, ioredis, and pino instrumentations. Microsoft notes that it doesn't support or guarantee the quality of community instrumentations, so test them in staging.
Check version ranges too. As of November 2026, the NestJS instrumentation README declares support for @nestjs/core versions from 4 up to, but not including, 12. If you're on NestJS 12, check the package's latest release notes, then confirm in a test trace that controller and handler spans appear.
Carry the trace through BullMQ
A queue breaks the normal flow of context. The API adds a job and returns. The worker picks it up later, in another process, with no incoming HTTP request to carry a traceparent header. Something has to store the trace context with the job.
There's no BullMQ package in opentelemetry-js-contrib. BullMQ provides its own telemetry interface, and its maintainers publish bullmq-otel, an OpenTelemetry implementation of it. You pass a BullMQOtel instance as the telemetry option on both the Queue and the Worker. Per the BullMQ traces guide, BullMQ then captures the trace context when a job is added, stores it with the job, and continues the trace when the job is processed. Configure it on both sides, or the worker starts an unrelated trace. With @nestjs/bullmq, check that your module setup passes the telemetry option through to both.
There's a design choice hidden here. BullMQ's code makes the processing span a child of the span that added the job. OpenTelemetry's messaging conventions, which are still in development status, use span links by default. They allow the parent-child pattern only when a span processes a single message.
For a typical export or email job, parent-child is convenient: the whole story, including time spent waiting in the queue, is one trace. The cost shows up with delayed jobs, long retries, or fan-out. One trace can stretch over minutes or hours, and that skews duration charts. For those jobs, BullMQ's per-job omitContext telemetry option starts a fresh trace when the job is processed.
If you also want queue wait time as a number you can alert on, record it as a metric. Don't rely on reading it from trace durations. The BullMQ jobs post earlier in this series covers the queue side in more depth.
Start the trace in React
To include the browser, the frontend must start the trace and send traceparent with its API calls. You have two options:
- The Application Insights JavaScript SDK. Per its configuration guide, it sends W3C trace context in its default mode. For a cross-origin API, including a subdomain, correlation headers aren't sent by default. Set
enableCorsCorrelationto true to turn them on. ThecorrelationHeaderExcludedDomainssetting keeps those headers off calls to third parties such as your identity provider. - OpenTelemetry for the browser. As of November 2026, OpenTelemetry describes browser instrumentation as experimental. The older fetch instrumentation is deprecated in favor of the new browser instrumentation package, which has a
propagateTraceHeaderCorsUrlsoption listing the cross-origin URLs that should receive trace headers.
Either way, the API must allow the headers. The traceparent and tracestate headers aren't CORS-safelisted, so a cross-origin API has to list them in Access-Control-Allow-Headers through your NestJS CORS configuration. Otherwise the browser's preflight blocks the request. Microsoft's guide also warns that a server that doesn't accept traceparent can make requests fail. Roll out the CORS change before you enable cross-origin correlation.
Name your services
When the API and the worker send telemetry to the same Application Insights resource, Microsoft says you must set Cloud Role Names, per its enable OpenTelemetry guide. Otherwise both appear as one service, and the application map can't show the hop from API to worker.
The role name comes from the OpenTelemetry service.name attribute, combined with service.namespace when you set one. Give each process its own name, for example reports-api and reports-worker, through the OTEL_SERVICE_NAME environment variable or resource attributes. The default is unknown_service, which helps nobody.
Add your own spans where auto-instrumentation stops
Auto-instrumentation sees HTTP, Redis, and SQL, not your business steps. When a job spends three seconds building a spreadsheet in memory, that time shows up as a gap between database spans.
Wrap meaningful steps in a span with tracer.startActiveSpan. The OpenTelemetry JS docs recommend it in most cases, because it makes the new span active for everything called inside it. A few rules:
- Always end the span, typically in a
finallyblock. - On failure, call
recordExceptionand set the span status to error. - Name spans after the operation, such as "build report rows", not after a user or ID.
- Add only attributes that help debugging, such as a row count or report type, and nothing personal.
Sampling: why the slow request is missing
This is the setting most likely to surprise you. Plain OpenTelemetry keeps every trace by default, per its sampling docs. The Azure Monitor distros don't. Per Microsoft's configuration guide, if you don't set a sampler, they use rate-limited sampling, about five traces per second, as of November 2026. Under load, the exact slow request a customer reported may not be stored.
Your options:
- Fixed percentage. Set
tracesPerSecondto 0 and usesamplingRatio, for example 0.1 for 10%. Microsoft suggests starting at 5% and adjusting. - Keep rate limiting, with a higher limit. This is more predictable for cost, but trace coverage drops as traffic grows.
- Tail sampling in a Collector. This keeps every slow or failed trace and samples the rest. The tail sampling processor is in beta, and all spans of a trace must reach the same Collector instance. That usually means two layers of Collectors once you scale out.
Keep the decision consistent across services. A trace is only useful if the API, the worker, and the browser all keep their parts of it. Check that the sampler in the worker respects the decision carried in the trace context, and verify it in a test.
Microsoft notes that metrics are never sampled, and recommends alerting on metrics. That gives you a cost model that works: alert on request-rate, error-rate, and latency metrics, and use traces to investigate. Application Insights ingestion is billed per GB, per the Azure Monitor pricing page, so sampling is your main cost control. Microsoft describes a daily cap as a last resort, not a replacement for sampling.
Connect logs to traces
A trace shows you where to look. The log line there explains what happened. Link them by writing the trace ID into every log record.
With pino, the pino instrumentation adds trace_id, span_id, and trace_flags to log records written inside a span. It can also send logs through the OpenTelemetry logs pipeline. As of November 2026, the logs signal in OpenTelemetry JS is still in development status, while traces and metrics are stable. In Application Insights, the trace ID appears as the operation ID, so you can join logs and requests on it in KQL.
Linking makes noisy logs more expensive to ignore. The earlier post on application log noise covers trimming them before you start correlating.
Keep personal data out of traces
Spans are stored and queried like logs, so the same privacy rules apply. For EU users, anything personal in a span attribute is personal data in your telemetry store.
Where personal data sneaks in:
- SQL. OpenTelemetry's database conventions say query text should be collected by default only if it's sanitized, and instrumentations should not capture parameter values by default. The pg instrumentation's
enhancedDatabaseReportingoption attaches query parameters and results to spans. Keep it off in production, and use parameterized queries so the query text holds placeholders, not values. - URLs. The URL conventions say sensitive content in
url.queryshould be scrubbed. Tokens and email addresses in query strings end up in spans. - Your own attributes. A customer email or name added "for debugging" is the most common leak. Use internal IDs, and only when they help.
OpenTelemetry's guide on handling sensitive data recommends collecting only what serves an observability purpose. It also warns that hashing an ID may not be enough anonymization. A Collector's redaction processor can enforce an allow-list of attributes centrally.
Fixing it afterwards is slow. Microsoft's personal data guidance calls filtering at collection "by far the best option". It also says purge operations have a 30-day SLA, and purging doesn't reduce what you were billed. Also check which region your Log Analytics workspace is in, if you have data residency commitments. This is engineering guidance, not legal advice.
Version drift to watch in late 2026
OpenTelemetry JS moves quickly, and the examples you find online lag behind:
- SDK 3.0. The 3.0 release announcement raises the minimum Node.js version to 22.15.0 and consolidates the tracing packages into
@opentelemetry/sdk-trace. Older imports from the separate base, Node, and web trace packages no longer work on 3.x. The 2.x line stays supported for one year after the 3.0 release. - Microsoft samples. As of November 2026, some Microsoft Learn examples still import the older trace packages. Expect to adjust them on 3.x.
- Mixing majors. If you use an Azure distro, check which OpenTelemetry major version it depends on before adding contrib instrumentations or SDK packages, and keep them aligned. Mixed versions can lead to missing spans that are hard to diagnose.
- The NestJS range. As noted above, confirm the NestJS instrumentation supports your NestJS major version.
Pin versions, upgrade OpenTelemetry packages together, and keep one test that checks a request produces the spans you expect after an upgrade.
Checklist
- Pick one setup: a single Azure distro, plain OpenTelemetry, or a Collector. Never initialize two distros.
- Load telemetry before the app, through
NODE_OPTIONS, and confirm your module format. - Register the NestJS, ioredis, and pino instrumentations if your distro doesn't include them, and check version ranges.
- Configure
bullmq-otelon both the queue and the worker, and useomitContextfor long-delayed or fan-out jobs. - Send
traceparentfrom React only to your own API, and allow the trace headers in CORS. - Give the API and the worker separate service names.
- Add manual spans for slow business steps, and always end them.
- Check your sampling default, choose a rate on purpose, and alert on metrics.
- Write trace IDs into logs.
- Keep personal data out of span attributes, SQL parameters, and URLs, and filter at collection.
- Pin and upgrade OpenTelemetry packages together, and test that spans still appear.



