opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

fix(instrumentation-fetch, instrumentation-xml-http-request) content length attributes missing

Open arriIsHere opened this issue 11 months ago • 5 comments
trafficstars

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.

  1. Open the examples/opentelemetry-web/examples/fetchexample
  2. Start example
  3. Note that the GET event has a http.response_content_length attribute
  4. Add the ignoreNetworkEvents: true config to the FetchInstrumentation in the index.js file
  5. Run example
  6. 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

arriIsHere avatar Dec 12 '24 15:12 arriIsHere