Skip to content

[Feature] instrumentation-nestjs-core: add microservices transport support #3563

Description

@Sajith15

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:

  1. @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
  2. ClientProxy.send() / ClientProxy.emit() - create producer spans when the microservice client sends a message, propagating trace context via message headers

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions