Skip to content

chore: remove unload event from OTLPExporterBrowserBase #4438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 15 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
6 changes: 6 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to experimental packages in this project will be documented
## Unreleased

### :boom: Breaking Change
* chore: remove unload event from OTLPExporterBrowserBase [#4438](https://github.com/open-telemetry/opentelemetry-js/pull/4438) @eldavojohn
* Reason: The 'unload' event prevents sites from taking advantage of Google's [backward/forward cache](https://web.dev/articles/bfcache#never_use_the_unload_event) and will be [deprecated](https://developer.chrome.com/articles/deprecating-unload/). It is now up to the consuming site to implement these shutdown events.
* This breaking change affects users under this scenario:
1. A user extends the exporter and overrides the shutdown function, and does something which is usually called by the unload listener
2. We remove the unload event listener
3. That user's overridden shutdown function no longer gets called

### :rocket: (Enhancement)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as otlpTypes from '../../types';
import { parseHeaders } from '../../util';
import { sendWithBeacon, sendWithXhr } from './util';
import { diag } from '@opentelemetry/api';
import { getEnv, baggageUtils, _globalThis } from '@opentelemetry/core';
import { getEnv, baggageUtils } from '@opentelemetry/core';

/**
* Collector Metric Exporter abstract base class
Expand Down Expand Up @@ -52,13 +52,9 @@ export abstract class OTLPExporterBrowserBase<
}
}

onInit(): void {
_globalThis.addEventListener('unload', this.shutdown);
}
onInit(): void {}

onShutdown(): void {
_globalThis.removeEventListener('unload', this.shutdown);
}
onShutdown(): void {}

send(
items: ExportItem[],
Expand Down