Skip to content

Commit

Permalink
Merge branch 'main' into simple-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Aug 29, 2021
2 parents edceb8d + dbfabd2 commit bb76be1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, unknown>> = {};
api.propagation.inject(api.context.active(), headers);
Expand Down
26 changes: 26 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
3 changes: 1 addition & 2 deletions packages/opentelemetry-sdk-trace-base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,8 +80,6 @@ export function buildSamplerFromEnv(
}
}

const DEFAULT_RATIO = 1;

function getSamplerProbabilityFromEnv(
env: Required<ENVIRONMENT>
): number | undefined {
Expand Down
9 changes: 7 additions & 2 deletions website_docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
title: "Javascript"
title: Javascript
weight: 20
description: >
description: >-
<img width="35" src="https://raw.github.com/open-telemetry/opentelemetry.io/main/iconography/32x32/JS_SDK.svg"></img>
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
Expand Down

0 comments on commit bb76be1

Please sign in to comment.