@opentelemetry/instrumentation-xml-http-request 0.300.0-development.1 → 0.300.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/version.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const VERSION = "0.300.0-development.1";
2
+ const VERSION = "0.300.0";
3
3
  //#endregion
4
4
  exports.VERSION = VERSION;
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0-development.1';\n"],"mappings":";AAMA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
package/dist/version.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const VERSION = "0.300.0-development.1";
2
+ const VERSION = "0.300.0";
3
3
  //#endregion
4
4
  export { VERSION };
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0-development.1';\n"],"mappings":";AAMA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
package/dist/xhr.cjs CHANGED
@@ -198,7 +198,7 @@ var XMLHttpRequestInstrumentation = class extends _opentelemetry_instrumentation
198
198
  return (original) => {
199
199
  const plugin = this;
200
200
  return function patchOpen(...args) {
201
- if (!plugin._isEnabled) return original.apply(this, args);
201
+ if (!plugin._enabled) return original.apply(this, args);
202
202
  const method = args[0];
203
203
  const url = args[1];
204
204
  plugin._createSpan(this, url, method);
@@ -276,7 +276,7 @@ var XMLHttpRequestInstrumentation = class extends _opentelemetry_instrumentation
276
276
  }
277
277
  return (original) => {
278
278
  return function patchSend(...args) {
279
- if (!plugin._isEnabled) return original.apply(this, args);
279
+ if (!plugin._enabled) return original.apply(this, args);
280
280
  const xhrMem = plugin._xhrMem.get(this);
281
281
  if (!xhrMem) return original.apply(this, args);
282
282
  const currentSpan = xhrMem.span;
@@ -311,18 +311,23 @@ var XMLHttpRequestInstrumentation = class extends _opentelemetry_instrumentation
311
311
  * implements enable function
312
312
  */
313
313
  enable() {
314
- if (this._isEnabled) return;
314
+ if (this._enabled) return;
315
315
  if (this._isXhrPatched) {
316
316
  this._diag.debug("reactivating existing patch on", this.moduleName, this.version);
317
- this._isEnabled = true;
317
+ this._enabled = true;
318
318
  return;
319
319
  }
320
320
  try {
321
321
  this._diag.debug("applying patch to", this.moduleName, this.version);
322
- this._wrap(XMLHttpRequest.prototype, "open", this._patchOpen());
323
- this._wrap(XMLHttpRequest.prototype, "send", this._patchSend());
322
+ const proto = XMLHttpRequest.prototype;
323
+ for (const name of ["open", "send"]) if (typeof proto[name] !== "function") {
324
+ this._diag.warn(`XMLHttpRequest.prototype.${name} is missing or not a function; instrumentation will not be enabled. Register the instrumentation after any XMLHttpRequest polyfill, or call enable() once it is available.`);
325
+ return;
326
+ }
327
+ this._wrap(proto, "open", this._patchOpen());
328
+ this._wrap(proto, "send", this._patchSend());
324
329
  this._isXhrPatched = true;
325
- this._isEnabled = true;
330
+ this._enabled = true;
326
331
  } catch (err) {
327
332
  this._unwrap(XMLHttpRequest.prototype, "open");
328
333
  this._unwrap(XMLHttpRequest.prototype, "send");
@@ -333,8 +338,8 @@ var XMLHttpRequestInstrumentation = class extends _opentelemetry_instrumentation
333
338
  * implements disable function
334
339
  */
335
340
  disable() {
336
- if (!this._isEnabled) return;
337
- this._isEnabled = false;
341
+ if (!this._enabled) return;
342
+ this._enabled = false;
338
343
  this._tasksCount = 0;
339
344
  this._xhrMem = /* @__PURE__ */ new WeakMap();
340
345
  this._usedResources = /* @__PURE__ */ new WeakSet();
package/dist/xhr.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.cjs","names":["InstrumentationBase","VERSION","parseUrl","shouldPropagateTraceHeaders","api","PTN","ATTR_HTTP_RESPONSE_STATUS_CODE","getResource","isUrlIgnored","normalizeHttpRequestMethod","ATTR_HTTP_REQUEST_METHOD","ATTR_HTTP_REQUEST_METHOD_ORIGINAL","ATTR_URL_FULL","ATTR_SERVER_ADDRESS","serverPortFromUrl","ATTR_SERVER_PORT","ATTR_ERROR_TYPE","hrTime","getXHRBodyLength","ATTR_HTTP_REQUEST_BODY_SIZE"],"sources":["../src/xhr.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/web-common';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n * @deprecated See https://github.com/open-telemetry/opentelemetry-browser/tree/main/packages/instrumentation#xhr-xmlhttprequest\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n\n // Note: Intentionally *not* using `_enabled` as the field name to avoid\n // any possible confusion with the `_enabled` field used on the *Node.js*\n // InstrumentationBase class.\n // Also not initializing the fields to `false` because the base class\n // constructor already calls `enable` modifying their values and it will\n // set the instrumentations in a bad state (enabled, patched but with flags set to false)\n declare private _isEnabled: boolean;\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n performance.clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = performance.getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const attributes = {} as api.Attributes;\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n const name = normMethod;\n\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._isEnabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._isEnabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._isEnabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._isEnabled) {\n return;\n }\n this._isEnabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAM,wBAAwB;;;;;AAwC9B,IAAa,gCAAb,cAAmDA,+BAAAA,oBAAyD;CAC1G,YAA6B;CAC7B,UAA2BC,gBAAAA;CAC3B,aAAa,KAAK;CAElB,cAAsB;CACtB,0BAAkB,IAAI,QAAgC;CACtD,iCAAyB,IAAI,QAAmC;CAWhE,YAAY,SAA8C,CAAC,GAAG;EAC5D,MAAM,mDAAmDA,gBAAAA,SAAS,MAAM;CAC1E;CAEA,OAAO,CAAC;;;;;;;CAQR,YAAoB,KAAqB,SAAiB;EACxD,MAAM,OAAA,GAAMC,0BAAAA,SAAAA,CAAS,OAAO,CAAC,CAAC;EAC9B,IACE,EAAA,GAACC,0BAAAA,4BAAAA,CACC,KACA,KAAK,UAAU,CAAC,CAAC,4BACnB,GACA;GACA,MAAM,UAA4C,CAAC;GACnD,mBAAI,YAAY,OAAOC,mBAAI,QAAQ,OAAO,GAAG,OAAO;GACpD,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAChC,KAAK,MAAM,MAAM,2CAA2C;GAE9D;EACF;EACA,MAAM,UAAsC,CAAC;EAC7C,mBAAI,YAAY,OAAOA,mBAAI,QAAQ,OAAO,GAAG,OAAO;EACpD,OAAO,KAAK,OAAO,CAAC,CAAC,SAAQ,QAAO;GAClC,IAAI,iBAAiB,KAAK,OAAO,QAAQ,IAAI,CAAC;EAChD,CAAC;CACH;;;;;;;CAQA,cACE,MACA,sBACM;EACN,mBAAI,QAAQ,KAAKA,mBAAI,MAAM,QAAQA,mBAAI,QAAQ,OAAO,GAAG,IAAI,SAAS;GACpE,MAAM,YAAY,KAAK,OAAO,UAAU,kBAAkB,EACxD,WAA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,WAAW,CAAC;GAC9D,KAAK,MAAM,eAAe,WAAW,QAAQ,KAAK,WAAW,CAAC;GAC9D,KAAK,gBAAgB;GACrB,KAAK,aAAa;EACpB,SAAS,KAAK;GAEZ,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,MAAM,KACT,uKAEA,GACF;EACF;CACF;;;;CAKA,UAAmB;EACjB,IAAI,CAAC,KAAK,YACR;EAEF,KAAK,aAAa;EAClB,KAAK,cAAc;EACnB,KAAK,0BAAU,IAAI,QAAgC;EACnD,KAAK,iCAAiB,IAAI,QAAmC;CAC/D;AACF"}
1
+ {"version":3,"file":"xhr.cjs","names":["InstrumentationBase","VERSION","parseUrl","shouldPropagateTraceHeaders","api","PTN","ATTR_HTTP_RESPONSE_STATUS_CODE","getResource","isUrlIgnored","normalizeHttpRequestMethod","ATTR_HTTP_REQUEST_METHOD","ATTR_HTTP_REQUEST_METHOD_ORIGINAL","ATTR_URL_FULL","ATTR_SERVER_ADDRESS","serverPortFromUrl","ATTR_SERVER_PORT","ATTR_ERROR_TYPE","hrTime","getXHRBodyLength","ATTR_HTTP_REQUEST_BODY_SIZE"],"sources":["../src/xhr.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/web-common';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n * @deprecated See https://github.com/open-telemetry/opentelemetry-browser/tree/main/packages/instrumentation#xhr-xmlhttprequest\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n\n // Not initialized: the base constructor calls enable() before subclass field\n // initializers run, so an initializer would reset the flag after patching.\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n performance.clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = performance.getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const attributes = {} as api.Attributes;\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n const name = normMethod;\n\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._enabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._enabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._enabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._enabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n const proto = XMLHttpRequest.prototype;\n // `_wrap` returns undefined, without throwing, on a missing or non-function\n // target, so a lone wrapped `open` would escape the catch and re-wrap on retry.\n for (const name of ['open', 'send'] as const) {\n if (typeof proto[name] !== 'function') {\n this._diag.warn(\n `XMLHttpRequest.prototype.${name} is missing or not a function; instrumentation will not be enabled. ` +\n 'Register the instrumentation after any XMLHttpRequest polyfill, or call enable() once it is available.'\n );\n return;\n }\n }\n this._wrap(proto, 'open', this._patchOpen());\n this._wrap(proto, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._enabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._enabled) {\n return;\n }\n this._enabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAM,wBAAwB;;;;;AAwC9B,IAAa,gCAAb,cAAmDA,+BAAAA,oBAAyD;CAC1G,YAA6B;CAC7B,UAA2BC,gBAAAA;CAC3B,aAAa,KAAK;CAElB,cAAsB;CACtB,0BAAkB,IAAI,QAAgC;CACtD,iCAAyB,IAAI,QAAmC;CAMhE,YAAY,SAA8C,CAAC,GAAG;EAC5D,MAAM,mDAAmDA,gBAAAA,SAAS,MAAM;CAC1E;CAEA,OAAO,CAAC;;;;;;;CAQR,YAAoB,KAAqB,SAAiB;EACxD,MAAM,OAAA,GAAMC,0BAAAA,SAAAA,CAAS,OAAO,CAAC,CAAC;EAC9B,IACE,EAAA,GAACC,0BAAAA,4BAAAA,CACC,KACA,KAAK,UAAU,CAAC,CAAC,4BACnB,GACA;GACA,MAAM,UAA4C,CAAC;GACnD,mBAAI,YAAY,OAAOC,mBAAI,QAAQ,OAAO,GAAG,OAAO;GACpD,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAChC,KAAK,MAAM,MAAM,2CAA2C;GAE9D;EACF;EACA,MAAM,UAAsC,CAAC;EAC7C,mBAAI,YAAY,OAAOA,mBAAI,QAAQ,OAAO,GAAG,OAAO;EACpD,OAAO,KAAK,OAAO,CAAC,CAAC,SAAQ,QAAO;GAClC,IAAI,iBAAiB,KAAK,OAAO,QAAQ,IAAI,CAAC;EAChD,CAAC;CACH;;;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,kCACA,KAAK,YACL,KAAK,OACP;GACA,KAAK,WAAW;GAChB;EACF;EAEA,IAAI;GACF,KAAK,MAAM,MAAM,qBAAqB,KAAK,YAAY,KAAK,OAAO;GACnE,MAAM,QAAQ,eAAe;GAG7B,KAAK,MAAM,QAAQ,CAAC,QAAQ,MAAM,GAChC,IAAI,OAAO,MAAM,UAAU,YAAY;IACrC,KAAK,MAAM,KACT,4BAA4B,KAAK,2KAEnC;IACA;GACF;GAEF,KAAK,MAAM,OAAO,QAAQ,KAAK,WAAW,CAAC;GAC3C,KAAK,MAAM,OAAO,QAAQ,KAAK,WAAW,CAAC;GAC3C,KAAK,gBAAgB;GACrB,KAAK,WAAW;EAClB,SAAS,KAAK;GAEZ,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,MAAM,KACT,uKAEA,GACF;EACF;CACF;;;;CAKA,UAAmB;EACjB,IAAI,CAAC,KAAK,UACR;EAEF,KAAK,WAAW;EAChB,KAAK,cAAc;EACnB,KAAK,0BAAU,IAAI,QAAgC;EACnD,KAAK,iCAAiB,IAAI,QAAmC;CAC/D;AACF"}
package/dist/xhr.d.cts CHANGED
@@ -41,7 +41,6 @@ declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpR
41
41
  private _tasksCount;
42
42
  private _xhrMem;
43
43
  private _usedResources;
44
- private _isEnabled;
45
44
  private _isXhrPatched;
46
45
  constructor(config?: XMLHttpRequestInstrumentationConfig);
47
46
  init(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.d.cts","names":[],"sources":["../src/xhr.d.ts"],"mappings":";;;;KAIY,8BAA8B,MAAM,IAAI,MAAM,KAAK;;;;UAI9C,4CAA4C;;;;;;;;EAQzD;;EAEA,+BAA+B;;;;;;EAM/B,aAAa,eAAe;;EAE5B,8BAA8B;;EAE9B;;EAEA;;;;;;cAMiB,sCAAsC,oBAAoB;WAClE;WACA;EACT;UACQ;UACA;UACA;UACA;UACA;EACR,YAAY,SAAS;EACrB;;;;;;;UAOQ;;;;;;;UAOA;;;;;;;EAOR,wBAAwB,MAAM,IAAI,MAAM,QAAQ;UACxC;;;;;;;;UAQA;;;;;;;UAOA;;;;;UAKA;;;;;;;UAOA;;;;;;;;UAQA;;;;;;;;UAQA;;;;;YAKE,eAAe,UAAU,iBAAiB;;;;;YAK1C,eAAe,UAAU,iBAAiB;;;;EAIpD;;;;EAIA"}
1
+ {"version":3,"file":"xhr.d.cts","names":[],"sources":["../src/xhr.d.ts"],"mappings":";;;;KAIY,8BAA8B,MAAM,IAAI,MAAM,KAAK;;;;UAI9C,4CAA4C;;;;;;;;EAQzD;;EAEA,+BAA+B;;;;;;EAM/B,aAAa,eAAe;;EAE5B,8BAA8B;;EAE9B;;EAEA;;;;;;cAMiB,sCAAsC,oBAAoB;WAClE;WACA;EACT;UACQ;UACA;UACA;UACA;EACR,YAAY,SAAS;EACrB;;;;;;;UAOQ;;;;;;;UAOA;;;;;;;EAOR,wBAAwB,MAAM,IAAI,MAAM,QAAQ;UACxC;;;;;;;;UAQA;;;;;;;UAOA;;;;;UAKA;;;;;;;UAOA;;;;;;;;UAQA;;;;;;;;UAQA;;;;;YAKE,eAAe,UAAU,iBAAiB;;;;;YAK1C,eAAe,UAAU,iBAAiB;;;;EAIpD;;;;EAIA"}
package/dist/xhr.d.mts CHANGED
@@ -41,7 +41,6 @@ declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpR
41
41
  private _tasksCount;
42
42
  private _xhrMem;
43
43
  private _usedResources;
44
- private _isEnabled;
45
44
  private _isXhrPatched;
46
45
  constructor(config?: XMLHttpRequestInstrumentationConfig);
47
46
  init(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.d.mts","names":[],"sources":["../src/xhr.d.ts"],"mappings":";;;;KAIY,8BAA8B,MAAM,IAAI,MAAM,KAAK;;;;UAI9C,4CAA4C;;;;;;;;EAQzD;;EAEA,+BAA+B;;;;;;EAM/B,aAAa,eAAe;;EAE5B,8BAA8B;;EAE9B;;EAEA;;;;;;cAMiB,sCAAsC,oBAAoB;WAClE;WACA;EACT;UACQ;UACA;UACA;UACA;UACA;EACR,YAAY,SAAS;EACrB;;;;;;;UAOQ;;;;;;;UAOA;;;;;;;EAOR,wBAAwB,MAAM,IAAI,MAAM,QAAQ;UACxC;;;;;;;;UAQA;;;;;;;UAOA;;;;;UAKA;;;;;;;UAOA;;;;;;;;UAQA;;;;;;;;UAQA;;;;;YAKE,eAAe,UAAU,iBAAiB;;;;;YAK1C,eAAe,UAAU,iBAAiB;;;;EAIpD;;;;EAIA"}
1
+ {"version":3,"file":"xhr.d.mts","names":[],"sources":["../src/xhr.d.ts"],"mappings":";;;;KAIY,8BAA8B,MAAM,IAAI,MAAM,KAAK;;;;UAI9C,4CAA4C;;;;;;;;EAQzD;;EAEA,+BAA+B;;;;;;EAM/B,aAAa,eAAe;;EAE5B,8BAA8B;;EAE9B;;EAEA;;;;;;cAMiB,sCAAsC,oBAAoB;WAClE;WACA;EACT;UACQ;UACA;UACA;UACA;EACR,YAAY,SAAS;EACrB;;;;;;;UAOQ;;;;;;;UAOA;;;;;;;EAOR,wBAAwB,MAAM,IAAI,MAAM,QAAQ;UACxC;;;;;;;;UAQA;;;;;;;UAOA;;;;;UAKA;;;;;;;UAOA;;;;;;;;UAQA;;;;;;;;UAQA;;;;;YAKE,eAAe,UAAU,iBAAiB;;;;;YAK1C,eAAe,UAAU,iBAAiB;;;;EAIpD;;;;EAIA"}
package/dist/xhr.mjs CHANGED
@@ -196,7 +196,7 @@ var XMLHttpRequestInstrumentation = class extends InstrumentationBase {
196
196
  return (original) => {
197
197
  const plugin = this;
198
198
  return function patchOpen(...args) {
199
- if (!plugin._isEnabled) return original.apply(this, args);
199
+ if (!plugin._enabled) return original.apply(this, args);
200
200
  const method = args[0];
201
201
  const url = args[1];
202
202
  plugin._createSpan(this, url, method);
@@ -274,7 +274,7 @@ var XMLHttpRequestInstrumentation = class extends InstrumentationBase {
274
274
  }
275
275
  return (original) => {
276
276
  return function patchSend(...args) {
277
- if (!plugin._isEnabled) return original.apply(this, args);
277
+ if (!plugin._enabled) return original.apply(this, args);
278
278
  const xhrMem = plugin._xhrMem.get(this);
279
279
  if (!xhrMem) return original.apply(this, args);
280
280
  const currentSpan = xhrMem.span;
@@ -309,18 +309,23 @@ var XMLHttpRequestInstrumentation = class extends InstrumentationBase {
309
309
  * implements enable function
310
310
  */
311
311
  enable() {
312
- if (this._isEnabled) return;
312
+ if (this._enabled) return;
313
313
  if (this._isXhrPatched) {
314
314
  this._diag.debug("reactivating existing patch on", this.moduleName, this.version);
315
- this._isEnabled = true;
315
+ this._enabled = true;
316
316
  return;
317
317
  }
318
318
  try {
319
319
  this._diag.debug("applying patch to", this.moduleName, this.version);
320
- this._wrap(XMLHttpRequest.prototype, "open", this._patchOpen());
321
- this._wrap(XMLHttpRequest.prototype, "send", this._patchSend());
320
+ const proto = XMLHttpRequest.prototype;
321
+ for (const name of ["open", "send"]) if (typeof proto[name] !== "function") {
322
+ this._diag.warn(`XMLHttpRequest.prototype.${name} is missing or not a function; instrumentation will not be enabled. Register the instrumentation after any XMLHttpRequest polyfill, or call enable() once it is available.`);
323
+ return;
324
+ }
325
+ this._wrap(proto, "open", this._patchOpen());
326
+ this._wrap(proto, "send", this._patchSend());
322
327
  this._isXhrPatched = true;
323
- this._isEnabled = true;
328
+ this._enabled = true;
324
329
  } catch (err) {
325
330
  this._unwrap(XMLHttpRequest.prototype, "open");
326
331
  this._unwrap(XMLHttpRequest.prototype, "send");
@@ -331,8 +336,8 @@ var XMLHttpRequestInstrumentation = class extends InstrumentationBase {
331
336
  * implements disable function
332
337
  */
333
338
  disable() {
334
- if (!this._isEnabled) return;
335
- this._isEnabled = false;
339
+ if (!this._enabled) return;
340
+ this._enabled = false;
336
341
  this._tasksCount = 0;
337
342
  this._xhrMem = /* @__PURE__ */ new WeakMap();
338
343
  this._usedResources = /* @__PURE__ */ new WeakSet();
package/dist/xhr.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.mjs","names":["PTN"],"sources":["../src/xhr.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/web-common';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n * @deprecated See https://github.com/open-telemetry/opentelemetry-browser/tree/main/packages/instrumentation#xhr-xmlhttprequest\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n\n // Note: Intentionally *not* using `_enabled` as the field name to avoid\n // any possible confusion with the `_enabled` field used on the *Node.js*\n // InstrumentationBase class.\n // Also not initializing the fields to `false` because the base class\n // constructor already calls `enable` modifying their values and it will\n // set the instrumentations in a bad state (enabled, patched but with flags set to false)\n declare private _isEnabled: boolean;\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n performance.clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = performance.getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const attributes = {} as api.Attributes;\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n const name = normMethod;\n\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._isEnabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._isEnabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._isEnabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._isEnabled) {\n return;\n }\n this._isEnabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"],"mappings":";;;;;;;;;AA+CA,MAAM,wBAAwB;;;;;AAwC9B,IAAa,gCAAb,cAAmD,oBAAyD;CAC1G,YAA6B;CAC7B,UAA2B;CAC3B,aAAa,KAAK;CAElB,cAAsB;CACtB,0BAAkB,IAAI,QAAgC;CACtD,iCAAyB,IAAI,QAAmC;CAWhE,YAAY,SAA8C,CAAC,GAAG;EAC5D,MAAM,mDAAmD,SAAS,MAAM;CAC1E;CAEA,OAAO,CAAC;;;;;;;CAQR,YAAoB,KAAqB,SAAiB;EACxD,MAAM,MAAM,SAAS,OAAO,CAAC,CAAC;EAC9B,IACE,CAAC,4BACC,KACA,KAAK,UAAU,CAAC,CAAC,4BACnB,G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AAK,YACL,KAAK,OACP;GACA,KAAK,aAAa;GAClB;EACF;EAEA,IAAI;GACF,KAAK,MAAM,MAAM,qBAAqB,KAAK,YAAY,KAAK,OAAO;GACnE,KAAK,MAAM,eAAe,WAAW,QAAQ,KAAK,WAAW,CAAC;GAC9D,KAAK,MAAM,eAAe,WAAW,QAAQ,KAAK,WAAW,CAAC;GAC9D,KAAK,gBAAgB;GACrB,KAAK,aAAa;EACpB,SAAS,KAAK;GAEZ,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,QAAQ,eAAe,WAAW,MAAM;GAC7C,KAAK,MAAM,KACT,uKAEA,GACF;EACF;CACF;;;;CAKA,UAAmB;EACjB,IAAI,CAAC,KAAK,YACR;EAEF,KAAK,aAAa;EAClB,KAAK,cAAc;EACnB,KAAK,0BAAU,IAAI,QAAgC;EACnD,KAAK,iCAAiB,IAAI,QAAmC;CAC/D;AACF"}
1
+ {"version":3,"file":"xhr.mjs","names":["PTN"],"sources":["../src/xhr.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/web-common';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n * @deprecated See https://github.com/open-telemetry/opentelemetry-browser/tree/main/packages/instrumentation#xhr-xmlhttprequest\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n\n // Not initialized: the base constructor calls enable() before subclass field\n // initializers run, so an initializer would reset the flag after patching.\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n performance.clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = performance.getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const attributes = {} as api.Attributes;\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n const name = normMethod;\n\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._enabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._enabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._enabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._enabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n const proto = XMLHttpRequest.prototype;\n // `_wrap` returns undefined, without throwing, on a missing or non-function\n // target, so a lone wrapped `open` would escape the catch and re-wrap on retry.\n for (const name of ['open', 'send'] as const) {\n if (typeof proto[name] !== 'function') {\n this._diag.warn(\n `XMLHttpRequest.prototype.${name} is missing or not a function; instrumentation will not be enabled. ` +\n 'Register the instrumentation after any XMLHttpRequest polyfill, or call enable() once it is available.'\n );\n return;\n }\n }\n this._wrap(proto, 'open', this._patchOpen());\n this._wrap(proto, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._enabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._enabled) {\n return;\n }\n this._enabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"],"mappings":";;;;;;;;;AA+CA,MAAM,wBAAwB;;;;;AAwC9B,IAAa,gCAAb,cAAmD,oBAAyD;CAC1G,YAA6B;CAC7B,UAA2B;CAC3B,aAAa,KAAK;CAElB,cAAsB;CACtB,0BAAkB,IAAI,QAAgC;CACtD,iCAAyB,IAAI,QAAmC;CAMhE,YAAY,SAA8C,CAAC,GAAG;EAC5D,MAAM,mDAAmD,SAAS,MAAM;CAC1E;CAEA,OAAO,CAAC;;;;;;;CAQR,YAAoB,KAAqB,SAAiB;EACxD,MAAM,MAAM,SAAS,OAAO,CAAC,CAAC;EAC9B,IACE,CAAC,4BACC,KACA,KAAK,UAAU,CAAC,CAAC,4BACnB,GACA;GACA,MAAM,UAA4C,CAAC;GACnD,IAAI,YAAY,OAAO,IAAI,QAAQ,OAAO,GAAG,OAAO;GACpD,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAChC,KAAK,MAAM,MAAM,2CAA2C;GAE9D;EACF;EACA,MAAM,UAAsC,CAAC;EAC7C,IAAI,YAAY,OAAO,IAAI,QAAQ,OAAO,GAAG,OAAO;EACpD,OAAO,KAAK,OAAO,CAAC,CAAC,SAAQ,QAAO;GAClC,IAAI,iBAAiB,KAAK,OAAO,QAAQ,IAAI,CAAC;EAChD,CAAC;CACH;;;;;;;CAQA,cACE,MACA,sBACM;EACN,IAAI,QAAQ,KAAK,IAAI,MAAM,QAAQ,IAAI,QAAQ,OAAO,GAAG,IAAI,SAAS;GACpE,MAAM,YAAY,KAAK,OAAO,UAAU,kBAAkB,EACxD,WAAW,qBAAqBA,uBAAI,aACtC,CAAC;GACD,qBACE,WACA,sBACA,KAAK,UAA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ACR;EAEF,KAAK,WAAW;EAChB,KAAK,cAAc;EACnB,KAAK,0BAAU,IAAI,QAAgC;EACnD,KAAK,iCAAiB,IAAI,QAAmC;CAC/D;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-xml-http-request",
3
- "version": "0.300.0-development.1",
3
+ "version": "0.300.0",
4
4
  "description": "OpenTelemetry instrumentation for XMLHttpRequest http client in web browsers",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",
@@ -57,10 +57,10 @@
57
57
  "devDependencies": {
58
58
  "@babel/core": "7.29.7",
59
59
  "@babel/preset-env": "7.29.7",
60
- "@opentelemetry/api": "1.10.0-development.1",
61
- "@opentelemetry/context-zone": "3.0.0-development.1",
62
- "@opentelemetry/propagator-b3": "3.0.0-development.1",
63
- "@opentelemetry/sdk-trace": "3.0.0-development.1",
60
+ "@opentelemetry/api": "1.10.0",
61
+ "@opentelemetry/context-zone": "3.0.0",
62
+ "@opentelemetry/propagator-b3": "3.0.0",
63
+ "@opentelemetry/sdk-trace": "3.0.0",
64
64
  "@types/mocha": "10.0.10",
65
65
  "@types/node": "18.19.130",
66
66
  "@types/sinon": "17.0.4",
@@ -73,7 +73,7 @@
73
73
  "karma-mocha": "2.0.1",
74
74
  "karma-spec-reporter": "0.0.37",
75
75
  "karma-webpack": "5.0.1",
76
- "mocha": "11.8.0",
76
+ "mocha": "12.0.3",
77
77
  "nyc": "18.0.0",
78
78
  "sinon": "18.0.1",
79
79
  "ts-loader": "9.5.7",
@@ -82,15 +82,15 @@
82
82
  "webpack-cli": "7.2.3"
83
83
  },
84
84
  "peerDependencies": {
85
- "@opentelemetry/api": "^1.3.0 || 1.10.0-development.1"
85
+ "@opentelemetry/api": "^1.3.0"
86
86
  },
87
87
  "dependencies": {
88
- "@opentelemetry/core": "3.0.0-development.1",
89
- "@opentelemetry/instrumentation": "0.300.0-development.1",
88
+ "@opentelemetry/core": "3.0.0",
89
+ "@opentelemetry/instrumentation": "0.300.0",
90
90
  "@opentelemetry/semantic-conventions": "^1.29.0",
91
- "@opentelemetry/web-common": "0.300.0-development.1"
91
+ "@opentelemetry/web-common": "0.300.0"
92
92
  },
93
93
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-xml-http-request",
94
94
  "sideEffects": false,
95
- "gitHead": "83d76963961161511591d5585407d23b5f035a37"
95
+ "gitHead": "12a5817ad147c186a0e45a6637abd5abf423727a"
96
96
  }