Skip to content

Commit 1be7c91

Browse files
committed
make it an array and add them all as listeners
1 parent 4a1eee3 commit 1be7c91

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export abstract class OTLPExporterBase<
3737
ServiceRequest,
3838
> {
3939
public readonly url: string;
40-
public readonly shutDownEvent: ShutdownEvent;
41-
public readonly isShutdownEventDisabled: boolean;
40+
public readonly shutDownEvents: ShutdownEvent[];
4241
public readonly hostname: string | undefined;
4342
public readonly timeoutMillis: number;
4443
protected _concurrencyLimit: number;
@@ -50,10 +49,7 @@ export abstract class OTLPExporterBase<
5049
*/
5150
constructor(config: T = {} as T) {
5251
this.url = this.getDefaultUrl(config);
53-
this.isShutdownEventDisabled = config.isShutdownEventDisabled;
54-
if (!config.isShutdownEventDisabled) {
55-
this.shutDownEvent = config.shutDownEvent ?? 'unload';
56-
}
52+
this.shutDownEvents = config.shutDownEvents ?? ['unload'];
5753
if (typeof config.hostname === 'string') {
5854
this.hostname = config.hostname;
5955
}

experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ export abstract class OTLPExporterBrowserBase<
5353
}
5454

5555
onInit(): void {
56-
if (this.shutDownEvent) {
57-
_globalThis.addEventListener(
58-
this.shutDownEvent ?? 'unload',
59-
this.shutdown
60-
);
61-
}
56+
this.shutDownEvents?.forEach(browserEvent => {
57+
_globalThis.addEventListener(browserEvent, this.shutdown);
58+
});
6259
}
6360

6461
onShutdown(): void {
65-
if (this.shutDownEvent) {
66-
_globalThis.removeEventListener(
67-
this.shutDownEvent ?? 'unload',
68-
this.shutdown
69-
);
70-
}
62+
this.shutDownEvents?.forEach(browserEvent => {
63+
_globalThis.removeEventListener(browserEvent, this.shutdown);
64+
});
7165
}
7266

7367
send(

experimental/packages/otlp-exporter-base/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export type ShutdownEvent = 'unload' | 'onhide' | 'pagehide' | 'beforeunload';
5353
* Collector Exporter base config
5454
*/
5555
export interface OTLPExporterConfigBase {
56-
isShutdownEventDisabled?: boolean;
57-
shutDownEvent?: ShutdownEvent;
56+
shutDownEvents?: ShutdownEvent[];
5857
headers?: Partial<Record<string, unknown>>;
5958
hostname?: string;
6059
url?: string;

0 commit comments

Comments
 (0)