Skip to content

Commit c9a3494

Browse files
authored
fix(instrumentation-xhr): http.url attribute should be absolute (#3200)
1 parent b9f5561 commit c9a3494

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

experimental/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ All notable changes to experimental packages in this project will be documented
1313

1414
### :bug: (Bug Fix)
1515

16+
* fix(instrumentation-xhr): http.url attribute should be absolute [#3200](https://github.com/open-telemetry/opentelemetry-js/pull/3200) @t2t2
17+
1618
### :books: (Refine Doc)
1719

1820
### :house: (Internal)

experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,17 @@ describe('fetch', () => {
837837
`event ${PTN.REQUEST_START} is not defined`
838838
);
839839
});
840+
841+
it('should have an absolute http.url attribute', () => {
842+
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
843+
const attributes = span.attributes;
844+
845+
assert.strictEqual(
846+
attributes[SemanticAttributes.HTTP_URL],
847+
location.origin + '/get',
848+
`attributes ${SemanticAttributes.HTTP_URL} is wrong`
849+
);
850+
});
840851
});
841852

842853
describe('when PerformanceObserver is undefined', () => {

experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRe
339339
kind: api.SpanKind.CLIENT,
340340
attributes: {
341341
[SemanticAttributes.HTTP_METHOD]: method,
342-
[SemanticAttributes.HTTP_URL]: url,
342+
[SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),
343343
},
344344
});
345345

experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,17 @@ describe('xhr', () => {
787787
`event ${PTN.REQUEST_START} is not defined`
788788
);
789789
});
790+
791+
it('should have an absolute http.url attribute', () => {
792+
const span: tracing.ReadableSpan = exportSpy.args[0][0][0];
793+
const attributes = span.attributes;
794+
795+
assert.strictEqual(
796+
attributes[SemanticAttributes.HTTP_URL],
797+
location.origin + '/get',
798+
`attributes ${SemanticAttributes.HTTP_URL} is wrong`
799+
);
800+
});
790801
});
791802

792803
});

0 commit comments

Comments
 (0)