Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2

### :bug: Bug Fixes

* fix(otlp-exporter-base): use sendBeacon with empty headers [#6216](https://github.com/open-telemetry/opentelemetry-js/pull/6216) @YangJonghun
* fix(instrumentation-grpc): attach correct name to diag message [#6097](https://github.com/open-telemetry/opentelemetry-js/pull/6043) @pichlermarc
* fix(opentelemetry-sdk-node): default to otlp if OTEL_METRICS_EXPORTER is empty [#6092](https://github.com/open-telemetry/opentelemetry-js/pull/6092) @jeengbe
* fix(configuration): merge service name from OTEL_SERVICE_NAME instead of replacing all resource attributes [#6162](https://github.com/open-telemetry/opentelemetry-js/pull/6162) @maryliag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function createLegacyOtlpBrowserExportDelegate<Internal, Response>(
export function inferExportDelegateToUse(
configHeaders: OTLPExporterConfigBase['headers']
) {
if (!configHeaders && typeof navigator.sendBeacon === 'function') {
const isEmptyHeaders =
configHeaders == null ||
(typeof configHeaders === 'object' &&
Object.keys(configHeaders).length === 0);

if (isEmptyHeaders && typeof navigator.sendBeacon === 'function') {
return createOtlpSendBeaconExportDelegate;
} else if (typeof globalThis.fetch !== 'undefined') {
return createOtlpFetchExportDelegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe('createLegacyBrowserDelegate', function () {
assert.equal(delegate, createOtlpSendBeaconExportDelegate);
});

it('uses the beacon delegate when headers is empty object', function () {
const delegate = inferExportDelegateToUse({});
assert.equal(delegate, createOtlpSendBeaconExportDelegate);
});

it('uses the fetch delegate when headers are provided', function () {
const delegate = inferExportDelegateToUse({ foo: 'bar' });
assert.equal(delegate, createOtlpFetchExportDelegate);
Expand Down