vercel / otel

OTEL tracing for Vercel
https://vercel.com/docs/observability/otel-overview
40 stars 9 forks source link

Fetch's propagateContext option is ignored when false #108

Open morley92 opened 4 months ago

morley92 commented 4 months ago

The docs suggest that any individual fetch request can be overwritten to start/stop propagating context

propagateContext: boolean: overrides propagateContextUrls for this call.

Example usage of this argument below -

const response = await fetch('http://some-url', {
  opentelemetry: {
    propagateContext: false // or true
  }
})

The source code, I believe incorrectly, only considers propagateContext if the value is truthy - see here

if (init?.opentelemetry?.propagateContext) {
  return init.opentelemetry.propagateContext;
}

This should be more like this -

if (typeof init?.opentelemetry?.propagateContext === 'boolean') {
  return init.opentelemetry.propagateContext;
}

This way, regardless of whether propagateContext is true or false, it will cause shouldPropagate to return early with the appropriate value, instead of only returning early when propagateContext is true.