From 24997089daf6d422494d112cf5531fe115eaa201 Mon Sep 17 00:00:00 2001 From: cristianmadularu <124408005+cristianmadularu@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:58:07 -0400 Subject: [PATCH] fix(otlp-exporter-base): replaced usage of window with _globalThis (#4157) Co-authored-by: Marc Pichler --- experimental/CHANGELOG.md | 2 ++ .../src/platform/browser/OTLPExporterBrowserBase.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 11e98847da..bc0fb011da 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,6 +21,8 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) +* fix(otlp-exporter-base): replaced usage of window with _globalThis [#4157](https://github.com/open-telemetry/opentelemetry-js/pull/4157) @cristianmadularu + ### :books: (Refine Doc) ### :house: (Internal) diff --git a/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts b/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts index 2888e317df..dbe02b222d 100644 --- a/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts +++ b/experimental/packages/otlp-exporter-base/src/platform/browser/OTLPExporterBrowserBase.ts @@ -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 } from '@opentelemetry/core'; +import { getEnv, baggageUtils, _globalThis } from '@opentelemetry/core'; /** * Collector Metric Exporter abstract base class @@ -53,11 +53,11 @@ export abstract class OTLPExporterBrowserBase< } onInit(): void { - window.addEventListener('unload', this.shutdown); + _globalThis.addEventListener('unload', this.shutdown); } onShutdown(): void { - window.removeEventListener('unload', this.shutdown); + _globalThis.removeEventListener('unload', this.shutdown); } send(