diff --git a/CHANGELOG.md b/CHANGELOG.md index e894e1efd2..2954118213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) * fix(instrumentation-http): fixed description for http.server.duration metric [#3710](https://github.com/open-telemetry/opentelemetry-js/pull/3710) +* fix(opentelemetry-sdk-trace-web): don't crash in runtimes where location isn't defined [#3715](https://github.com/open-telemetry/opentelemetry-js/pull/3715) ### :books: (Refine Doc) diff --git a/packages/opentelemetry-sdk-trace-web/src/utils.ts b/packages/opentelemetry-sdk-trace-web/src/utils.ts index 127454b0a6..2027abc42f 100644 --- a/packages/opentelemetry-sdk-trace-web/src/utils.ts +++ b/packages/opentelemetry-sdk-trace-web/src/utils.ts @@ -307,7 +307,11 @@ export function parseUrl(url: string): URLLike { if (typeof URL === 'function') { return new URL( url, - typeof document !== 'undefined' ? document.baseURI : location.href + typeof document !== 'undefined' + ? document.baseURI + : typeof location !== 'undefined' // Some JS runtimes (e.g. Deno) don't define this + ? location.href + : undefined ); } const element = getUrlNormalizingAnchor();