Skip to content

Commit 9945c4b

Browse files
Grunetdyladan
andauthored
fix(opentelemetry-sdk-trace-web): don't crash in runtimes where location isn't defined (open-telemetry#3715)
* fix(opentelemetry-sdk-trace-web): don't crash in runtimes where location isn't defined * chore: updated changelog * chore(opentelemetry-sdk-trace-web): fix linter issues * fix(opentelemetry-sdk-trace-web): Remove broken test and replace with comment --------- Co-authored-by: Daniel Dyla <[email protected]>
1 parent 9328558 commit 9945c4b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
1616
### :bug: (Bug Fix)
1717

1818
* fix(instrumentation-http): fixed description for http.server.duration metric [#3710](https://github.com/open-telemetry/opentelemetry-js/pull/3710)
19+
* 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)
1920

2021
### :books: (Refine Doc)
2122

packages/opentelemetry-sdk-trace-web/src/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ export function parseUrl(url: string): URLLike {
307307
if (typeof URL === 'function') {
308308
return new URL(
309309
url,
310-
typeof document !== 'undefined' ? document.baseURI : location.href
310+
typeof document !== 'undefined'
311+
? document.baseURI
312+
: typeof location !== 'undefined' // Some JS runtimes (e.g. Deno) don't define this
313+
? location.href
314+
: undefined
311315
);
312316
}
313317
const element = getUrlNormalizingAnchor();

0 commit comments

Comments
 (0)