@opentelemetry/instrumentation-xml-http-request 0.51.0 → 0.52.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.
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.51.0";
1
+ export declare const VERSION = "0.52.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export var VERSION = '0.51.0';
17
+ export var VERSION = '0.52.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.51.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.52.0';\n"]}
@@ -30,7 +30,7 @@ export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConf
30
30
  /**
31
31
  * This class represents a XMLHttpRequest plugin for auto instrumentation
32
32
  */
33
- export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
33
+ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {
34
34
  readonly component: string;
35
35
  readonly version: string;
36
36
  moduleName: string;
@@ -39,7 +39,6 @@ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
39
39
  private _usedResources;
40
40
  constructor(config?: XMLHttpRequestInstrumentationConfig);
41
41
  init(): void;
42
- private _getConfig;
43
42
  /**
44
43
  * Adds custom headers to XMLHttpRequest
45
44
  * @param xhr
package/build/esm/xhr.js CHANGED
@@ -31,7 +31,7 @@ var __extends = (this && this.__extends) || (function () {
31
31
  import * as api from '@opentelemetry/api';
32
32
  import { isWrapped, InstrumentationBase, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation';
33
33
  import { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';
34
- import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
34
+ import { SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, } from '@opentelemetry/semantic-conventions';
35
35
  import { addSpanNetworkEvents, getResource, PerformanceTimingNames as PTN, shouldPropagateTraceHeaders, parseUrl, } from '@opentelemetry/sdk-trace-web';
36
36
  import { EventNames } from './enums/EventNames';
37
37
  import { VERSION } from './version';
@@ -47,6 +47,7 @@ var OBSERVER_WAIT_TIME_MS = 300;
47
47
  var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
48
48
  __extends(XMLHttpRequestInstrumentation, _super);
49
49
  function XMLHttpRequestInstrumentation(config) {
50
+ if (config === void 0) { config = {}; }
50
51
  var _this = _super.call(this, '@opentelemetry/instrumentation-xml-http-request', VERSION, config) || this;
51
52
  _this.component = 'xml-http-request';
52
53
  _this.version = VERSION;
@@ -57,9 +58,6 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
57
58
  return _this;
58
59
  }
59
60
  XMLHttpRequestInstrumentation.prototype.init = function () { };
60
- XMLHttpRequestInstrumentation.prototype._getConfig = function () {
61
- return this._config;
62
- };
63
61
  /**
64
62
  * Adds custom headers to XMLHttpRequest
65
63
  * @param xhr
@@ -68,7 +66,7 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
68
66
  */
69
67
  XMLHttpRequestInstrumentation.prototype._addHeaders = function (xhr, spanUrl) {
70
68
  var url = parseUrl(spanUrl).href;
71
- if (!shouldPropagateTraceHeaders(url, this._getConfig().propagateTraceHeaderCorsUrls)) {
69
+ if (!shouldPropagateTraceHeaders(url, this.getConfig().propagateTraceHeaderCorsUrls)) {
72
70
  var headers_1 = {};
73
71
  api.propagation.inject(api.context.active(), headers_1);
74
72
  if (Object.keys(headers_1).length > 0) {
@@ -94,7 +92,7 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
94
92
  var childSpan = _this.tracer.startSpan('CORS Preflight', {
95
93
  startTime: corsPreFlightRequest[PTN.FETCH_START],
96
94
  });
97
- if (!_this._getConfig().ignoreNetworkEvents) {
95
+ if (!_this.getConfig().ignoreNetworkEvents) {
98
96
  addSpanNetworkEvents(childSpan, corsPreFlightRequest);
99
97
  }
100
98
  childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);
@@ -111,21 +109,21 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
111
109
  if (typeof spanUrl === 'string') {
112
110
  var parsedUrl = parseUrl(spanUrl);
113
111
  if (xhrMem.status !== undefined) {
114
- span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);
112
+ span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);
115
113
  }
116
114
  if (xhrMem.statusText !== undefined) {
117
115
  span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);
118
116
  }
119
- span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);
120
- span.setAttribute(SemanticAttributes.HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
117
+ span.setAttribute(SEMATTRS_HTTP_HOST, parsedUrl.host);
118
+ span.setAttribute(SEMATTRS_HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
121
119
  // @TODO do we want to collect this or it will be collected earlier once only or
122
120
  // maybe when parent span is not available ?
123
- span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent);
121
+ span.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);
124
122
  }
125
123
  };
126
124
  XMLHttpRequestInstrumentation.prototype._applyAttributesAfterXHR = function (span, xhr) {
127
125
  var _this = this;
128
- var applyCustomAttributesOnSpan = this._getConfig().applyCustomAttributesOnSpan;
126
+ var applyCustomAttributesOnSpan = this.getConfig().applyCustomAttributesOnSpan;
129
127
  if (typeof applyCustomAttributesOnSpan === 'function') {
130
128
  safeExecuteInTheMiddle(function () { return applyCustomAttributesOnSpan(span, xhr); }, function (error) {
131
129
  if (!error) {
@@ -175,7 +173,7 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
175
173
  * @private
176
174
  */
177
175
  XMLHttpRequestInstrumentation.prototype._clearResources = function () {
178
- if (this._tasksCount === 0 && this._getConfig().clearTimingResources) {
176
+ if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {
179
177
  otperformance.clearResourceTimings();
180
178
  this._xhrMem = new WeakMap();
181
179
  this._usedResources = new WeakSet();
@@ -206,7 +204,7 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
206
204
  this._addChildSpan(span, corsPreFlightRequest);
207
205
  this._markResourceAsUsed(corsPreFlightRequest);
208
206
  }
209
- if (!this._getConfig().ignoreNetworkEvents) {
207
+ if (!this.getConfig().ignoreNetworkEvents) {
210
208
  addSpanNetworkEvents(span, mainRequest);
211
209
  }
212
210
  }
@@ -236,7 +234,7 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
236
234
  */
237
235
  XMLHttpRequestInstrumentation.prototype._createSpan = function (xhr, url, method) {
238
236
  var _a;
239
- if (isUrlIgnored(url, this._getConfig().ignoreUrls)) {
237
+ if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {
240
238
  this._diag.debug('ignoring span as url matches ignored url');
241
239
  return;
242
240
  }
@@ -244,8 +242,8 @@ var XMLHttpRequestInstrumentation = /** @class */ (function (_super) {
244
242
  var currentSpan = this.tracer.startSpan(spanName, {
245
243
  kind: api.SpanKind.CLIENT,
246
244
  attributes: (_a = {},
247
- _a[SemanticAttributes.HTTP_METHOD] = method,
248
- _a[SemanticAttributes.HTTP_URL] = parseUrl(url).toString(),
245
+ _a[SEMATTRS_HTTP_METHOD] = method,
246
+ _a[SEMATTRS_HTTP_URL] = parseUrl(url).toString(),
249
247
  _a),
250
248
  });
251
249
  currentSpan.addEvent(EventNames.METHOD_OPEN);
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,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AC;IAClE,CAAC;IAED;;OAEG;IACM,+CAAO,GAAhB;QACE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;IACH,oCAAC;AAAD,CAAC,AAldD,CAAmD,mBAAmB,GAkdrE","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase {\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 constructor(config?: XMLHttpRequestInstrumentationConfig) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n private _getConfig(): XMLHttpRequestInstrumentationConfig {\n return this._config;\n }\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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SemanticAttributes.HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(\n SemanticAttributes.HTTP_USER_AGENT,\n navigator.userAgent\n );\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this._getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
1
+ {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,sBAAsB,IAAI,GAAG,EAC7B,2BAA2B,EAC3B,QAAQ,GACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,uEAAuE;AACvE,2DAA2D;AAC3D,kEAAkE;AAClE,cAAc;AACd,IAAM,qBAAqB,GAAG,GAAG,CAAC;AAkClC;;GAEG;AACH;IAAmD,iDAAwD;IASzG,uCAAY,MAAgD;QAAhD,uBAAA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,CAAmD,mBAAmB,GA2crE","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport {\n SEMATTRS_HTTP_HOST,\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_SCHEME,\n SEMATTRS_HTTP_STATUS_CODE,\n SEMATTRS_HTTP_URL,\n SEMATTRS_HTTP_USER_AGENT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\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 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SEMATTRS_HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SEMATTRS_HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SEMATTRS_HTTP_METHOD]: method,\n [SEMATTRS_HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.51.0";
1
+ export declare const VERSION = "0.52.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export const VERSION = '0.51.0';
17
+ export const VERSION = '0.52.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.51.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.52.0';\n"]}
@@ -30,7 +30,7 @@ export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConf
30
30
  /**
31
31
  * This class represents a XMLHttpRequest plugin for auto instrumentation
32
32
  */
33
- export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
33
+ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {
34
34
  readonly component: string;
35
35
  readonly version: string;
36
36
  moduleName: string;
@@ -39,7 +39,6 @@ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
39
39
  private _usedResources;
40
40
  constructor(config?: XMLHttpRequestInstrumentationConfig);
41
41
  init(): void;
42
- private _getConfig;
43
42
  /**
44
43
  * Adds custom headers to XMLHttpRequest
45
44
  * @param xhr
@@ -16,7 +16,7 @@
16
16
  import * as api from '@opentelemetry/api';
17
17
  import { isWrapped, InstrumentationBase, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation';
18
18
  import { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';
19
- import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
19
+ import { SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, } from '@opentelemetry/semantic-conventions';
20
20
  import { addSpanNetworkEvents, getResource, PerformanceTimingNames as PTN, shouldPropagateTraceHeaders, parseUrl, } from '@opentelemetry/sdk-trace-web';
21
21
  import { EventNames } from './enums/EventNames';
22
22
  import { VERSION } from './version';
@@ -30,7 +30,7 @@ const OBSERVER_WAIT_TIME_MS = 300;
30
30
  * This class represents a XMLHttpRequest plugin for auto instrumentation
31
31
  */
32
32
  export class XMLHttpRequestInstrumentation extends InstrumentationBase {
33
- constructor(config) {
33
+ constructor(config = {}) {
34
34
  super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);
35
35
  this.component = 'xml-http-request';
36
36
  this.version = VERSION;
@@ -40,9 +40,6 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
40
40
  this._usedResources = new WeakSet();
41
41
  }
42
42
  init() { }
43
- _getConfig() {
44
- return this._config;
45
- }
46
43
  /**
47
44
  * Adds custom headers to XMLHttpRequest
48
45
  * @param xhr
@@ -51,7 +48,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
51
48
  */
52
49
  _addHeaders(xhr, spanUrl) {
53
50
  const url = parseUrl(spanUrl).href;
54
- if (!shouldPropagateTraceHeaders(url, this._getConfig().propagateTraceHeaderCorsUrls)) {
51
+ if (!shouldPropagateTraceHeaders(url, this.getConfig().propagateTraceHeaderCorsUrls)) {
55
52
  const headers = {};
56
53
  api.propagation.inject(api.context.active(), headers);
57
54
  if (Object.keys(headers).length > 0) {
@@ -76,7 +73,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
76
73
  const childSpan = this.tracer.startSpan('CORS Preflight', {
77
74
  startTime: corsPreFlightRequest[PTN.FETCH_START],
78
75
  });
79
- if (!this._getConfig().ignoreNetworkEvents) {
76
+ if (!this.getConfig().ignoreNetworkEvents) {
80
77
  addSpanNetworkEvents(childSpan, corsPreFlightRequest);
81
78
  }
82
79
  childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);
@@ -93,20 +90,20 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
93
90
  if (typeof spanUrl === 'string') {
94
91
  const parsedUrl = parseUrl(spanUrl);
95
92
  if (xhrMem.status !== undefined) {
96
- span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);
93
+ span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);
97
94
  }
98
95
  if (xhrMem.statusText !== undefined) {
99
96
  span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);
100
97
  }
101
- span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);
102
- span.setAttribute(SemanticAttributes.HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
98
+ span.setAttribute(SEMATTRS_HTTP_HOST, parsedUrl.host);
99
+ span.setAttribute(SEMATTRS_HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
103
100
  // @TODO do we want to collect this or it will be collected earlier once only or
104
101
  // maybe when parent span is not available ?
105
- span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent);
102
+ span.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);
106
103
  }
107
104
  }
108
105
  _applyAttributesAfterXHR(span, xhr) {
109
- const applyCustomAttributesOnSpan = this._getConfig().applyCustomAttributesOnSpan;
106
+ const applyCustomAttributesOnSpan = this.getConfig().applyCustomAttributesOnSpan;
110
107
  if (typeof applyCustomAttributesOnSpan === 'function') {
111
108
  safeExecuteInTheMiddle(() => applyCustomAttributesOnSpan(span, xhr), error => {
112
109
  if (!error) {
@@ -156,7 +153,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
156
153
  * @private
157
154
  */
158
155
  _clearResources() {
159
- if (this._tasksCount === 0 && this._getConfig().clearTimingResources) {
156
+ if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {
160
157
  otperformance.clearResourceTimings();
161
158
  this._xhrMem = new WeakMap();
162
159
  this._usedResources = new WeakSet();
@@ -187,7 +184,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
187
184
  this._addChildSpan(span, corsPreFlightRequest);
188
185
  this._markResourceAsUsed(corsPreFlightRequest);
189
186
  }
190
- if (!this._getConfig().ignoreNetworkEvents) {
187
+ if (!this.getConfig().ignoreNetworkEvents) {
191
188
  addSpanNetworkEvents(span, mainRequest);
192
189
  }
193
190
  }
@@ -216,7 +213,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
216
213
  * @private
217
214
  */
218
215
  _createSpan(xhr, url, method) {
219
- if (isUrlIgnored(url, this._getConfig().ignoreUrls)) {
216
+ if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {
220
217
  this._diag.debug('ignoring span as url matches ignored url');
221
218
  return;
222
219
  }
@@ -224,8 +221,8 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
224
221
  const currentSpan = this.tracer.startSpan(spanName, {
225
222
  kind: api.SpanKind.CLIENT,
226
223
  attributes: {
227
- [SemanticAttributes.HTTP_METHOD]: method,
228
- [SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),
224
+ [SEMATTRS_HTTP_METHOD]: method,
225
+ [SEMATTRS_HTTP_URL]: parseUrl(url).toString(),
229
226
  },
230
227
  });
231
228
  currentSpan.addEvent(EventNames.METHOD_OPEN);
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,sBAAsB,IAAI,GAAG,EAC7B,2BAA2B,EAC3B,QAAQ,GACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,uEAAuE;AACvE,2DAA2D;AAC3D,kEAAkE;AAClE,cAAc;AACd,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAkClC;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,mBAAmB;IASpE,YAAY,MAA4C;QACtD,KAAK,CAAC,iDAAiD,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QATnE,c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AAC,IAAI,CAAC,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACM,OAAO;QACd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase {\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 constructor(config?: XMLHttpRequestInstrumentationConfig) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n private _getConfig(): XMLHttpRequestInstrumentationConfig {\n return this._config;\n }\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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SemanticAttributes.HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(\n SemanticAttributes.HTTP_USER_AGENT,\n navigator.userAgent\n );\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this._getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
1
+ {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,E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MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport {\n SEMATTRS_HTTP_HOST,\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_SCHEME,\n SEMATTRS_HTTP_STATUS_CODE,\n SEMATTRS_HTTP_URL,\n SEMATTRS_HTTP_USER_AGENT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\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 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SEMATTRS_HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SEMATTRS_HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SEMATTRS_HTTP_METHOD]: method,\n [SEMATTRS_HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.51.0";
1
+ export declare const VERSION = "0.52.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.51.0';
20
+ exports.VERSION = '0.52.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.51.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.52.0';\n"]}
@@ -30,7 +30,7 @@ export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConf
30
30
  /**
31
31
  * This class represents a XMLHttpRequest plugin for auto instrumentation
32
32
  */
33
- export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
33
+ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {
34
34
  readonly component: string;
35
35
  readonly version: string;
36
36
  moduleName: string;
@@ -39,7 +39,6 @@ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase {
39
39
  private _usedResources;
40
40
  constructor(config?: XMLHttpRequestInstrumentationConfig);
41
41
  init(): void;
42
- private _getConfig;
43
42
  /**
44
43
  * Adds custom headers to XMLHttpRequest
45
44
  * @param xhr
package/build/src/xhr.js CHANGED
@@ -33,7 +33,7 @@ const OBSERVER_WAIT_TIME_MS = 300;
33
33
  * This class represents a XMLHttpRequest plugin for auto instrumentation
34
34
  */
35
35
  class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBase {
36
- constructor(config) {
36
+ constructor(config = {}) {
37
37
  super('@opentelemetry/instrumentation-xml-http-request', version_1.VERSION, config);
38
38
  this.component = 'xml-http-request';
39
39
  this.version = version_1.VERSION;
@@ -43,9 +43,6 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
43
43
  this._usedResources = new WeakSet();
44
44
  }
45
45
  init() { }
46
- _getConfig() {
47
- return this._config;
48
- }
49
46
  /**
50
47
  * Adds custom headers to XMLHttpRequest
51
48
  * @param xhr
@@ -54,7 +51,7 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
54
51
  */
55
52
  _addHeaders(xhr, spanUrl) {
56
53
  const url = (0, sdk_trace_web_1.parseUrl)(spanUrl).href;
57
- if (!(0, sdk_trace_web_1.shouldPropagateTraceHeaders)(url, this._getConfig().propagateTraceHeaderCorsUrls)) {
54
+ if (!(0, sdk_trace_web_1.shouldPropagateTraceHeaders)(url, this.getConfig().propagateTraceHeaderCorsUrls)) {
58
55
  const headers = {};
59
56
  api.propagation.inject(api.context.active(), headers);
60
57
  if (Object.keys(headers).length > 0) {
@@ -79,7 +76,7 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
79
76
  const childSpan = this.tracer.startSpan('CORS Preflight', {
80
77
  startTime: corsPreFlightRequest[sdk_trace_web_1.PerformanceTimingNames.FETCH_START],
81
78
  });
82
- if (!this._getConfig().ignoreNetworkEvents) {
79
+ if (!this.getConfig().ignoreNetworkEvents) {
83
80
  (0, sdk_trace_web_1.addSpanNetworkEvents)(childSpan, corsPreFlightRequest);
84
81
  }
85
82
  childSpan.end(corsPreFlightRequest[sdk_trace_web_1.PerformanceTimingNames.RESPONSE_END]);
@@ -96,20 +93,20 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
96
93
  if (typeof spanUrl === 'string') {
97
94
  const parsedUrl = (0, sdk_trace_web_1.parseUrl)(spanUrl);
98
95
  if (xhrMem.status !== undefined) {
99
- span.setAttribute(semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);
96
+ span.setAttribute(semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);
100
97
  }
101
98
  if (xhrMem.statusText !== undefined) {
102
99
  span.setAttribute(AttributeNames_1.AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);
103
100
  }
104
- span.setAttribute(semantic_conventions_1.SemanticAttributes.HTTP_HOST, parsedUrl.host);
105
- span.setAttribute(semantic_conventions_1.SemanticAttributes.HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
101
+ span.setAttribute(semantic_conventions_1.SEMATTRS_HTTP_HOST, parsedUrl.host);
102
+ span.setAttribute(semantic_conventions_1.SEMATTRS_HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
106
103
  // @TODO do we want to collect this or it will be collected earlier once only or
107
104
  // maybe when parent span is not available ?
108
- span.setAttribute(semantic_conventions_1.SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent);
105
+ span.setAttribute(semantic_conventions_1.SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);
109
106
  }
110
107
  }
111
108
  _applyAttributesAfterXHR(span, xhr) {
112
- const applyCustomAttributesOnSpan = this._getConfig().applyCustomAttributesOnSpan;
109
+ const applyCustomAttributesOnSpan = this.getConfig().applyCustomAttributesOnSpan;
113
110
  if (typeof applyCustomAttributesOnSpan === 'function') {
114
111
  (0, instrumentation_1.safeExecuteInTheMiddle)(() => applyCustomAttributesOnSpan(span, xhr), error => {
115
112
  if (!error) {
@@ -159,7 +156,7 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
159
156
  * @private
160
157
  */
161
158
  _clearResources() {
162
- if (this._tasksCount === 0 && this._getConfig().clearTimingResources) {
159
+ if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {
163
160
  core_1.otperformance.clearResourceTimings();
164
161
  this._xhrMem = new WeakMap();
165
162
  this._usedResources = new WeakSet();
@@ -190,7 +187,7 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
190
187
  this._addChildSpan(span, corsPreFlightRequest);
191
188
  this._markResourceAsUsed(corsPreFlightRequest);
192
189
  }
193
- if (!this._getConfig().ignoreNetworkEvents) {
190
+ if (!this.getConfig().ignoreNetworkEvents) {
194
191
  (0, sdk_trace_web_1.addSpanNetworkEvents)(span, mainRequest);
195
192
  }
196
193
  }
@@ -219,7 +216,7 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
219
216
  * @private
220
217
  */
221
218
  _createSpan(xhr, url, method) {
222
- if ((0, core_1.isUrlIgnored)(url, this._getConfig().ignoreUrls)) {
219
+ if ((0, core_1.isUrlIgnored)(url, this.getConfig().ignoreUrls)) {
223
220
  this._diag.debug('ignoring span as url matches ignored url');
224
221
  return;
225
222
  }
@@ -227,8 +224,8 @@ class XMLHttpRequestInstrumentation extends instrumentation_1.InstrumentationBas
227
224
  const currentSpan = this.tracer.startSpan(spanName, {
228
225
  kind: api.SpanKind.CLIENT,
229
226
  attributes: {
230
- [semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: method,
231
- [semantic_conventions_1.SemanticAttributes.HTTP_URL]: (0, sdk_trace_web_1.parseUrl)(url).toString(),
227
+ [semantic_conventions_1.SEMATTRS_HTTP_METHOD]: method,
228
+ [semantic_conventions_1.SEMATTRS_HTTP_URL]: (0, sdk_trace_web_1.parseUrl)(url).toString(),
232
229
  },
233
230
  });
234
231
  currentSpan.addEvent(EventNames_1.EventNames.METHOD_OPEN);
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,oEAKwC;AACxC,8CAA0E;AAC1E,8EAAyE;AACzE,gEAMsC;AACtC,mDAAgD;AAOhD,uCAAoC;AACpC,2DAAwD;AAExD,uEAAuE;AACvE,2DAA2D;AAC3D,kEAAkE;AAClE,cAAc;AACd,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAkClC;;GAEG;AACH,MAAa,6BAA8B,SAAQ,qCAAmB;IASpE,YAAY,MAA4C;QACtD,KAAK,CAAC,iDAAiD,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;QATnE,cAAS,GAAW,kBAAkB,CAAC;QACvC,YAAO,GAAW,iBAAO,CAAC;QACnC,eAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QAEpB,gBAAW,GAAG,CAAC,CAAC;QAChB,YAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;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,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,IAAA,2BAAS,EAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACM,OAAO;QACd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF;AAldD,sEAkdC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase {\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 constructor(config?: XMLHttpRequestInstrumentationConfig) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n private _getConfig(): XMLHttpRequestInstrumentationConfig {\n return this._config;\n }\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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SemanticAttributes.HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(\n SemanticAttributes.HTTP_USER_AGENT,\n navigator.userAgent\n );\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this._getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this._getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SemanticAttributes.HTTP_METHOD]: method,\n [SemanticAttributes.HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
1
+ {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,0CAA0C;AAC1C,oEAKwC;AACxC,8CAA0E;AAC1E,8EAO6C;AAC7C,gEAMsC;AACtC,mDAAgD;AAOhD,uCAAoC;AACpC,2DAAwD;AAExD,uEAAuE;AACvE,2DAA2D;AAC3D,kEAAkE;AAClE,cAAc;AACd,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAkClC;;GAEG;AACH,MAAa,6BAA8B,SAAQ,qCAAwD;IASzG,YAAY,SAA8C,EAAE;QAC1D,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AAI,IAAA,2BAAS,EAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,IAAA,2BAAS,EAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACM,OAAO;QACd,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF;AA3cD,sEA2cC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as api from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationConfig,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport {\n SEMATTRS_HTTP_HOST,\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_SCHEME,\n SEMATTRS_HTTP_STATUS_CODE,\n SEMATTRS_HTTP_URL,\n SEMATTRS_HTTP_USER_AGENT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport { EventNames } from './enums/EventNames';\nimport {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\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}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\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 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(childSpan, corsPreFlightRequest);\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 * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n if (xhrMem.status !== undefined) {\n span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n span.setAttribute(SEMATTRS_HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n SEMATTRS_HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(SEMATTRS_HTTP_USER_AGENT, navigator.userAgent);\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 (otperformance as unknown as 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\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 = (otperformance as unknown as 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 if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvents(span, mainRequest);\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 if (isUrlIgnored(url, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const spanName = method.toUpperCase();\n\n const currentSpan = this.tracer.startSpan(spanName, {\n kind: api.SpanKind.CLIENT,\n attributes: {\n [SEMATTRS_HTTP_METHOD]: method,\n [SEMATTRS_HTTP_URL]: parseUrl(url).toString(),\n },\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 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, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(eventName: string, xhr: XMLHttpRequest) {\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 plugin._applyAttributesAfterXHR(xhrMem.span, xhr);\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);\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this);\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this);\n } else {\n endSpan(EventNames.EVENT_ERROR, this);\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 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 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 this._diag.debug('applying patch to', this.moduleName, this.version);\n\n if (isWrapped(XMLHttpRequest.prototype.open)) {\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._diag.debug('removing previous patch from method open');\n }\n\n if (isWrapped(XMLHttpRequest.prototype.send)) {\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.debug('removing previous patch from method send');\n }\n\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n }\n\n /**\n * implements disable function\n */\n override disable() {\n this._diag.debug('removing patch from', this.moduleName, this.version);\n\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-xml-http-request",
3
- "version": "0.51.0",
4
- "description": "OpenTelemetry XMLHttpRequest automatic instrumentation package.",
3
+ "version": "0.52.0",
4
+ "description": "OpenTelemetry instrumentation for XMLHttpRequest http client in web browsers",
5
5
  "main": "build/src/index.js",
6
6
  "module": "build/esm/index.js",
7
7
  "esnext": "build/esnext/index.js",
@@ -20,7 +20,8 @@
20
20
  "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
21
21
  "precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies",
22
22
  "prewatch": "node ../../../scripts/version-update.js",
23
- "peer-api-check": "node ../../../scripts/peer-api-check.js"
23
+ "peer-api-check": "node ../../../scripts/peer-api-check.js",
24
+ "align-api-deps": "node ../../../scripts/align-api-deps.js"
24
25
  },
25
26
  "keywords": [
26
27
  "opentelemetry",
@@ -54,31 +55,31 @@
54
55
  "access": "public"
55
56
  },
56
57
  "devDependencies": {
57
- "@babel/core": "7.23.6",
58
- "@babel/preset-env": "7.22.20",
59
- "@opentelemetry/api": "1.8.0",
60
- "@opentelemetry/context-zone": "1.24.0",
61
- "@opentelemetry/propagator-b3": "1.24.0",
62
- "@opentelemetry/sdk-trace-base": "1.24.0",
58
+ "@babel/core": "7.24.6",
59
+ "@babel/preset-env": "7.24.6",
60
+ "@opentelemetry/api": "1.9.0",
61
+ "@opentelemetry/context-zone": "1.25.0",
62
+ "@opentelemetry/propagator-b3": "1.25.0",
63
+ "@opentelemetry/sdk-trace-base": "1.25.0",
63
64
  "@types/mocha": "10.0.6",
64
65
  "@types/node": "18.6.5",
65
- "@types/sinon": "10.0.20",
66
+ "@types/sinon": "17.0.3",
66
67
  "@types/webpack-env": "1.16.3",
67
68
  "babel-loader": "8.3.0",
68
69
  "babel-plugin-istanbul": "6.1.1",
69
70
  "codecov": "3.8.3",
70
71
  "cross-var": "1.1.0",
71
- "karma": "6.4.2",
72
+ "karma": "6.4.3",
72
73
  "karma-chrome-launcher": "3.1.0",
73
74
  "karma-coverage": "2.2.1",
74
75
  "karma-mocha": "2.0.1",
75
76
  "karma-spec-reporter": "0.0.36",
76
- "karma-webpack": "4.0.2",
77
+ "karma-webpack": "5.0.1",
77
78
  "lerna": "6.6.2",
78
79
  "mocha": "10.2.0",
79
80
  "nyc": "15.1.0",
80
81
  "sinon": "15.1.2",
81
- "ts-loader": "8.4.0",
82
+ "ts-loader": "9.5.1",
82
83
  "ts-mocha": "10.0.0",
83
84
  "typescript": "4.4.4",
84
85
  "webpack": "5.89.0",
@@ -89,12 +90,12 @@
89
90
  "@opentelemetry/api": "^1.0.0"
90
91
  },
91
92
  "dependencies": {
92
- "@opentelemetry/core": "1.24.0",
93
- "@opentelemetry/instrumentation": "0.51.0",
94
- "@opentelemetry/sdk-trace-web": "1.24.0",
95
- "@opentelemetry/semantic-conventions": "1.24.0"
93
+ "@opentelemetry/core": "1.25.0",
94
+ "@opentelemetry/instrumentation": "0.52.0",
95
+ "@opentelemetry/sdk-trace-web": "1.25.0",
96
+ "@opentelemetry/semantic-conventions": "1.25.0"
96
97
  },
97
98
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-xml-http-request",
98
99
  "sideEffects": false,
99
- "gitHead": "3ab4f765d8d696327b7d139ae6a45e7bd7edd924"
100
+ "gitHead": "c4d3351b6b3f5593c8d7cbfec97b45cea9fe1511"
100
101
  }