fix(otlp-exporter-base): replaced usage of window with _globalThis #4157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
The issue being fixed is an error being thrown when trying to export logs from code running in a web worker. I noticed that the exporter is using the 'window' object instead of globalThis (or the _globalThis instance provided by the otlp lib). The 'window' is not available to code running in a worker, only to the main app thread.
Please see this issue #3991
Fixes #3991
Short description of the changes
Replaced the usage of 'window' with the '_globalThis' instance exposed by @opentelemetry/core
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
In order to reproduce the issue, try to export logs from code running in a web worker. You would get an error indicating that 'window' is not defined.
I have a patched version replacing 'window' with 'globalThis' in which the issue no longer occurs.
I also ran the 'compile' and 'test' scripts before and after my changes and observed the same results.
Checklist: