opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

@opentelemetry/exporter-trace-otlp-grpc ignores headers

Open ruslan-mikhailov opened this issue 8 months ago • 3 comments
trafficstars

Hello!

According to the documentation, it is possible to provide custom headers when configuring the OTLP trace exporter:

new OTLPTraceExporter({
    // optional - default url is http://localhost:4318/v1/traces
    url: '<your-otlp-endpoint>/v1/traces',
    // optional - collection of custom headers to be sent with each request, empty by default
    headers: {},
  })

However, the headers option is ignored in the @opentelemetry/exporter-trace-otlp-grpc package, as seen in the implementation here: https://github.com/open-telemetry/opentelemetry-js/blob/v1.x/experimental/packages/otlp-grpc-exporter-base/src/configuration/convert-legacy-otlp-grpc-options.ts#L36

This behavior can be confusing for library users, as demonstrated in these discussions: https://community.grafana.com/t/sending-one-simple-trace-to-tempo-via-http/82901/3 https://community.grafana.com/t/how-to-send-traces-from-node-js-otel-sdk-to-tempo/81283 Possible workarounds:

  1. Use metadata property
  2. Setting OTEL_EXPORTER_OTLP_HEADERS env variable

Are there any specific reasons why the gRPC exporter ignores the headers option? If so, I suggest explicitly documenting this behavior in the module's documentation to avoid confusion.

  • [x] This only affects the JavaScript OpenTelemetry library
  • [ ] This may affect other libraries, but I would like to get opinions here first

ruslan-mikhailov avatar Mar 04 '25 09:03 ruslan-mikhailov