Skip to content

feat(nestjs): add instrumentation for NestJS microservice#3435

Open
neilime wants to merge 1 commit intoopen-telemetry:mainfrom
neilime:feat/nestjs-instrument-microservice
Open

feat(nestjs): add instrumentation for NestJS microservice#3435
neilime wants to merge 1 commit intoopen-telemetry:mainfrom
neilime:feat/nestjs-instrument-microservice

Conversation

@neilime
Copy link
Copy Markdown
Member

@neilime neilime commented Mar 13, 2026

Which problem is this PR solving?

  • NestJS instrumentation currently only covers the core HTTP/controller lifecycle through @opentelemetry/instrumentation-nestjs-core, so Nest microservice applications and hybrid apps do not produce dedicated spans for microservice bootstrapping or message/event handlers.
  • This change adds first-class NestJS microservice instrumentation while keeping the existing core-only package available as a compatibility path for current users.

Short description of the changes

  • Add a new @opentelemetry/instrumentation-nestjs package that instruments both Nest HTTP controllers and Nest microservice handlers.
  • Create spans for standalone and hybrid microservice startup (NestFactory.createMicroservice and app.connectMicroservice) and for message/event handler execution.
  • Add Nest-specific attributes for microservice tracing, including handler callback, pattern, and transport information.
  • Keep @opentelemetry/instrumentation-nestjs-core as a deprecated compatibility wrapper that delegates to the new package with microservice instrumentation disabled.
  • Register the new package in @opentelemetry/auto-instrumentations-node and update the related README/docs.
  • Add tests covering HTTP behavior, standalone microservices, and hybrid microservices.

@github-actions
Copy link
Copy Markdown
Contributor

This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature.
Are you familiar with this package? Consider becoming a component owner.

@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch from 4222aba to e793cc5 Compare March 23, 2026 13:15
@neilime neilime requested a review from a team as a code owner March 23, 2026 13:15
@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch 3 times, most recently from cbd154c to e27c710 Compare March 23, 2026 13:32
@neilime neilime removed the pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. label Mar 23, 2026
@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch from e27c710 to c9262de Compare March 23, 2026 15:33
@github-actions github-actions bot added the pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. label Mar 23, 2026
@neilime neilime removed pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. pkg-status:unmaintained:autoclose-scheduled labels Mar 23, 2026
@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch from c9262de to 6ec6182 Compare March 25, 2026 16:00
@github-actions github-actions bot added the pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. label Mar 25, 2026
@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch from 6ec6182 to 0c99a46 Compare March 25, 2026 16:19
@github-actions
Copy link
Copy Markdown
Contributor

This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature.
Are you familiar with this package? Consider becoming a component owner.

@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch 2 times, most recently from 3790533 to 0705e54 Compare March 26, 2026 14:34
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
@neilime neilime force-pushed the feat/nestjs-instrument-microservice branch from 0705e54 to b92e038 Compare March 26, 2026 14:46
@neilime neilime removed the pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. label Mar 26, 2026
@neilime
Copy link
Copy Markdown
Member Author

neilime commented Mar 26, 2026

Hi @blumamir, @dyladan, @[legendecas, @pichlermarc,

I will need you opinion on this PR.

I'm convinced that having instrumentation for just nestjs-core it to restrictive. Having an instrumation by nestjs package is bloated.

IMO the best solution is to deprecated the original nestjs-core instrumentation and forge a new nestjs (only) instrumentation.

I have made the code, it's working good, battle tested and backward compatible.

But I dont how to deal with de preciation and the new package. I've made what I supposed to be ok, but I'll appreciate your recommandation to mathc with repository practices.

Thanks

@david-luna
Copy link
Copy Markdown
Contributor

Hi @neilime

Thanks for working on this. I'm okay with having a new and more generic instrumentation (let's wait for more feedback). IMHO I would split this PR into smaller ones with this order

  • PR to add the new instrumentation (this one)
  • wait for the publication of the new instrumentation
  • PR to add the deprecation notice into @opentelemetry/instrumentation-nestjs-core
  • PR to replace it in auto instrumentations
  • after a period of time remove the deprecated instrumentation. Leaving a README for people looking at the instrumentation

@opentelemetry/instrumentation-fastify had a similar process. Ref: #2647

If you agree with this process I think this PR should only contain the new instrumentation. And I'd prefer to not refactor the current instrumentation so we avoid maintenance on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants