Problem:
The existing @opentelemetry/instrumentation-nestjs-core instruments HTTP request handling in NestJS but does not support NestJS microservices (TCP, Redis, NATS, Kafka, gRPC transports).
Issue #2510 documents this: teams using NestJS microservices get no trace propagation across service calls, making distributed tracing effectively useless in microservice architectures.
What I want to add:
Extend instrumentation-nestjs-core to support NestJS microservice message patterns:
-
@MessagePattern handlers - create a child span when a microservice handler receives a message, with:
messaging.system = transport type (redis/nats/kafka/tcp)
messaging.destination = the pattern string
messaging.operation = process
-
ClientProxy.send() / ClientProxy.emit() - create producer spans when the microservice client sends a message, propagating trace context via message headers
-
Context propagation - inject/extract traceparent into NestJS microservice message headers (the data envelope already has a headers field in newer NestJS versions)
Implementation approach:
The existing instrumentation patches RouterExplorer for HTTP. For microservices, we'd similarly patch:
ServerTCP.handleMessage() / ServerRedis.handleMessage() etc. using the Server base class
ClientProxy.send() and ClientProxy.emit() at the base class level
Scope:
- TCP, Redis, and NATS transports initially (highest usage)
- Kafka and gRPC in follow-up PRs
- Integration tests using
testcontainers
Is there maintainer appetite for this? I know this is a significant addition - I'd start with a minimal PR for TCP + Redis and then build out from there based on feedback.
Problem:
The existing
@opentelemetry/instrumentation-nestjs-coreinstruments HTTP request handling in NestJS but does not support NestJS microservices (TCP, Redis, NATS, Kafka, gRPC transports).Issue #2510 documents this: teams using NestJS microservices get no trace propagation across service calls, making distributed tracing effectively useless in microservice architectures.
What I want to add:
Extend
instrumentation-nestjs-coreto support NestJS microservice message patterns:@MessagePatternhandlers - create a child span when a microservice handler receives a message, with:messaging.system= transport type (redis/nats/kafka/tcp)messaging.destination= the pattern stringmessaging.operation=processClientProxy.send()/ClientProxy.emit()- create producer spans when the microservice client sends a message, propagating trace context via message headersContext propagation - inject/extract
traceparentinto NestJS microservice message headers (thedataenvelope already has aheadersfield in newer NestJS versions)Implementation approach:
The existing instrumentation patches
RouterExplorerfor HTTP. For microservices, we'd similarly patch:ServerTCP.handleMessage()/ServerRedis.handleMessage()etc. using theServerbase classClientProxy.send()andClientProxy.emit()at the base class levelScope:
testcontainersIs there maintainer appetite for this? I know this is a significant addition - I'd start with a minimal PR for TCP + Redis and then build out from there based on feedback.