feat(browser otlp exporter): add fetch transport for fetch-only environments#5807
Conversation
|
|
…on, xhr and fetch delegates
2c4a8b6 to
e3cd53a
Compare
dyladan
left a comment
There was a problem hiding this comment.
Seems reasonable to me and I don't see any obvious issues. I'd wait for @pichlermarc review before merging because he's much closer to the exporters but overall LGTM
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5807 +/- ##
=======================================
Coverage 95.06% 95.06%
=======================================
Files 307 307
Lines 8031 8031
Branches 1627 1627
=======================================
Hits 7635 7635
Misses 396 396
🚀 New features to boost your workflow:
|
|
Hi guys, any news on this? |
|
We looked at it during the SIG meeting two or three weeks ago but @pichlermarc (who's the de-facto code owner for the exporters) was on vacation at the time. IIRC there was also talks of using |
yes, my personal preference would be to drop XHR in favor of There has been some push-back to doing this in the past - so I will ask around in the SIG again today and will report back here. |
pichlermarc
left a comment
There was a problem hiding this comment.
Alright, so looks like we'll move ahead with this PR here and then we'll drop XHR in a later release.
@SacDeNoeuds would you mind marking XhrTransport and associated types as @depreacated? (referring to the newly added FetchTransport as a replacement - with polyfill provided by the end-user if necessary.
I'll create a follow-up issue to tackle removing XHR eventually once this PR has merged.
…ndBeacon is unavailable
| export function inferExportDelegateToUse( | ||
| configHeaders: OTLPExporterConfigBase['headers'] | ||
| ) { | ||
| if (!configHeaders && typeof navigator.sendBeacon === 'function') { | ||
| return createOtlpSendBeaconExportDelegate; | ||
| } else if (typeof globalThis.fetch !== 'undefined') { | ||
| return createOtlpFetchExportDelegate; | ||
| } else { | ||
| return createOtlpSendBeaconExportDelegate(options, serializer); | ||
| return createOtlpXhrExportDelegate; | ||
| } | ||
| } |
There was a problem hiding this comment.
The former test I wrote was ineffective, every createOtlpXxExporterDelegate returns an instance of the class OTLPExportDelegate, the initial tests were flawed considering they were testing the instance constructor and it was the same constructor – OTLPExportDelegate – in all cases.
I added an intermediary testable function and updated the test.
pichlermarc
left a comment
There was a problem hiding this comment.
Thanks for making the changes, just needs some more adjustment on the changelog and we should be good to go. :)
|
oh - looks like some of the tests in the individual exporters now need to be adapted too as they expect XHR to be used. There is no need to test all cases in the individual exporters as we do test that behavior in the base package already, but we should change the tests from XHR to fetch there. |
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
|
Thanks again for your reviews, I took a bit of time to update all the tests, all tests should pass now. It may be worth adding the script |
pichlermarc
left a comment
There was a problem hiding this comment.
Looks good, thank you for working on this 🙌
|
Thanks @pichlermarc, I just fixed a small changelog conflict. I suppose you will be dealing with PR merging? |
|
Thank you for your contribution @SacDeNoeuds! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
…onments (open-telemetry#5807) Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Which problem is this PR solving?
In service workers,
XMLHttpRequestandnavigator.sendBeaconare both unavailable, making theOTLPTraceExporterfrom@opentelemetry/exporter-trace-otlp-httpunusable.Fixes #4631
Short description of the changes
Add the fetch transport and enables it only when both xhr and beacons are unavailable.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I took the xhr transport tests and adapted the
arrangestep for the fetch transport.See the test file: experimental/packages/otlp-exporter-base/test/browser/fetch-transport.test.ts
Checklist:
Additional context