Skip to content

Sentry Tracing is Suppressed on Application Startup if a Controller Uses NestJS FileInterceptor #17790

@SetropLeo

Description

@SetropLeo

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nestjs

SDK Version

10.15.0

Framework Version

11.0.1

Link to Sentry event

https://portal-telemedicina-nk.sentry.io/explore/traces/trace/7333d38d64ea1b7db2f9394af03d724c/?mode=samples&pageEnd&pageStart&project=4509923232120832&project=4510046854905856&source=traces&statsPeriod=24h&table=trace&timestamp=1758814281.369

Reproduction Example/SDK Setup

It looks like Sentry's performance tracing enters a mostly "suppressed" state immediately on application startup if any controller in the NestJS project is decorated with @UseInterceptors(FileInterceptor(...)) (FileInterceptor from NestJS for file uploads)

The weirdest part is that you don't even have to call the file upload endpoint. Just having the @UseInterceptors(FileInterceptor(...)) line in any controller is enough to cause the issue right when the app starts up

The problem is not a runtime conflict on the request stream, but seems to be an initialization-time conflict during the NestJS application bootstrap (NestFactory.create()).

When the FileInterceptor line is commented out everything works perfectly.
When the FileInterceptor line is active it causes a problem where any action within the nestjs app generates only a single span

My guess is that when NestJS boots up and sees the FileInterceptor, it loads multer early. This seems to be conflicting with how Sentry works.

Steps to Reproduce

  1. Set sentry's debugger option to true.

  2. Call any endpoint you might have within your project. Example:

@Get('someEndpointYouMightHave')
yourControllerFunctionHere() {
  this.callYourServiceHere();
}
  1. Check how many spans are created and keep the value in mind. Example:

Sentry Logger [log]: SpanExporter exported 7 spans, 0 spans are waiting for their parent spans to finish

  1. Place this line of code (below) within any controller of your project. Example:

NOTE: I placed in this case within the same controller I showed above, but you can place it within any other controller and call the first controller that you used to test.

@Get('someEndpointYouMightHave')
@UseInterceptors(FileInterceptor('file')) // <-- THE PROBLEMATIC LINE
yourControllerFunctionHere() {
  this.callYourServiceHere();
}
  1. Check how many spans are created and compare the results:

Sentry Logger [log]: SpanExporter exported 1 spans, 0 spans are waiting for their parent spans to finish

Expected Result

Sentry Logger [log]: SpanExporter exported 7 spans, 0 spans are waiting for their parent spans to finish

Actual Result

Sentry Logger [log]: SpanExporter exported 1 spans, 0 spans are waiting for their parent spans to finish

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions