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

[otlp-exporter] web exporters should set User-Agent header upon requests. #3808

Closed
llc1123 opened this issue May 16, 2023 · 7 comments
Closed
Labels
feature-request spec-feature This is a request to implement a new feature which is already specified by the OTel specification stale

Comments

@llc1123
Copy link
Contributor

llc1123 commented May 16, 2023

        Error: Uncaught AssertionError: 'Refused to set unsafe header "User-Agent"' === 'Request Timeout' (webpack-internal:///../../../node_modules/assert/assert.js:199)

Originally posted by @JamieDanielson in #3790 (comment)

The current test based on headless Chrome will return above error due to Chrome's limitation.

Setting the user-agent header in Chrome browser by Headers object or using fetch() will have no effect but won't throw any error.
Using XMLHttpRequest.setRequestHeader() will throw the above error.

As other browsers (tested on latest Firefox and Safari) work as expected, I suggest we use a try...catch block and ignore the output and complete the implementation as per specification.

Another thing is that the current implementation uses sendBeacon if available and if no custom header being set. As the user-agent header should be present as per spec. We should remove the use of sendBeacon.

We can also rely solely on fetch and drop XMLHttpRequest. Users should use a polyfill for fetch if they want to support legacy browsers.

Related: #3790 #3806 #3291

@llc1123 llc1123 changed the title [BUG] Cannot set User-Agent header in web [BUG] Web exporters should set User-Agent header upon requests. May 16, 2023
@llc1123 llc1123 changed the title [BUG] Web exporters should set User-Agent header upon requests. [otlp-exporter] web exporters should set User-Agent header upon requests. May 16, 2023
@llc1123
Copy link
Contributor Author

llc1123 commented May 16, 2023

Also, if the user-agent header is not allowed to be overwritten by the user (which I believe the spec says so), we can implement this in the base packages instead of in separate exporter packages (simply apply user-agent after applying the configured headers). We can also warn the user if they attempt to set user-agent by config.

@pichlermarc pichlermarc added feature-request spec-feature This is a request to implement a new feature which is already specified by the OTel specification labels May 17, 2023
@llc1123
Copy link
Contributor Author

llc1123 commented May 17, 2023

We can also rely solely on fetch and drop XMLHttpRequest. Users should use a polyfill for fetch if they want to support legacy browsers.

I found some usages of modern javascript features (such as Object.entries()) in the sendWithXhr function. Is there a guideline of browser compatibility or I suggest we just use fetch instead.

@llc1123
Copy link
Contributor Author

llc1123 commented May 18, 2023

I've finished the user-agent part in #3811. Should I replace sendWithXhr with fetch?

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jul 24, 2023
@dyladan dyladan removed the stale label Jul 26, 2023
@dyladan
Copy link
Member

dyladan commented Jul 26, 2023

not stale

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jan 15, 2024
Copy link

This issue was closed because it has been stale for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request spec-feature This is a request to implement a new feature which is already specified by the OTel specification stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants