opentelemetry-js
opentelemetry-js copied to clipboard
fix(instrumentation-fetch, instrumentation-xml-http-request) content length attributes missing
Which problem is this PR solving?
http.response_content_length and http.response_content_length_uncompressed attributes are not present on network spans from instrumentation-xml-http-request and instrumentation-fetch plugins when the ignoreNetworkEvents configuration property is set to true
This PR adds the addSpanContentLengthAttributes utility method to @opentelemetry/sdk-trace-web removing the logic for adding content length related attributes from the addSpanNetworkEvents method.
Fixes #5229
Short description of the changes
By skipping over the call to addSpanNetworkEvents the mentioned attributes were not getting added to the main and preflight network spans. We moved the logic for adding the content length attributes to the new addSpanContentLengthAttributes method. This new method will be called regardless of if ignoreNetworkEvents is set to true in the config.
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Automated unit tests were written as well as testing with the fetch and xhr examples to verify the attributes are being added with the proposed code.
- Open the examples/opentelemetry-web/examples/fetchexample
- Start example
- Note that the GET event has a http.response_content_length attribute
- Add the ignoreNetworkEvents: true config to the FetchInstrumentation in the index.js file
- Run example
- The http.response_content_length attribute should still be present on the GET span
Checklist:
- [x] Followed the style guidelines of this project
- [x] Unit tests have been added
- [x] Documentation has been updated