diff --git a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts index d82f6cdc35b..01ff72cb2fa 100644 --- a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts +++ b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts @@ -158,6 +158,10 @@ export class FetchInstrumentation extends InstrumentationBase< api.propagation.inject(api.context.active(), options.headers, { set: (h, k, v) => h.set(k, typeof v === 'string' ? v : String(v)), }); + } else if(options.headers instanceof Headers) { + api.propagation.inject(api.context.active(), options.headers, { + set: (h, k, v) => h.set(k, typeof v === 'string' ? v : String(v)), + }); } else { const headers: Partial> = {}; api.propagation.inject(api.context.active(), headers); diff --git a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts index 1fa0d465c7d..1de5b795d0a 100644 --- a/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts +++ b/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts @@ -535,6 +535,32 @@ describe('fetch', () => { assert.ok(typeof r.headers.get(X_B3_TRACE_ID) === 'string'); }); + it('should keep custom headers with a request object and a headers object', () => { + const r = new Request('url', { + headers: new Headers({'foo': 'bar'}) + }); + window.fetch(r).catch(() => {}); + assert.ok(r.headers.get('foo') === 'bar'); + }); + + it('should keep custom headers with url, untyped request object and typed headers object', () => { + const url = 'url'; + const init = { + headers: new Headers({'foo': 'bar'}) + }; + window.fetch(url, init).catch(() => {}); + assert.ok(init.headers.get('foo') === 'bar'); + }); + + it('should keep custom headers with url, untyped request object and untyped headers object', () => { + const url = 'url'; + const init = { + headers: {'foo': 'bar'} + }; + window.fetch(url, init).catch(() => {}); + assert.ok(init.headers['foo'] === 'bar'); + }); + it('should pass request object as first parameter to the original function (#2411)', () => { const r = new Request(url); return window.fetch(r).then(() => { diff --git a/packages/opentelemetry-sdk-trace-base/src/config.ts b/packages/opentelemetry-sdk-trace-base/src/config.ts index 38c869cfa74..042427d04a0 100644 --- a/packages/opentelemetry-sdk-trace-base/src/config.ts +++ b/packages/opentelemetry-sdk-trace-base/src/config.ts @@ -27,6 +27,7 @@ import { const env = getEnv(); const FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn; +const DEFAULT_RATIO = 1; /** * Default configuration. For fields with primitive values, any user-provided @@ -79,8 +80,6 @@ export function buildSamplerFromEnv( } } -const DEFAULT_RATIO = 1; - function getSamplerProbabilityFromEnv( env: Required ): number | undefined { diff --git a/website_docs/_index.md b/website_docs/_index.md index 859f8026cc9..e0846eac64c 100644 --- a/website_docs/_index.md +++ b/website_docs/_index.md @@ -1,9 +1,14 @@ --- -title: "Javascript" +title: Javascript weight: 20 -description: > +description: >- A language-specific implementation of OpenTelemetry in JavaScript (for Node.JS & the browser). +cascade: + github_repo: &repo /~https://github.com/open-telemetry/opentelemetry-js + github_subdir: website_docs + path_base_for_github_subdir: content/en/docs/js/ + github_project_repo: *repo --- This page contains an introduction to OpenTelemetry in JavaScript. This guide