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

fix(instrumentation-xhr): http.url attribute should be absolute #3200

Merged
merged 5 commits into from
Nov 22, 2022

Conversation

t2t2
Copy link
Contributor

@t2t2 t2t2 commented Aug 25, 2022

Which problem is this PR solving?

As per the specification http.url attribute should be "Full HTTP request URL in the form scheme://host[:port]/path?query[#fragment]." Currently if a XHR request is done with a relative URL, then the http.url attribute is also relative

Also added a test that checks this in fetch instrumentation

Short description of the changes

Added relative -> abs conversion via parseUrl

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@t2t2 t2t2 requested a review from a team August 25, 2022 12:04
@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #3200 (3d0556a) into main (b9f5561) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3200      +/-   ##
==========================================
- Coverage   93.29%   93.28%   -0.02%     
==========================================
  Files         247      247              
  Lines        7352     7352              
  Branches     1512     1512              
==========================================
- Hits         6859     6858       -1     
- Misses        493      494       +1     
Impacted Files Coverage Δ
...emetry-instrumentation-xml-http-request/src/xhr.ts 97.58% <ø> (ø)
...-trace-base/src/platform/node/RandomIdGenerator.ts 87.50% <0.00%> (-6.25%) ⬇️

@t2t2 t2t2 changed the title Fix xhr absolute fix(instrumentation-xhr): http.url attribute should be absolute Aug 25, 2022
@t2t2
Copy link
Contributor Author

t2t2 commented Aug 25, 2022

Lack of changes in fetch instrumentation actually brings up a small but significant difference in the ignoreUrls config option of XHR and fetch instrumentations

In fetch instrumentation already parsed URL is passed to _createSpan

const url = web.parseUrl(args[0] instanceof Request ? args[0].url : args[0]).href;

In both instrumentations, ignoreUrls check is in _createSpan method, which means in fetch absolute url is always used while in xhr it depends on what URL was passed to XHR.open call. Therefore when using ignoreUrls you need to either have separate configs for these instrumentations (which sucks), or make sure your regexp works with both (unintuitive and undocumented) and have strings in both absolute and relative versions (string being exact match check is worse DX than having it just be substring/includes check</personal opinion>)

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this!

@@ -339,7 +339,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRe
kind: api.SpanKind.CLIENT,
attributes: {
[SemanticAttributes.HTTP_METHOD]: method,
[SemanticAttributes.HTTP_URL]: url,
[SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),
Copy link
Member

@legendecas legendecas Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: we have several call sites of parseUrl in the instrumentation. I believe we can parse the URL at the beginning of the span creation, and keep using that parsed URL to avoid duplicated parsing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usages of pareUrl() looks like they are processing a past in property -- So I don't think they should be changed.

@github-actions
Copy link

This PR 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 Oct 31, 2022
@dyladan dyladan removed the stale label Nov 2, 2022
@legendecas legendecas merged commit c9a3494 into open-telemetry:main Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants