@opentelemetry/instrumentation-xml-http-request 0.222.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.
Files changed (94) hide show
  1. package/README.md +8 -10
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/index.cjs +3 -0
  4. package/dist/index.d.cts +2 -0
  5. package/dist/index.d.mts +2 -0
  6. package/dist/index.mjs +2 -0
  7. package/dist/semconv.cjs +13 -0
  8. package/dist/semconv.cjs.map +1 -0
  9. package/dist/semconv.mjs +13 -0
  10. package/dist/semconv.mjs.map +1 -0
  11. package/dist/types.d.cts +31 -0
  12. package/dist/types.d.cts.map +1 -0
  13. package/dist/types.d.mts +31 -0
  14. package/dist/types.d.mts.map +1 -0
  15. package/dist/utils.cjs +86 -0
  16. package/dist/utils.cjs.map +1 -0
  17. package/dist/utils.mjs +82 -0
  18. package/dist/utils.mjs.map +1 -0
  19. package/dist/version.cjs +6 -0
  20. package/dist/version.cjs.map +1 -0
  21. package/dist/version.mjs +6 -0
  22. package/dist/version.mjs.map +1 -0
  23. package/dist/xhr.cjs +345 -0
  24. package/dist/xhr.cjs.map +1 -0
  25. package/dist/xhr.d.cts +133 -0
  26. package/dist/xhr.d.cts.map +1 -0
  27. package/dist/xhr.d.mts +133 -0
  28. package/dist/xhr.d.mts.map +1 -0
  29. package/dist/xhr.mjs +343 -0
  30. package/dist/xhr.mjs.map +1 -0
  31. package/package.json +34 -31
  32. package/build/esm/enums/EventNames.d.ts +0 -9
  33. package/build/esm/enums/EventNames.js +0 -14
  34. package/build/esm/enums/EventNames.js.map +0 -1
  35. package/build/esm/index.d.ts +0 -3
  36. package/build/esm/index.js +0 -6
  37. package/build/esm/index.js.map +0 -1
  38. package/build/esm/semconv.d.ts +0 -9
  39. package/build/esm/semconv.js +0 -18
  40. package/build/esm/semconv.js.map +0 -1
  41. package/build/esm/types.d.ts +0 -29
  42. package/build/esm/types.js +0 -6
  43. package/build/esm/types.js.map +0 -1
  44. package/build/esm/utils.d.ts +0 -14
  45. package/build/esm/utils.js +0 -118
  46. package/build/esm/utils.js.map +0 -1
  47. package/build/esm/version.d.ts +0 -2
  48. package/build/esm/version.js +0 -7
  49. package/build/esm/version.js.map +0 -1
  50. package/build/esm/xhr.d.ts +0 -131
  51. package/build/esm/xhr.js +0 -415
  52. package/build/esm/xhr.js.map +0 -1
  53. package/build/esnext/enums/EventNames.d.ts +0 -9
  54. package/build/esnext/enums/EventNames.js +0 -14
  55. package/build/esnext/enums/EventNames.js.map +0 -1
  56. package/build/esnext/index.d.ts +0 -3
  57. package/build/esnext/index.js +0 -6
  58. package/build/esnext/index.js.map +0 -1
  59. package/build/esnext/semconv.d.ts +0 -9
  60. package/build/esnext/semconv.js +0 -18
  61. package/build/esnext/semconv.js.map +0 -1
  62. package/build/esnext/types.d.ts +0 -29
  63. package/build/esnext/types.js +0 -6
  64. package/build/esnext/types.js.map +0 -1
  65. package/build/esnext/utils.d.ts +0 -14
  66. package/build/esnext/utils.js +0 -118
  67. package/build/esnext/utils.js.map +0 -1
  68. package/build/esnext/version.d.ts +0 -2
  69. package/build/esnext/version.js +0 -7
  70. package/build/esnext/version.js.map +0 -1
  71. package/build/esnext/xhr.d.ts +0 -131
  72. package/build/esnext/xhr.js +0 -415
  73. package/build/esnext/xhr.js.map +0 -1
  74. package/build/src/enums/EventNames.d.ts +0 -9
  75. package/build/src/enums/EventNames.js +0 -17
  76. package/build/src/enums/EventNames.js.map +0 -1
  77. package/build/src/index.d.ts +0 -3
  78. package/build/src/index.js +0 -10
  79. package/build/src/index.js.map +0 -1
  80. package/build/src/semconv.d.ts +0 -9
  81. package/build/src/semconv.js +0 -21
  82. package/build/src/semconv.js.map +0 -1
  83. package/build/src/types.d.ts +0 -29
  84. package/build/src/types.js +0 -7
  85. package/build/src/types.js.map +0 -1
  86. package/build/src/utils.d.ts +0 -14
  87. package/build/src/utils.js +0 -124
  88. package/build/src/utils.js.map +0 -1
  89. package/build/src/version.d.ts +0 -2
  90. package/build/src/version.js +0 -10
  91. package/build/src/version.js.map +0 -1
  92. package/build/src/xhr.d.ts +0 -131
  93. package/build/src/xhr.js +0 -419
  94. package/build/src/xhr.js.map +0 -1
package/README.md CHANGED
@@ -16,22 +16,22 @@ npm install --save @opentelemetry/instrumentation-xml-http-request
16
16
  ## Usage
17
17
 
18
18
  ```js
19
+ import { context, trace } from '@opentelemetry/api';
19
20
  import {
20
21
  ConsoleSpanExporter,
21
22
  SimpleSpanProcessor,
22
- WebTracerProvider,
23
- } from '@opentelemetry/sdk-trace-web';
23
+ TracerProvider,
24
+ } from '@opentelemetry/sdk-trace';
24
25
  import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
25
26
  import { ZoneContextManager } from '@opentelemetry/context-zone';
26
27
  import { registerInstrumentations } from '@opentelemetry/instrumentation';
27
28
 
28
- const providerWithZone = new WebTracerProvider({
29
+ const providerWithZone = new TracerProvider({
29
30
  spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
30
31
  });
31
32
 
32
- providerWithZone.register({
33
- contextManager: new ZoneContextManager(),
34
- });
33
+ context.setGlobalContextManager(new ZoneContextManager().enable());
34
+ trace.setGlobalTracerProvider(providerWithZone);
35
35
 
36
36
  registerInstrumentations({
37
37
  instrumentations: [
@@ -50,10 +50,8 @@ const webTracerWithZone = providerWithZone.getTracer('default');
50
50
  const xmlHttpRequestInstrumentation = new XMLHttpRequestInstrumentation({
51
51
  propagateTraceHeaderCorsUrls: ['http://localhost:8090']
52
52
  });
53
- const providerWithZone = new WebTracerProvider();
54
- providerWithZone.register({
55
- contextManager: new ZoneContextManager(),
56
- });
53
+ const providerWithZone = new TracerProvider();
54
+ context.setGlobalContextManager(new ZoneContextManager().enable());
57
55
  xmlHttpRequestInstrumentation.setTracerProvider(providerWithZone);
58
56
  /////////////////////////////////////////
59
57
 
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
package/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xhr = require("./xhr.cjs");
3
+ exports.XMLHttpRequestInstrumentation = require_xhr.XMLHttpRequestInstrumentation;
@@ -0,0 +1,2 @@
1
+ import { XHRCustomAttributeFunction, XMLHttpRequestInstrumentation, XMLHttpRequestInstrumentationConfig } from "./xhr.cjs";
2
+ export { type XHRCustomAttributeFunction, XMLHttpRequestInstrumentation, type XMLHttpRequestInstrumentationConfig };
@@ -0,0 +1,2 @@
1
+ import { XHRCustomAttributeFunction, XMLHttpRequestInstrumentation, XMLHttpRequestInstrumentationConfig } from "./xhr.mjs";
2
+ export { type XHRCustomAttributeFunction, XMLHttpRequestInstrumentation, type XMLHttpRequestInstrumentationConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { XMLHttpRequestInstrumentation } from "./xhr.mjs";
2
+ export { XMLHttpRequestInstrumentation };
@@ -0,0 +1,13 @@
1
+ //#region src/semconv.ts
2
+ /**
3
+ * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
4
+ *
5
+ * @example 3495
6
+ *
7
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
8
+ */
9
+ const ATTR_HTTP_REQUEST_BODY_SIZE = "http.request.body.size";
10
+ //#endregion
11
+ exports.ATTR_HTTP_REQUEST_BODY_SIZE = ATTR_HTTP_REQUEST_BODY_SIZE;
12
+
13
+ //# sourceMappingURL=semconv.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.cjs","names":[],"sources":["../src/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const;\n"],"mappings":";;;;;;;;AAkBA,MAAa,8BAA8B"}
@@ -0,0 +1,13 @@
1
+ //#region src/semconv.ts
2
+ /**
3
+ * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
4
+ *
5
+ * @example 3495
6
+ *
7
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
8
+ */
9
+ const ATTR_HTTP_REQUEST_BODY_SIZE = "http.request.body.size";
10
+ //#endregion
11
+ export { ATTR_HTTP_REQUEST_BODY_SIZE };
12
+
13
+ //# sourceMappingURL=semconv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.mjs","names":[],"sources":["../src/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const;\n"],"mappings":";;;;;;;;AAkBA,MAAa,8BAA8B"}
@@ -0,0 +1,31 @@
1
+ import * as api from "@opentelemetry/api";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * method "open" from XMLHttpRequest
5
+ */
6
+ type OpenFunction = (method: string, url: string, async?: boolean, user?: string | null, pass?: string | null) => void;
7
+ /**
8
+ * method "send" from XMLHttpRequest
9
+ */
10
+ type SendFunction = typeof XMLHttpRequest.prototype.send;
11
+ /**
12
+ * interface to store information in weak map about spans, resources and
13
+ * callbacks
14
+ */
15
+ interface XhrMem {
16
+ status?: number;
17
+ statusText?: string;
18
+ span: api.Span;
19
+ spanUrl?: string;
20
+ sendStartTime?: api.HrTime;
21
+ createdResources?: {
22
+ observer: PerformanceObserver;
23
+ entries: PerformanceResourceTiming[];
24
+ };
25
+ callbackToRemoveEvents?: () => void;
26
+ }
27
+ type PropagateTraceHeaderCorsUrl = string | RegExp;
28
+ type PropagateTraceHeaderCorsUrls = PropagateTraceHeaderCorsUrl | PropagateTraceHeaderCorsUrl[];
29
+ //#endregion
30
+ export { OpenFunction, PropagateTraceHeaderCorsUrl, PropagateTraceHeaderCorsUrls, SendFunction, XhrMem };
31
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.d.ts"],"mappings":";;;;;KAIY,gBAAgB,gBAAgB,aAAa,iBAAiB,sBAAsB;;;;KAIpF,sBAAsB,eAAe,UAAU;;;;;UAM1C;EACb;EACA;EACA,MAAM,IAAI;EACV;EACA,gBAAgB,IAAI;EACpB;IACI,UAAU;IACV,SAAS;;EAEb;;KAEQ,uCAAuC;KACvC,+BAA+B,8BAA8B"}
@@ -0,0 +1,31 @@
1
+ import * as api from "@opentelemetry/api";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * method "open" from XMLHttpRequest
5
+ */
6
+ type OpenFunction = (method: string, url: string, async?: boolean, user?: string | null, pass?: string | null) => void;
7
+ /**
8
+ * method "send" from XMLHttpRequest
9
+ */
10
+ type SendFunction = typeof XMLHttpRequest.prototype.send;
11
+ /**
12
+ * interface to store information in weak map about spans, resources and
13
+ * callbacks
14
+ */
15
+ interface XhrMem {
16
+ status?: number;
17
+ statusText?: string;
18
+ span: api.Span;
19
+ spanUrl?: string;
20
+ sendStartTime?: api.HrTime;
21
+ createdResources?: {
22
+ observer: PerformanceObserver;
23
+ entries: PerformanceResourceTiming[];
24
+ };
25
+ callbackToRemoveEvents?: () => void;
26
+ }
27
+ type PropagateTraceHeaderCorsUrl = string | RegExp;
28
+ type PropagateTraceHeaderCorsUrls = PropagateTraceHeaderCorsUrl | PropagateTraceHeaderCorsUrl[];
29
+ //#endregion
30
+ export { OpenFunction, PropagateTraceHeaderCorsUrl, PropagateTraceHeaderCorsUrls, SendFunction, XhrMem };
31
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.d.ts"],"mappings":";;;;;KAIY,gBAAgB,gBAAgB,aAAa,iBAAiB,sBAAsB;;;;KAIpF,sBAAsB,eAAe,UAAU;;;;;UAM1C;EACb;EACA;EACA,MAAM,IAAI;EACV;EACA,gBAAgB,IAAI;EACpB;IACI,UAAU;IACV,SAAS;;EAEb;;KAEQ,uCAAuC;KACvC,+BAA+B,8BAA8B"}
package/dist/utils.cjs ADDED
@@ -0,0 +1,86 @@
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ let _opentelemetry_api = require("@opentelemetry/api");
3
+ _opentelemetry_api = require_runtime.__toESM(_opentelemetry_api);
4
+ let _opentelemetry_core = require("@opentelemetry/core");
5
+ //#region src/utils.ts
6
+ const DIAG_LOGGER = _opentelemetry_api.diag.createComponentLogger({ namespace: "@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils" });
7
+ function isDocument(value) {
8
+ return typeof Document !== "undefined" && value instanceof Document;
9
+ }
10
+ /**
11
+ * Helper function to determine payload content length for XHR requests
12
+ * @param body
13
+ * @returns content length
14
+ */
15
+ function getXHRBodyLength(body) {
16
+ if (isDocument(body)) return new XMLSerializer().serializeToString(document).length;
17
+ if (typeof body === "string") return getByteLength(body);
18
+ if (body instanceof Blob) return body.size;
19
+ if (body instanceof FormData) return getFormDataSize(body);
20
+ if (body instanceof URLSearchParams) return getByteLength(body.toString());
21
+ if (body.byteLength !== void 0) return body.byteLength;
22
+ DIAG_LOGGER.warn("unknown body type");
23
+ }
24
+ const TEXT_ENCODER = new TextEncoder();
25
+ function getByteLength(s) {
26
+ return TEXT_ENCODER.encode(s).byteLength;
27
+ }
28
+ function getFormDataSize(formData) {
29
+ let size = 0;
30
+ for (const [key, value] of formData.entries()) {
31
+ size += key.length;
32
+ if (value instanceof Blob) size += value.size;
33
+ else size += value.length;
34
+ }
35
+ return size;
36
+ }
37
+ /**
38
+ * Normalize an HTTP request method string per `http.request.method` spec
39
+ * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
40
+ */
41
+ function normalizeHttpRequestMethod(method) {
42
+ const knownMethods = getKnownMethods();
43
+ const methUpper = method.toUpperCase();
44
+ if (methUpper in knownMethods) return methUpper;
45
+ else return "_OTHER";
46
+ }
47
+ const DEFAULT_KNOWN_METHODS = {
48
+ CONNECT: true,
49
+ DELETE: true,
50
+ GET: true,
51
+ HEAD: true,
52
+ OPTIONS: true,
53
+ PATCH: true,
54
+ POST: true,
55
+ PUT: true,
56
+ TRACE: true,
57
+ QUERY: true
58
+ };
59
+ let knownMethods;
60
+ function getKnownMethods() {
61
+ if (knownMethods === void 0) {
62
+ const cfgMethods = (0, _opentelemetry_core.getStringListFromEnv)("OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS");
63
+ if (cfgMethods && cfgMethods.length > 0) {
64
+ knownMethods = {};
65
+ cfgMethods.forEach((m) => {
66
+ knownMethods[m] = true;
67
+ });
68
+ } else knownMethods = DEFAULT_KNOWN_METHODS;
69
+ }
70
+ return knownMethods;
71
+ }
72
+ const HTTP_PORT_FROM_PROTOCOL = {
73
+ "https:": "443",
74
+ "http:": "80"
75
+ };
76
+ function serverPortFromUrl(url) {
77
+ const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
78
+ if (serverPort && !isNaN(serverPort)) return serverPort;
79
+ else return;
80
+ }
81
+ //#endregion
82
+ exports.getXHRBodyLength = getXHRBodyLength;
83
+ exports.normalizeHttpRequestMethod = normalizeHttpRequestMethod;
84
+ exports.serverPortFromUrl = serverPortFromUrl;
85
+
86
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":["api","getStringListFromEnv"],"sources":["../src/utils.ts"],"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/web-common';\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"],"mappings":";;;;;AAYA,MAAM,cAAcA,mBAAI,KAAK,sBAAsB,EACjD,WACE,sEACJ,CAAC;AAED,SAAS,WAAW,OAAmC;CACrD,OAAO,OAAO,aAAa,eAAe,iBAAiB;AAC7D;;;;;;AAOA,SAAgB,iBACd,MACoB;CACpB,IAAI,WAAW,IAAI,GACjB,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,QAAQ,CAAC,CAAC;CAIzD,IAAI,OAAO,SAAS,UAClB,OAAO,cAAc,IAAI;CAG3B,IAAI,gBAAgB,MAClB,OAAO,KAAK;CAGd,IAAI,gBAAgB,UAClB,OAAO,gBAAgB,IAAI;CAG7B,IAAI,gBAAgB,iBAClB,OAAO,cAAc,KAAK,SAAS,CAAC;CAItC,IAAI,KAAK,eAAe,KAAA,GACtB,OAAO,KAAK;CAGd,YAAY,KAAK,mBAAmB;AAEtC;AAEA,MAAM,eAAe,IAAI,YAAY;AACrC,SAAS,cAAc,GAAmB;CACxC,OAAO,aAAa,OAAO,CAAC,CAAC,CAAC;AAChC;AAEA,SAAS,gBAAgB,UAA4B;CACnD,IAAI,OAAO;CACX,KAAK,MAAM,CAAC,KAAK,UAAU,SAAS,QAAQ,GAAG;EAC7C,QAAQ,IAAI;EACZ,IAAI,iBAAiB,MACnB,QAAQ,MAAM;OAEd,QAAQ,MAAM;CAElB;CACA,OAAO;AACT;;;;;AAMA,SAAgB,2BAA2B,QAAwB;CACjE,MAAM,eAAe,gBAAgB;CACrC,MAAM,YAAY,OAAO,YAAY;CACrC,IAAI,aAAa,cACf,OAAO;MAEP,OAAO;AAEX;AAEA,MAAM,wBAAwB;CAC5B,SAAS;CACT,QAAQ;CACR,KAAK;CACL,MAAM;CACN,SAAS;CACT,OAAO;CACP,MAAM;CACN,KAAK;CACL,OAAO;CAEP,OAAO;AACT;AACA,IAAI;AACJ,SAAS,kBAAkB;CACzB,IAAI,iBAAiB,KAAA,GAAW;EAC9B,MAAM,cAAA,GAAaC,oBAAAA,qBAAAA,CACjB,yCACF;EACA,IAAI,cAAc,WAAW,SAAS,GAAG;GACvC,eAAe,CAAC;GAChB,WAAW,SAAQ,MAAK;IACtB,aAAa,KAAK;GACpB,CAAC;EACH,OACE,eAAe;CAEnB;CACA,OAAO;AACT;AAEA,MAAM,0BAAqD;CACzD,UAAU;CACV,SAAS;AACX;AACA,SAAgB,kBAAkB,KAAkC;CAClE,MAAM,aAAa,OAAO,IAAI,QAAQ,wBAAwB,IAAI,SAAS;CAE3E,IAAI,cAAc,CAAC,MAAM,UAAU,GACjC,OAAO;MAEP;AAEJ"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,82 @@
1
+ import * as api from "@opentelemetry/api";
2
+ import { getStringListFromEnv } from "@opentelemetry/core";
3
+ //#region src/utils.ts
4
+ const DIAG_LOGGER = api.diag.createComponentLogger({ namespace: "@opentelemetry/opentelemetry-instrumentation-xml-http-request/utils" });
5
+ function isDocument(value) {
6
+ return typeof Document !== "undefined" && value instanceof Document;
7
+ }
8
+ /**
9
+ * Helper function to determine payload content length for XHR requests
10
+ * @param body
11
+ * @returns content length
12
+ */
13
+ function getXHRBodyLength(body) {
14
+ if (isDocument(body)) return new XMLSerializer().serializeToString(document).length;
15
+ if (typeof body === "string") return getByteLength(body);
16
+ if (body instanceof Blob) return body.size;
17
+ if (body instanceof FormData) return getFormDataSize(body);
18
+ if (body instanceof URLSearchParams) return getByteLength(body.toString());
19
+ if (body.byteLength !== void 0) return body.byteLength;
20
+ DIAG_LOGGER.warn("unknown body type");
21
+ }
22
+ const TEXT_ENCODER = new TextEncoder();
23
+ function getByteLength(s) {
24
+ return TEXT_ENCODER.encode(s).byteLength;
25
+ }
26
+ function getFormDataSize(formData) {
27
+ let size = 0;
28
+ for (const [key, value] of formData.entries()) {
29
+ size += key.length;
30
+ if (value instanceof Blob) size += value.size;
31
+ else size += value.length;
32
+ }
33
+ return size;
34
+ }
35
+ /**
36
+ * Normalize an HTTP request method string per `http.request.method` spec
37
+ * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
38
+ */
39
+ function normalizeHttpRequestMethod(method) {
40
+ const knownMethods = getKnownMethods();
41
+ const methUpper = method.toUpperCase();
42
+ if (methUpper in knownMethods) return methUpper;
43
+ else return "_OTHER";
44
+ }
45
+ const DEFAULT_KNOWN_METHODS = {
46
+ CONNECT: true,
47
+ DELETE: true,
48
+ GET: true,
49
+ HEAD: true,
50
+ OPTIONS: true,
51
+ PATCH: true,
52
+ POST: true,
53
+ PUT: true,
54
+ TRACE: true,
55
+ QUERY: true
56
+ };
57
+ let knownMethods;
58
+ function getKnownMethods() {
59
+ if (knownMethods === void 0) {
60
+ const cfgMethods = getStringListFromEnv("OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS");
61
+ if (cfgMethods && cfgMethods.length > 0) {
62
+ knownMethods = {};
63
+ cfgMethods.forEach((m) => {
64
+ knownMethods[m] = true;
65
+ });
66
+ } else knownMethods = DEFAULT_KNOWN_METHODS;
67
+ }
68
+ return knownMethods;
69
+ }
70
+ const HTTP_PORT_FROM_PROTOCOL = {
71
+ "https:": "443",
72
+ "http:": "80"
73
+ };
74
+ function serverPortFromUrl(url) {
75
+ const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
76
+ if (serverPort && !isNaN(serverPort)) return serverPort;
77
+ else return;
78
+ }
79
+ //#endregion
80
+ export { getXHRBodyLength, normalizeHttpRequestMethod, serverPortFromUrl };
81
+
82
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"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/web-common';\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"],"mappings":";;;AAYA,MAAM,cAAc,IAAI,KAAK,sBAAsB,EACjD,WACE,sEACJ,CAAC;AAED,SAAS,WAAW,OAAmC;CACrD,OAAO,OAAO,aAAa,eAAe,iBAAiB;AAC7D;;;;;;AAOA,SAAgB,iBACd,MACoB;CACpB,IAAI,WAAW,IAAI,GACjB,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,QAAQ,CAAC,CAAC;CAIzD,IAAI,OAAO,SAAS,UAClB,OAAO,cAAc,IAAI;CAG3B,IAAI,gBAAgB,MAClB,OAAO,KAAK;CAGd,IAAI,gBAAgB,UAClB,OAAO,gBAAgB,IAAI;CAG7B,IAAI,gBAAgB,iBAClB,OAAO,cAAc,KAAK,SAAS,CAAC;CAItC,IAAI,KAAK,eAAe,KAAA,GACtB,OAAO,KAAK;CAGd,YAAY,KAAK,mBAAmB;AAEtC;AAEA,MAAM,eAAe,IAAI,YAAY;AACrC,SAAS,cAAc,GAAmB;CACxC,OAAO,aAAa,OAAO,CAAC,CAAC,CAAC;AAChC;AAEA,SAAS,gBAAgB,UAA4B;CACnD,IAAI,OAAO;CACX,KAAK,MAAM,CAAC,KAAK,UAAU,SAAS,QAAQ,GAAG;EAC7C,QAAQ,IAAI;EACZ,IAAI,iBAAiB,MACnB,QAAQ,MAAM;OAEd,QAAQ,MAAM;CAElB;CACA,OAAO;AACT;;;;;AAMA,SAAgB,2BAA2B,QAAwB;CACjE,MAAM,eAAe,gBAAgB;CACrC,MAAM,YAAY,OAAO,YAAY;CACrC,IAAI,aAAa,cACf,OAAO;MAEP,OAAO;AAEX;AAEA,MAAM,wBAAwB;CAC5B,SAAS;CACT,QAAQ;CACR,KAAK;CACL,MAAM;CACN,SAAS;CACT,OAAO;CACP,MAAM;CACN,KAAK;CACL,OAAO;CAEP,OAAO;AACT;AACA,IAAI;AACJ,SAAS,kBAAkB;CACzB,IAAI,iBAAiB,KAAA,GAAW;EAC9B,MAAM,aAAa,qBACjB,yCACF;EACA,IAAI,cAAc,WAAW,SAAS,GAAG;GACvC,eAAe,CAAC;GAChB,WAAW,SAAQ,MAAK;IACtB,aAAa,KAAK;GACpB,CAAC;EACH,OACE,eAAe;CAEnB;CACA,OAAO;AACT;AAEA,MAAM,0BAAqD;CACzD,UAAU;CACV,SAAS;AACX;AACA,SAAgB,kBAAkB,KAAkC;CAClE,MAAM,aAAa,OAAO,IAAI,QAAQ,wBAAwB,IAAI,SAAS;CAE3E,IAAI,cAAc,CAAC,MAAM,UAAU,GACjC,OAAO;MAEP;AAEJ"}
@@ -0,0 +1,6 @@
1
+ //#region src/version.ts
2
+ const VERSION = "0.300.0-development.0";
3
+ //#endregion
4
+ exports.VERSION = VERSION;
5
+
6
+ //# sourceMappingURL=version.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0-development.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
@@ -0,0 +1,6 @@
1
+ //#region src/version.ts
2
+ const VERSION = "0.300.0-development.0";
3
+ //#endregion
4
+ export { VERSION };
5
+
6
+ //# sourceMappingURL=version.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.300.0-development.0';\n"],"mappings":";AAMA,MAAa,UAAU"}