open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.7k stars 781 forks source link

Possible to configure Multiple Exporters using NodeSDK? #4881

Open NicholasGWK opened 2 months ago

NicholasGWK commented 2 months ago

Hello! I may be reading docs/types incorrectly, but it seems like it's only possible to configure a single trace exporter(and logger actually?) using the NodeSDK?

I know multiple are supported via env vars/a full setup, but just wanted to check that my read was correct here (we're migrating vendors so want to switch my config to send to both for now as we don't have a collector yet).

If it's something desirable I could maybe take a crack at a PR, but also let me know if it's supposed to just cover the single case!

Cheers

jclapadula commented 2 weeks ago

Hey, It took me a while to find out how to do it (I think there is no example in the docs), but you have to use spanProcessors instead of traceExporter, something like:

  new NodeSDK({
    spanProcessors: [
      new BatchSpanProcessor(new OTLPTraceExporter(oneConfig)),
      new BatchSpanProcessor(new OTLPTraceExporter(anotherConfig)),
    ],
    // rest of the config
  })