diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 7d39f3e228..3ddc5c1f88 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -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) diff --git a/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts b/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts index e4ce4f9f5a..439ca17cc8 100644 --- a/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts @@ -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', () => { diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts index 062d6fde4a..59d03b9c85 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -339,7 +339,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase { `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` + ); + }); }); });