Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-trace-web): remove browsing context only api dependency on utils #2714

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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