Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestJS FilesInterceptor breaks tracing #5413

Closed
nilswinking opened this issue Feb 1, 2025 · 3 comments
Closed

NestJS FilesInterceptor breaks tracing #5413

nilswinking opened this issue Feb 1, 2025 · 3 comments
Labels
bug Something isn't working has:reproducer This bug/feature has a minimal reproducer provided triage

Comments

@nilswinking
Copy link

What happened?

When using the FilesInterceptor in a NestJS application tracing does not work.

Steps to Reproduce

Reproduction: https://stackblitz.com/edit/nestjs-otel-tracing-files-interceptor?file=src%2Fapp.controller.ts

  1. Start the project.
  2. Send a request to /, you will see the tracing output in the console.
  3. Comment out the @UseInterceptors(FilesInterceptor('files')) part.
  4. Once the application restarted with the changes send another request.

Expected Result

Tracing output is visible in the console

Actual Result

No tracing output is visible/no tracing is happening

Additional Details

  • The mere presence of this annotation is enough to break tracing. The issue is not limited to the one endpoint annotated with it
  • Other Interceptors can be used without issue. I have included a LoggingInterceptor in the reproduction to check.
  • I have checked with both node 18 and 20, but the reproduction is using version 18
  • the reproduction uses SimpleSpanProcessor and ConsoleSpanExporter but BatchSpanProcessor and other exporters also don't work

OpenTelemetry Setup Code

package.json

Relevant log output

Operating System and Version

No response

Runtime and Version

Node.js v18.20.3 and Node.js v20.18.2

@nilswinking nilswinking added bug Something isn't working triage labels Feb 1, 2025
@mehdifracso
Copy link

OtelSDK needs to be imported before everything so it patches every module before they're loaded.

Here is how I fixed it, I moved the otelSDK import to the top of the main.ts file:

import otelSDK from './tracing';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// import otelSDK from './tracing';

async function bootstrap() {
  otelSDK.start();
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

@dyladan dyladan added the has:reproducer This bug/feature has a minimal reproducer provided label Feb 5, 2025
@dyladan
Copy link
Member

dyladan commented Feb 5, 2025

@nilswinking does the above suggestion fix your issue?

@nilswinking
Copy link
Author

I ended up having to use a dynamic import as having some other imports before the initialization caused some other problems.

import otelSDK from '@app/utils/tracing';

async function bootstrap() {
  otelSDK.start();
  await import('./server').then(async ({ startServer }) => {
    await startServer();
  });
}

bootstrap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has:reproducer This bug/feature has a minimal reproducer provided triage
Projects
None yet
Development

No branches or pull requests

3 participants