From a3078b6eb9766b08ba34846ec532f520d55f3490 Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Mon, 4 Apr 2022 14:28:29 +0200 Subject: [PATCH] fix(instrumentation-xml-http-request): use previous parseUrl approach as the new approach throws on relative paths. --- .../src/xhr.ts | 8 +++++++- .../test/xhr.test.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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 dfadaed3869..776e738dc7f 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -26,9 +26,9 @@ import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { addSpanNetworkEvents, getResource, - parseUrl, PerformanceTimingNames as PTN, shouldPropagateTraceHeaders, + URLLike } from '@opentelemetry/sdk-trace-web'; import { EventNames } from './enums/EventNames'; import { @@ -40,6 +40,12 @@ import { import { VERSION } from './version'; import { AttributeNames } from './enums/AttributeNames'; +function parseUrl(url: string): URLLike { + const element = document.createElement('a'); + element.href = url; + return element; +} + // how long to wait for observer to collect information about resources // this is needed as event "load" is called before observer // hard to say how long it should really wait, seems like 300ms is diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts b/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts index 0f82d8b16c5..ba45094f3f5 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts @@ -29,7 +29,7 @@ import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { PerformanceTimingNames as PTN, WebTracerProvider, - parseUrl, + URLLike, } from '@opentelemetry/sdk-trace-web'; import * as assert from 'assert'; import * as sinon from 'sinon'; @@ -48,6 +48,12 @@ class DummySpanExporter implements tracing.SpanExporter { } } +function parseUrl(url: string): URLLike { + const element = document.createElement('a'); + element.href = url; + return element; +} + const XHR_TIMEOUT = 2000; const getData = (