@opentelemetry/instrumentation-xml-http-request 0.222.0-development.0 → 0.300.0-development.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -10
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/semconv.cjs +13 -0
- package/dist/semconv.cjs.map +1 -0
- package/dist/semconv.mjs +13 -0
- package/dist/semconv.mjs.map +1 -0
- package/dist/types.d.cts +31 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +31 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/utils.cjs +86 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.mjs +82 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/version.cjs +6 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.mjs +6 -0
- package/dist/version.mjs.map +1 -0
- package/dist/xhr.cjs +345 -0
- package/dist/xhr.cjs.map +1 -0
- package/dist/xhr.d.cts +133 -0
- package/dist/xhr.d.cts.map +1 -0
- package/dist/xhr.d.mts +133 -0
- package/dist/xhr.d.mts.map +1 -0
- package/dist/xhr.mjs +343 -0
- package/dist/xhr.mjs.map +1 -0
- package/package.json +34 -31
- package/build/esm/enums/EventNames.d.ts +0 -9
- package/build/esm/enums/EventNames.js +0 -14
- package/build/esm/enums/EventNames.js.map +0 -1
- package/build/esm/index.d.ts +0 -3
- package/build/esm/index.js +0 -6
- package/build/esm/index.js.map +0 -1
- package/build/esm/semconv.d.ts +0 -9
- package/build/esm/semconv.js +0 -18
- package/build/esm/semconv.js.map +0 -1
- package/build/esm/types.d.ts +0 -29
- package/build/esm/types.js +0 -6
- package/build/esm/types.js.map +0 -1
- package/build/esm/utils.d.ts +0 -14
- package/build/esm/utils.js +0 -118
- package/build/esm/utils.js.map +0 -1
- package/build/esm/version.d.ts +0 -2
- package/build/esm/version.js +0 -7
- package/build/esm/version.js.map +0 -1
- package/build/esm/xhr.d.ts +0 -131
- package/build/esm/xhr.js +0 -415
- package/build/esm/xhr.js.map +0 -1
- package/build/esnext/enums/EventNames.d.ts +0 -9
- package/build/esnext/enums/EventNames.js +0 -14
- package/build/esnext/enums/EventNames.js.map +0 -1
- package/build/esnext/index.d.ts +0 -3
- package/build/esnext/index.js +0 -6
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/semconv.d.ts +0 -9
- package/build/esnext/semconv.js +0 -18
- package/build/esnext/semconv.js.map +0 -1
- package/build/esnext/types.d.ts +0 -29
- package/build/esnext/types.js +0 -6
- package/build/esnext/types.js.map +0 -1
- package/build/esnext/utils.d.ts +0 -14
- package/build/esnext/utils.js +0 -118
- package/build/esnext/utils.js.map +0 -1
- package/build/esnext/version.d.ts +0 -2
- package/build/esnext/version.js +0 -7
- package/build/esnext/version.js.map +0 -1
- package/build/esnext/xhr.d.ts +0 -131
- package/build/esnext/xhr.js +0 -415
- package/build/esnext/xhr.js.map +0 -1
- package/build/src/enums/EventNames.d.ts +0 -9
- package/build/src/enums/EventNames.js +0 -17
- package/build/src/enums/EventNames.js.map +0 -1
- package/build/src/index.d.ts +0 -3
- package/build/src/index.js +0 -10
- package/build/src/index.js.map +0 -1
- package/build/src/semconv.d.ts +0 -9
- package/build/src/semconv.js +0 -21
- package/build/src/semconv.js.map +0 -1
- package/build/src/types.d.ts +0 -29
- package/build/src/types.js +0 -7
- package/build/src/types.js.map +0 -1
- package/build/src/utils.d.ts +0 -14
- package/build/src/utils.js +0 -124
- package/build/src/utils.js.map +0 -1
- package/build/src/version.d.ts +0 -2
- package/build/src/version.js +0 -10
- package/build/src/version.js.map +0 -1
- package/build/src/xhr.d.ts +0 -131
- package/build/src/xhr.js +0 -419
- package/build/src/xhr.js.map +0 -1
package/build/esnext/utils.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright The OpenTelemetry Authors
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-fetch
|
|
6
|
-
// These may be unified in the future.
|
|
7
|
-
import * as api from '@opentelemetry/api';
|
|
8
|
-
import { getStringListFromEnv } from '@opentelemetry/core';
|
|
9
|
-
const DIAG_LOGGER = api.diag.createComponentLogger({
|
|
10
|
-
namespace: '@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils',
|
|
11
|
-
});
|
|
12
|
-
function isDocument(value) {
|
|
13
|
-
return typeof Document !== 'undefined' && value instanceof Document;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Helper function to determine payload content length for XHR requests
|
|
17
|
-
* @param body
|
|
18
|
-
* @returns content length
|
|
19
|
-
*/
|
|
20
|
-
export function getXHRBodyLength(body) {
|
|
21
|
-
if (isDocument(body)) {
|
|
22
|
-
return new XMLSerializer().serializeToString(document).length;
|
|
23
|
-
}
|
|
24
|
-
// XMLHttpRequestBodyInit expands to the following:
|
|
25
|
-
if (typeof body === 'string') {
|
|
26
|
-
return getByteLength(body);
|
|
27
|
-
}
|
|
28
|
-
if (body instanceof Blob) {
|
|
29
|
-
return body.size;
|
|
30
|
-
}
|
|
31
|
-
if (body instanceof FormData) {
|
|
32
|
-
return getFormDataSize(body);
|
|
33
|
-
}
|
|
34
|
-
if (body instanceof URLSearchParams) {
|
|
35
|
-
return getByteLength(body.toString());
|
|
36
|
-
}
|
|
37
|
-
// ArrayBuffer | ArrayBufferView
|
|
38
|
-
if (body.byteLength !== undefined) {
|
|
39
|
-
return body.byteLength;
|
|
40
|
-
}
|
|
41
|
-
DIAG_LOGGER.warn('unknown body type');
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
45
|
-
function getByteLength(s) {
|
|
46
|
-
return TEXT_ENCODER.encode(s).byteLength;
|
|
47
|
-
}
|
|
48
|
-
function getFormDataSize(formData) {
|
|
49
|
-
let size = 0;
|
|
50
|
-
for (const [key, value] of formData.entries()) {
|
|
51
|
-
size += key.length;
|
|
52
|
-
if (value instanceof Blob) {
|
|
53
|
-
size += value.size;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
size += value.length;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return size;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Normalize an HTTP request method string per `http.request.method` spec
|
|
63
|
-
* https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
|
|
64
|
-
*/
|
|
65
|
-
export function normalizeHttpRequestMethod(method) {
|
|
66
|
-
const knownMethods = getKnownMethods();
|
|
67
|
-
const methUpper = method.toUpperCase();
|
|
68
|
-
if (methUpper in knownMethods) {
|
|
69
|
-
return methUpper;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return '_OTHER';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const DEFAULT_KNOWN_METHODS = {
|
|
76
|
-
CONNECT: true,
|
|
77
|
-
DELETE: true,
|
|
78
|
-
GET: true,
|
|
79
|
-
HEAD: true,
|
|
80
|
-
OPTIONS: true,
|
|
81
|
-
PATCH: true,
|
|
82
|
-
POST: true,
|
|
83
|
-
PUT: true,
|
|
84
|
-
TRACE: true,
|
|
85
|
-
// QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/
|
|
86
|
-
QUERY: true,
|
|
87
|
-
};
|
|
88
|
-
let knownMethods;
|
|
89
|
-
function getKnownMethods() {
|
|
90
|
-
if (knownMethods === undefined) {
|
|
91
|
-
const cfgMethods = getStringListFromEnv('OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS');
|
|
92
|
-
if (cfgMethods && cfgMethods.length > 0) {
|
|
93
|
-
knownMethods = {};
|
|
94
|
-
cfgMethods.forEach(m => {
|
|
95
|
-
knownMethods[m] = true;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
knownMethods = DEFAULT_KNOWN_METHODS;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return knownMethods;
|
|
103
|
-
}
|
|
104
|
-
const HTTP_PORT_FROM_PROTOCOL = {
|
|
105
|
-
'https:': '443',
|
|
106
|
-
'http:': '80',
|
|
107
|
-
};
|
|
108
|
-
export function serverPortFromUrl(url) {
|
|
109
|
-
const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
|
|
110
|
-
// Guard with `if (serverPort)` because `Number('') === 0`.
|
|
111
|
-
if (serverPort && !isNaN(serverPort)) {
|
|
112
|
-
return serverPort;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kGAAkG;AAClG,sCAAsC;AAEtC,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC;IACjD,SAAS,EACP,qEAAqE;CACxE,CAAC,CAAC;AAEH,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,QAAQ,KAAK,WAAW,IAAI,KAAK,YAAY,QAAQ,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAuC;IAEvC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;QACpB,OAAO,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;KAC/D;IAED,mDAAmD;IACnD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;KAC5B;IAED,IAAI,IAAI,YAAY,IAAI,EAAE;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC;KAClB;IAED,IAAI,IAAI,YAAY,QAAQ,EAAE;QAC5B,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;KAC9B;IAED,IAAI,IAAI,YAAY,eAAe,EAAE;QACnC,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;KACvC;IAED,gCAAgC;IAChC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;IAED,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACtC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AACvC,SAAS,aAAa,CAAC,CAAS;IAC9B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AAC3C,CAAC;AAED,SAAS,eAAe,CAAC,QAAkB;IACzC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;QAC7C,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC;QACnB,IAAI,KAAK,YAAY,IAAI,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;SACpB;aAAM;YACL,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;SACtB;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACvC,IAAI,SAAS,IAAI,YAAY,EAAE;QAC7B,OAAO,SAAS,CAAC;KAClB;SAAM;QACL,OAAO,QAAQ,CAAC;KACjB;AACH,CAAC;AAED,MAAM,qBAAqB,GAAG;IAC5B,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,qFAAqF;IACrF,KAAK,EAAE,IAAI;CACZ,CAAC;AACF,IAAI,YAAwC,CAAC;AAC7C,SAAS,eAAe;IACtB,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,MAAM,UAAU,GAAG,oBAAoB,CACrC,yCAAyC,CAC1C,CAAC;QACF,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,YAAY,GAAG,EAAE,CAAC;YAClB,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACrB,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;YACzB,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,YAAY,GAAG,qBAAqB,CAAC;SACtC;KACF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,uBAAuB,GAA8B;IACzD,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,IAAI;CACd,CAAC;AACF,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7E,2DAA2D;IAC3D,IAAI,UAAU,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC;KACnB;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-fetch\n// These may be unified in the future.\n\nimport * as api from '@opentelemetry/api';\nimport { getStringListFromEnv } from '@opentelemetry/core';\nimport type { URLLike } from '@opentelemetry/sdk-trace-web';\n\nconst DIAG_LOGGER = api.diag.createComponentLogger({\n namespace:\n '@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils',\n});\n\nfunction isDocument(value: unknown): value is Document {\n return typeof Document !== 'undefined' && value instanceof Document;\n}\n\n/**\n * Helper function to determine payload content length for XHR requests\n * @param body\n * @returns content length\n */\nexport function getXHRBodyLength(\n body: Document | XMLHttpRequestBodyInit\n): number | undefined {\n if (isDocument(body)) {\n return new XMLSerializer().serializeToString(document).length;\n }\n\n // XMLHttpRequestBodyInit expands to the following:\n if (typeof body === 'string') {\n return getByteLength(body);\n }\n\n if (body instanceof Blob) {\n return body.size;\n }\n\n if (body instanceof FormData) {\n return getFormDataSize(body);\n }\n\n if (body instanceof URLSearchParams) {\n return getByteLength(body.toString());\n }\n\n // ArrayBuffer | ArrayBufferView\n if (body.byteLength !== undefined) {\n return body.byteLength;\n }\n\n DIAG_LOGGER.warn('unknown body type');\n return undefined;\n}\n\nconst TEXT_ENCODER = new TextEncoder();\nfunction getByteLength(s: string): number {\n return TEXT_ENCODER.encode(s).byteLength;\n}\n\nfunction getFormDataSize(formData: FormData): number {\n let size = 0;\n for (const [key, value] of formData.entries()) {\n size += key.length;\n if (value instanceof Blob) {\n size += value.size;\n } else {\n size += value.length;\n }\n }\n return size;\n}\n\n/**\n * Normalize an HTTP request method string per `http.request.method` spec\n * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span\n */\nexport function normalizeHttpRequestMethod(method: string): string {\n const knownMethods = getKnownMethods();\n const methUpper = method.toUpperCase();\n if (methUpper in knownMethods) {\n return methUpper;\n } else {\n return '_OTHER';\n }\n}\n\nconst DEFAULT_KNOWN_METHODS = {\n CONNECT: true,\n DELETE: true,\n GET: true,\n HEAD: true,\n OPTIONS: true,\n PATCH: true,\n POST: true,\n PUT: true,\n TRACE: true,\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n QUERY: true,\n};\nlet knownMethods: { [key: string]: boolean };\nfunction getKnownMethods() {\n if (knownMethods === undefined) {\n const cfgMethods = getStringListFromEnv(\n 'OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS'\n );\n if (cfgMethods && cfgMethods.length > 0) {\n knownMethods = {};\n cfgMethods.forEach(m => {\n knownMethods[m] = true;\n });\n } else {\n knownMethods = DEFAULT_KNOWN_METHODS;\n }\n }\n return knownMethods;\n}\n\nconst HTTP_PORT_FROM_PROTOCOL: { [key: string]: string } = {\n 'https:': '443',\n 'http:': '80',\n};\nexport function serverPortFromUrl(url: URLLike): number | undefined {\n const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);\n // Guard with `if (serverPort)` because `Number('') === 0`.\n if (serverPort && !isNaN(serverPort)) {\n return serverPort;\n } else {\n return undefined;\n }\n}\n"]}
|
package/build/esnext/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,uBAAuB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.222.0-development.0';\n"]}
|
package/build/esnext/xhr.d.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import * as api from '@opentelemetry/api';
|
|
2
|
-
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
3
|
-
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
4
|
-
import type { OpenFunction, PropagateTraceHeaderCorsUrls, SendFunction, XhrMem } from './types';
|
|
5
|
-
export type XHRCustomAttributeFunction = (span: api.Span, xhr: XMLHttpRequest) => void;
|
|
6
|
-
/**
|
|
7
|
-
* XMLHttpRequest config
|
|
8
|
-
*/
|
|
9
|
-
export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConfig {
|
|
10
|
-
/**
|
|
11
|
-
* The number of timing resources is limited, after the limit
|
|
12
|
-
* (chrome 250, safari 150) the information is not collected anymore.
|
|
13
|
-
* The only way to prevent that is to regularly clean the resources
|
|
14
|
-
* whenever it is possible. This is needed only when PerformanceObserver
|
|
15
|
-
* is not available
|
|
16
|
-
*/
|
|
17
|
-
clearTimingResources?: boolean;
|
|
18
|
-
/** URLs which should include trace headers when origin doesn't match */
|
|
19
|
-
propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;
|
|
20
|
-
/**
|
|
21
|
-
* URLs that partially match any regex in ignoreUrls will not be traced.
|
|
22
|
-
* In addition, URLs that are _exact matches_ of strings in ignoreUrls will
|
|
23
|
-
* also not be traced.
|
|
24
|
-
*/
|
|
25
|
-
ignoreUrls?: Array<string | RegExp>;
|
|
26
|
-
/** Function for adding custom attributes on the span */
|
|
27
|
-
applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;
|
|
28
|
-
/** Ignore adding network events as span events */
|
|
29
|
-
ignoreNetworkEvents?: boolean;
|
|
30
|
-
/** Measure outgoing request size */
|
|
31
|
-
measureRequestSize?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* This class represents a XMLHttpRequest plugin for auto instrumentation
|
|
35
|
-
*/
|
|
36
|
-
export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {
|
|
37
|
-
readonly component: string;
|
|
38
|
-
readonly version: string;
|
|
39
|
-
moduleName: string;
|
|
40
|
-
private _tasksCount;
|
|
41
|
-
private _xhrMem;
|
|
42
|
-
private _usedResources;
|
|
43
|
-
private _isEnabled;
|
|
44
|
-
private _isXhrPatched;
|
|
45
|
-
constructor(config?: XMLHttpRequestInstrumentationConfig);
|
|
46
|
-
init(): void;
|
|
47
|
-
/**
|
|
48
|
-
* Adds custom headers to XMLHttpRequest
|
|
49
|
-
* @param xhr
|
|
50
|
-
* @param spanUrl
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
private _addHeaders;
|
|
54
|
-
/**
|
|
55
|
-
* Add cors pre flight child span
|
|
56
|
-
* @param span
|
|
57
|
-
* @param corsPreFlightRequest
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
|
-
private _addChildSpan;
|
|
61
|
-
/**
|
|
62
|
-
* Add attributes when span is going to end
|
|
63
|
-
* @param span
|
|
64
|
-
* @param xhr
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
_addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem): void;
|
|
68
|
-
private _applyAttributesAfterXHR;
|
|
69
|
-
/**
|
|
70
|
-
* will collect information about all resources created
|
|
71
|
-
* between "send" and "end" with additional waiting for main resource
|
|
72
|
-
* @param xhr
|
|
73
|
-
* @param spanUrl
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
private _addResourceObserver;
|
|
77
|
-
/**
|
|
78
|
-
* Clears the resource timings and all resources assigned with spans
|
|
79
|
-
* when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is
|
|
80
|
-
* set to true (default false)
|
|
81
|
-
* @private
|
|
82
|
-
*/
|
|
83
|
-
private _clearResources;
|
|
84
|
-
/**
|
|
85
|
-
* Finds appropriate resource and add network events to the span
|
|
86
|
-
* @param span
|
|
87
|
-
*/
|
|
88
|
-
private _findResourceAndAddNetworkEvents;
|
|
89
|
-
/**
|
|
90
|
-
* Removes the previous information about span.
|
|
91
|
-
* This might happened when the same xhr is used again.
|
|
92
|
-
* @param xhr
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
private _cleanPreviousSpanInformation;
|
|
96
|
-
/**
|
|
97
|
-
* Creates a new span when method "open" is called
|
|
98
|
-
* @param xhr
|
|
99
|
-
* @param url
|
|
100
|
-
* @param method
|
|
101
|
-
* @private
|
|
102
|
-
*/
|
|
103
|
-
private _createSpan;
|
|
104
|
-
/**
|
|
105
|
-
* Marks certain [resource]{@link PerformanceResourceTiming} when information
|
|
106
|
-
* from this is used to add events to span.
|
|
107
|
-
* This is done to avoid reusing the same resource again for next span
|
|
108
|
-
* @param resource
|
|
109
|
-
* @private
|
|
110
|
-
*/
|
|
111
|
-
private _markResourceAsUsed;
|
|
112
|
-
/**
|
|
113
|
-
* Patches the method open
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
protected _patchOpen(): (original: OpenFunction) => OpenFunction;
|
|
117
|
-
/**
|
|
118
|
-
* Patches the method send
|
|
119
|
-
* @private
|
|
120
|
-
*/
|
|
121
|
-
protected _patchSend(): (original: SendFunction) => SendFunction;
|
|
122
|
-
/**
|
|
123
|
-
* implements enable function
|
|
124
|
-
*/
|
|
125
|
-
enable(): void;
|
|
126
|
-
/**
|
|
127
|
-
* implements disable function
|
|
128
|
-
*/
|
|
129
|
-
disable(): void;
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=xhr.d.ts.map
|
package/build/esnext/xhr.js
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright The OpenTelemetry Authors
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import * as api from '@opentelemetry/api';
|
|
6
|
-
import { InstrumentationBase, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation';
|
|
7
|
-
import { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';
|
|
8
|
-
import { addSpanNetworkEvents, getResource, PerformanceTimingNames as PTN, shouldPropagateTraceHeaders, parseUrl, } from '@opentelemetry/sdk-trace-web';
|
|
9
|
-
import { ATTR_ERROR_TYPE, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_REQUEST_METHOD_ORIGINAL, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, } from '@opentelemetry/semantic-conventions';
|
|
10
|
-
import { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';
|
|
11
|
-
import { EventNames } from './enums/EventNames';
|
|
12
|
-
import { normalizeHttpRequestMethod, serverPortFromUrl, getXHRBodyLength, } from './utils';
|
|
13
|
-
import { VERSION } from './version';
|
|
14
|
-
// how long to wait for observer to collect information about resources
|
|
15
|
-
// this is needed as event "load" is called before observer
|
|
16
|
-
// hard to say how long it should really wait, seems like 300ms is
|
|
17
|
-
// safe enough
|
|
18
|
-
const OBSERVER_WAIT_TIME_MS = 300;
|
|
19
|
-
/**
|
|
20
|
-
* This class represents a XMLHttpRequest plugin for auto instrumentation
|
|
21
|
-
*/
|
|
22
|
-
export class XMLHttpRequestInstrumentation extends InstrumentationBase {
|
|
23
|
-
component = 'xml-http-request';
|
|
24
|
-
version = VERSION;
|
|
25
|
-
moduleName = this.component;
|
|
26
|
-
_tasksCount = 0;
|
|
27
|
-
_xhrMem = new WeakMap();
|
|
28
|
-
_usedResources = new WeakSet();
|
|
29
|
-
constructor(config = {}) {
|
|
30
|
-
super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);
|
|
31
|
-
}
|
|
32
|
-
init() { }
|
|
33
|
-
/**
|
|
34
|
-
* Adds custom headers to XMLHttpRequest
|
|
35
|
-
* @param xhr
|
|
36
|
-
* @param spanUrl
|
|
37
|
-
* @private
|
|
38
|
-
*/
|
|
39
|
-
_addHeaders(xhr, spanUrl) {
|
|
40
|
-
const url = parseUrl(spanUrl).href;
|
|
41
|
-
if (!shouldPropagateTraceHeaders(url, this.getConfig().propagateTraceHeaderCorsUrls)) {
|
|
42
|
-
const headers = {};
|
|
43
|
-
api.propagation.inject(api.context.active(), headers);
|
|
44
|
-
if (Object.keys(headers).length > 0) {
|
|
45
|
-
this._diag.debug('headers inject skipped due to CORS policy');
|
|
46
|
-
}
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const headers = {};
|
|
50
|
-
api.propagation.inject(api.context.active(), headers);
|
|
51
|
-
Object.keys(headers).forEach(key => {
|
|
52
|
-
xhr.setRequestHeader(key, String(headers[key]));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Add cors pre flight child span
|
|
57
|
-
* @param span
|
|
58
|
-
* @param corsPreFlightRequest
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
_addChildSpan(span, corsPreFlightRequest) {
|
|
62
|
-
api.context.with(api.trace.setSpan(api.context.active(), span), () => {
|
|
63
|
-
const childSpan = this.tracer.startSpan('CORS Preflight', {
|
|
64
|
-
startTime: corsPreFlightRequest[PTN.FETCH_START],
|
|
65
|
-
});
|
|
66
|
-
addSpanNetworkEvents(childSpan, corsPreFlightRequest, this.getConfig().ignoreNetworkEvents, undefined, true);
|
|
67
|
-
childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Add attributes when span is going to end
|
|
72
|
-
* @param span
|
|
73
|
-
* @param xhr
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
_addFinalSpanAttributes(span, xhrMem) {
|
|
77
|
-
if (xhrMem.status) {
|
|
78
|
-
// Intentionally exclude status=0, because XHR uses 0 for before a
|
|
79
|
-
// response is received and semconv says to only add the attribute if
|
|
80
|
-
// received a response.
|
|
81
|
-
span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
_applyAttributesAfterXHR(span, xhr) {
|
|
85
|
-
const applyCustomAttributesOnSpan = this.getConfig().applyCustomAttributesOnSpan;
|
|
86
|
-
if (typeof applyCustomAttributesOnSpan === 'function') {
|
|
87
|
-
safeExecuteInTheMiddle(() => applyCustomAttributesOnSpan(span, xhr), error => {
|
|
88
|
-
if (!error) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this._diag.error('applyCustomAttributesOnSpan', error);
|
|
92
|
-
}, true);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* will collect information about all resources created
|
|
97
|
-
* between "send" and "end" with additional waiting for main resource
|
|
98
|
-
* @param xhr
|
|
99
|
-
* @param spanUrl
|
|
100
|
-
* @private
|
|
101
|
-
*/
|
|
102
|
-
_addResourceObserver(xhr, spanUrl) {
|
|
103
|
-
const xhrMem = this._xhrMem.get(xhr);
|
|
104
|
-
if (!xhrMem ||
|
|
105
|
-
typeof PerformanceObserver !== 'function' ||
|
|
106
|
-
typeof PerformanceResourceTiming !== 'function') {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
xhrMem.createdResources = {
|
|
110
|
-
observer: new PerformanceObserver(list => {
|
|
111
|
-
const entries = list.getEntries();
|
|
112
|
-
const parsedUrl = parseUrl(spanUrl);
|
|
113
|
-
entries.forEach(entry => {
|
|
114
|
-
if (entry.initiatorType === 'xmlhttprequest' &&
|
|
115
|
-
entry.name === parsedUrl.href) {
|
|
116
|
-
if (xhrMem.createdResources) {
|
|
117
|
-
xhrMem.createdResources.entries.push(entry);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}),
|
|
122
|
-
entries: [],
|
|
123
|
-
};
|
|
124
|
-
xhrMem.createdResources.observer.observe({
|
|
125
|
-
entryTypes: ['resource'],
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Clears the resource timings and all resources assigned with spans
|
|
130
|
-
* when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is
|
|
131
|
-
* set to true (default false)
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
_clearResources() {
|
|
135
|
-
if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {
|
|
136
|
-
otperformance.clearResourceTimings();
|
|
137
|
-
this._xhrMem = new WeakMap();
|
|
138
|
-
this._usedResources = new WeakSet();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Finds appropriate resource and add network events to the span
|
|
143
|
-
* @param span
|
|
144
|
-
*/
|
|
145
|
-
_findResourceAndAddNetworkEvents(xhrMem, span, spanUrl, startTime, endTime) {
|
|
146
|
-
if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
let resources = xhrMem.createdResources.entries;
|
|
150
|
-
if (!resources || !resources.length) {
|
|
151
|
-
// fallback - either Observer is not available or it took longer
|
|
152
|
-
// then OBSERVER_WAIT_TIME_MS and observer didn't collect enough
|
|
153
|
-
// information
|
|
154
|
-
// ts thinks this is the perf_hooks module, but it is the browser performance api
|
|
155
|
-
resources = otperformance.getEntriesByType('resource');
|
|
156
|
-
}
|
|
157
|
-
const resource = getResource(parseUrl(spanUrl).href, startTime, endTime, resources, this._usedResources);
|
|
158
|
-
if (resource.mainRequest) {
|
|
159
|
-
const mainRequest = resource.mainRequest;
|
|
160
|
-
this._markResourceAsUsed(mainRequest);
|
|
161
|
-
const corsPreFlightRequest = resource.corsPreFlightRequest;
|
|
162
|
-
if (corsPreFlightRequest) {
|
|
163
|
-
this._addChildSpan(span, corsPreFlightRequest);
|
|
164
|
-
this._markResourceAsUsed(corsPreFlightRequest);
|
|
165
|
-
}
|
|
166
|
-
addSpanNetworkEvents(span, mainRequest, this.getConfig().ignoreNetworkEvents, undefined, true);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Removes the previous information about span.
|
|
171
|
-
* This might happened when the same xhr is used again.
|
|
172
|
-
* @param xhr
|
|
173
|
-
* @private
|
|
174
|
-
*/
|
|
175
|
-
_cleanPreviousSpanInformation(xhr) {
|
|
176
|
-
const xhrMem = this._xhrMem.get(xhr);
|
|
177
|
-
if (xhrMem) {
|
|
178
|
-
const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;
|
|
179
|
-
if (callbackToRemoveEvents) {
|
|
180
|
-
callbackToRemoveEvents();
|
|
181
|
-
}
|
|
182
|
-
this._xhrMem.delete(xhr);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Creates a new span when method "open" is called
|
|
187
|
-
* @param xhr
|
|
188
|
-
* @param url
|
|
189
|
-
* @param method
|
|
190
|
-
* @private
|
|
191
|
-
*/
|
|
192
|
-
_createSpan(xhr, url, method) {
|
|
193
|
-
const parsedUrl = parseUrl(url);
|
|
194
|
-
if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {
|
|
195
|
-
this._diag.debug('ignoring span as url matches ignored url');
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
const attributes = {};
|
|
199
|
-
const origMethod = method;
|
|
200
|
-
const normMethod = normalizeHttpRequestMethod(method);
|
|
201
|
-
const name = normMethod;
|
|
202
|
-
attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;
|
|
203
|
-
if (normMethod !== origMethod) {
|
|
204
|
-
attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;
|
|
205
|
-
}
|
|
206
|
-
attributes[ATTR_URL_FULL] = parsedUrl.toString();
|
|
207
|
-
attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;
|
|
208
|
-
const serverPort = serverPortFromUrl(parsedUrl);
|
|
209
|
-
if (serverPort) {
|
|
210
|
-
attributes[ATTR_SERVER_PORT] = serverPort;
|
|
211
|
-
}
|
|
212
|
-
const currentSpan = this.tracer.startSpan(name, {
|
|
213
|
-
kind: api.SpanKind.CLIENT,
|
|
214
|
-
attributes,
|
|
215
|
-
});
|
|
216
|
-
currentSpan.addEvent(EventNames.METHOD_OPEN);
|
|
217
|
-
this._cleanPreviousSpanInformation(xhr);
|
|
218
|
-
this._xhrMem.set(xhr, {
|
|
219
|
-
span: currentSpan,
|
|
220
|
-
spanUrl: url,
|
|
221
|
-
});
|
|
222
|
-
return currentSpan;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Marks certain [resource]{@link PerformanceResourceTiming} when information
|
|
226
|
-
* from this is used to add events to span.
|
|
227
|
-
* This is done to avoid reusing the same resource again for next span
|
|
228
|
-
* @param resource
|
|
229
|
-
* @private
|
|
230
|
-
*/
|
|
231
|
-
_markResourceAsUsed(resource) {
|
|
232
|
-
this._usedResources.add(resource);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Patches the method open
|
|
236
|
-
* @private
|
|
237
|
-
*/
|
|
238
|
-
_patchOpen() {
|
|
239
|
-
return (original) => {
|
|
240
|
-
const plugin = this;
|
|
241
|
-
return function patchOpen(...args) {
|
|
242
|
-
if (!plugin._isEnabled) {
|
|
243
|
-
return original.apply(this, args);
|
|
244
|
-
}
|
|
245
|
-
const method = args[0];
|
|
246
|
-
const url = args[1];
|
|
247
|
-
plugin._createSpan(this, url, method);
|
|
248
|
-
return original.apply(this, args);
|
|
249
|
-
};
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Patches the method send
|
|
254
|
-
* @private
|
|
255
|
-
*/
|
|
256
|
-
_patchSend() {
|
|
257
|
-
const plugin = this;
|
|
258
|
-
function endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime) {
|
|
259
|
-
const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;
|
|
260
|
-
if (typeof callbackToRemoveEvents === 'function') {
|
|
261
|
-
callbackToRemoveEvents();
|
|
262
|
-
}
|
|
263
|
-
const { span, spanUrl, sendStartTime } = xhrMem;
|
|
264
|
-
if (span) {
|
|
265
|
-
plugin._findResourceAndAddNetworkEvents(xhrMem, span, spanUrl, sendStartTime, performanceEndTime);
|
|
266
|
-
span.addEvent(eventName, endTime);
|
|
267
|
-
plugin._addFinalSpanAttributes(span, xhrMem);
|
|
268
|
-
span.end(endTime);
|
|
269
|
-
plugin._tasksCount--;
|
|
270
|
-
}
|
|
271
|
-
plugin._clearResources();
|
|
272
|
-
}
|
|
273
|
-
function endSpan(eventName, xhr, isError, errorType) {
|
|
274
|
-
const xhrMem = plugin._xhrMem.get(xhr);
|
|
275
|
-
if (!xhrMem) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
xhrMem.status = xhr.status;
|
|
279
|
-
xhrMem.statusText = xhr.statusText;
|
|
280
|
-
plugin._xhrMem.delete(xhr);
|
|
281
|
-
if (xhrMem.span) {
|
|
282
|
-
const span = xhrMem.span;
|
|
283
|
-
plugin._applyAttributesAfterXHR(span, xhr);
|
|
284
|
-
if (isError) {
|
|
285
|
-
if (errorType) {
|
|
286
|
-
span.setStatus({
|
|
287
|
-
code: api.SpanStatusCode.ERROR,
|
|
288
|
-
message: errorType,
|
|
289
|
-
});
|
|
290
|
-
span.setAttribute(ATTR_ERROR_TYPE, errorType);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else if (xhrMem.status && xhrMem.status >= 400) {
|
|
294
|
-
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
295
|
-
span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const performanceEndTime = hrTime();
|
|
299
|
-
const endTime = Date.now();
|
|
300
|
-
// the timeout is needed as observer doesn't have yet information
|
|
301
|
-
// when event "load" is called. Also the time may differ depends on
|
|
302
|
-
// browser and speed of computer
|
|
303
|
-
setTimeout(() => {
|
|
304
|
-
endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);
|
|
305
|
-
}, OBSERVER_WAIT_TIME_MS);
|
|
306
|
-
}
|
|
307
|
-
function onError() {
|
|
308
|
-
endSpan(EventNames.EVENT_ERROR, this, true, 'error');
|
|
309
|
-
}
|
|
310
|
-
function onAbort() {
|
|
311
|
-
endSpan(EventNames.EVENT_ABORT, this, false);
|
|
312
|
-
}
|
|
313
|
-
function onTimeout() {
|
|
314
|
-
endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');
|
|
315
|
-
}
|
|
316
|
-
function onLoad() {
|
|
317
|
-
if (this.status < 299) {
|
|
318
|
-
endSpan(EventNames.EVENT_LOAD, this, false);
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
endSpan(EventNames.EVENT_ERROR, this, false);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
function unregister(xhr) {
|
|
325
|
-
xhr.removeEventListener('abort', onAbort);
|
|
326
|
-
xhr.removeEventListener('error', onError);
|
|
327
|
-
xhr.removeEventListener('load', onLoad);
|
|
328
|
-
xhr.removeEventListener('timeout', onTimeout);
|
|
329
|
-
const xhrMem = plugin._xhrMem.get(xhr);
|
|
330
|
-
if (xhrMem) {
|
|
331
|
-
xhrMem.callbackToRemoveEvents = undefined;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return (original) => {
|
|
335
|
-
return function patchSend(...args) {
|
|
336
|
-
if (!plugin._isEnabled) {
|
|
337
|
-
return original.apply(this, args);
|
|
338
|
-
}
|
|
339
|
-
const xhrMem = plugin._xhrMem.get(this);
|
|
340
|
-
if (!xhrMem) {
|
|
341
|
-
return original.apply(this, args);
|
|
342
|
-
}
|
|
343
|
-
const currentSpan = xhrMem.span;
|
|
344
|
-
const spanUrl = xhrMem.spanUrl;
|
|
345
|
-
if (currentSpan && spanUrl) {
|
|
346
|
-
if (plugin.getConfig().measureRequestSize && args?.[0]) {
|
|
347
|
-
const body = args[0];
|
|
348
|
-
const bodyLength = getXHRBodyLength(body);
|
|
349
|
-
if (bodyLength !== undefined) {
|
|
350
|
-
currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
api.context.with(api.trace.setSpan(api.context.active(), currentSpan), () => {
|
|
354
|
-
plugin._tasksCount++;
|
|
355
|
-
xhrMem.sendStartTime = hrTime();
|
|
356
|
-
currentSpan.addEvent(EventNames.METHOD_SEND);
|
|
357
|
-
this.addEventListener('abort', onAbort);
|
|
358
|
-
this.addEventListener('error', onError);
|
|
359
|
-
this.addEventListener('load', onLoad);
|
|
360
|
-
this.addEventListener('timeout', onTimeout);
|
|
361
|
-
xhrMem.callbackToRemoveEvents = () => {
|
|
362
|
-
unregister(this);
|
|
363
|
-
if (xhrMem.createdResources) {
|
|
364
|
-
xhrMem.createdResources.observer.disconnect();
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
plugin._addHeaders(this, spanUrl);
|
|
368
|
-
plugin._addResourceObserver(this, spanUrl);
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
return original.apply(this, args);
|
|
372
|
-
};
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* implements enable function
|
|
377
|
-
*/
|
|
378
|
-
enable() {
|
|
379
|
-
if (this._isEnabled) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if (this._isXhrPatched) {
|
|
383
|
-
this._diag.debug('reactivating existing patch on', this.moduleName, this.version);
|
|
384
|
-
this._isEnabled = true;
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
try {
|
|
388
|
-
this._diag.debug('applying patch to', this.moduleName, this.version);
|
|
389
|
-
this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());
|
|
390
|
-
this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());
|
|
391
|
-
this._isXhrPatched = true;
|
|
392
|
-
this._isEnabled = true;
|
|
393
|
-
}
|
|
394
|
-
catch (err) {
|
|
395
|
-
// make sure there is no wrapped functions
|
|
396
|
-
this._unwrap(XMLHttpRequest.prototype, 'open');
|
|
397
|
-
this._unwrap(XMLHttpRequest.prototype, 'send');
|
|
398
|
-
this._diag.warn('Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +
|
|
399
|
-
'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.', err);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* implements disable function
|
|
404
|
-
*/
|
|
405
|
-
disable() {
|
|
406
|
-
if (!this._isEnabled) {
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
this._isEnabled = false;
|
|
410
|
-
this._tasksCount = 0;
|
|
411
|
-
this._xhrMem = new WeakMap();
|
|
412
|
-
this._usedResources = new WeakSet();
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
//# sourceMappingURL=xhr.js.map
|