Skip to content

Commit

Permalink
fix(sdk-trace-web): remove browsing context only api dependency on utils
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jan 13, 2022
1 parent d315b0a commit 57e3299
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
21 changes: 21 additions & 0 deletions doc/web-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Web API Usages Guidance

The packages of OpenTelemetry that targeting web platforms should be compatible
with the following web environments:

- [Browsing Context](https://developer.mozilla.org/en-US/docs/Glossary/Browsing_context),
- [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers).

As such, the usage of Web API that depends on APIs like [`window`],
[`document`] and [`navigator`] is discouraged.

If the use of the browsing context API is necessary, like adding `onload`
listeners, an alternative code path for Web Worker environment should also be
supported.

It is an exception to above guidance if the package is instrumenting the
browsing context only.

[`window`]: https://developer.mozilla.org/en-US/docs/Web/API/window
[`document`]: https://developer.mozilla.org/en-US/docs/Web/API/Document
[`navigator]: https://developer.mozilla.org/en-US/docs/Web/API/Navigator
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"browser": true,
"jquery": true
},
...require('../../../eslint.config.js')
}
2 changes: 0 additions & 2 deletions packages/opentelemetry-sdk-trace-web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"browser": true,
"jquery": true
},
...require('../../eslint.config.js')
}
4 changes: 2 additions & 2 deletions packages/opentelemetry-sdk-trace-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function getResource(
}
const sorted = sortResources(filteredResources);

if (parsedSpanUrl.origin !== window.location.origin && sorted.length > 1) {
if (parsedSpanUrl.origin !== location.origin && sorted.length > 1) {
let corsPreFlightRequest: PerformanceResourceTiming | undefined = sorted[0];
let mainRequest: PerformanceResourceTiming = findMainRequest(
sorted,
Expand Down Expand Up @@ -421,7 +421,7 @@ export function shouldPropagateTraceHeaders(
}
const parsedSpanUrl = parseUrl(spanUrl);

if (parsedSpanUrl.origin === window.location.origin) {
if (parsedSpanUrl.origin === location.origin) {
return true;
} else {
return propagateTraceHeaderUrls.some(propagateTraceHeaderUrl =>
Expand Down

0 comments on commit 57e3299

Please sign in to comment.