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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(instrumentation-xhr): http.url attribute should be absolute [#3200](https://github.com/open-telemetry/opentelemetry-js/pull/3200) @t2t2

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,17 @@ describe('fetch', () => {
`event ${PTN.REQUEST_START} is not defined`
);
});

it('should have an absolute http.url attribute', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const attributes = span.attributes;

assert.strictEqual(
attributes[SemanticAttributes.HTTP_URL],
location.origin + '/get',
`attributes ${SemanticAttributes.HTTP_URL} is wrong`
);
});
});

describe('when PerformanceObserver is undefined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,17 @@ describe('xhr', () => {
`event ${PTN.REQUEST_START} is not defined`
);
});

it('should have an absolute http.url attribute', () => {
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
const attributes = span.attributes;

assert.strictEqual(
attributes[SemanticAttributes.HTTP_URL],
location.origin + '/get',
`attributes ${SemanticAttributes.HTTP_URL} is wrong`
);
});
});

});
Expand Down