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

What to use for "provider" in fastifyOtelInstrumentation.setTracerProvider(provider) ? #23

Open
2 tasks done
PrimeDominus opened this issue Feb 20, 2025 · 3 comments
Open
2 tasks done

Comments

@PrimeDominus
Copy link

PrimeDominus commented Feb 20, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Maybe it's sleep deprivation, but I've looked through various docs and I'm admittedly stumped. In the README.md example it states:

// ... in your OTEL setup
const FastifyOtelInstrumentation = require('@fastify/otel');

// If serverName is not provided, it will fallback to OTEL_SERVICE_NAME
// as per https://opentelemetry.io/docs/languages/sdk-configuration/general/.
const fastifyOtelInstrumentation = new FastifyOtelInstrumentation({ servername: '<yourCustomApplicationName>' }); 
fastifyOtelInstrumentation.setTracerProvider(provider)

What should the value for the provider parameter (last line above) be if I'm using @fastify/otel with @opentelemetry/auto-instrumentations-node?

@PrimeDominus
Copy link
Author

For extra clarification, when starting a new project with Express I would normally just run auto-instrumentation using the following env var and not use a custom instrumentation.ts.

NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"

Do I now need to set up the exporter and provider in the "OTEL setup" file with something like the following?

const exporter = new CollectorTraceExporter();
const provider = new NodeTracerProvider({
  resource: new Resource({
    [SEMRESATTRS_SERVICE_NAME]: 'basic-service',
  }),
  spanProcessors: [
    new SimpleSpanProcessor(exporter),
  ],
});
provider.register();

@metcoder95
Copy link
Member

You can use the following testing file as reference:

const httpInstrumentation = new HttpInstrumentation()

Currently @opentelemetry/auto-instrumentation-node does not contains Fastify instrumentation.

Do I now need to set up the exporter and provider in the "OTEL setup" file with something like the following?

Yes

@PrimeDominus
Copy link
Author

I see. I'll give it a try with other instrumentations as well e.g. @opentelemetry/instrumentation-nestjs-core

Would we need to also instrument @opentelemetry/instrumentation-pino as well, or does @fastify/otel handle that for us since pino is built into fastify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants