@opentelemetry/instrumentation-fetch 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 (85) hide show
  1. package/README.md +9 -10
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/fetch.cjs +317 -0
  4. package/dist/fetch.cjs.map +1 -0
  5. package/dist/fetch.d.cts +120 -0
  6. package/dist/fetch.d.cts.map +1 -0
  7. package/dist/fetch.d.mts +120 -0
  8. package/dist/fetch.d.mts.map +1 -0
  9. package/dist/fetch.mjs +314 -0
  10. package/dist/fetch.mjs.map +1 -0
  11. package/dist/index.cjs +3 -0
  12. package/dist/index.d.cts +2 -0
  13. package/dist/index.d.mts +2 -0
  14. package/dist/index.mjs +2 -0
  15. package/dist/semconv.cjs +13 -0
  16. package/dist/semconv.cjs.map +1 -0
  17. package/dist/semconv.mjs +13 -0
  18. package/dist/semconv.mjs.map +1 -0
  19. package/dist/types.d.cts +12 -0
  20. package/dist/types.d.cts.map +1 -0
  21. package/dist/types.d.mts +12 -0
  22. package/dist/types.d.mts.map +1 -0
  23. package/dist/utils.cjs +157 -0
  24. package/dist/utils.cjs.map +1 -0
  25. package/dist/utils.mjs +154 -0
  26. package/dist/utils.mjs.map +1 -0
  27. package/dist/version.cjs +6 -0
  28. package/dist/version.cjs.map +1 -0
  29. package/dist/version.mjs +6 -0
  30. package/dist/version.mjs.map +1 -0
  31. package/package.json +34 -31
  32. package/build/esm/fetch.d.ts +0 -118
  33. package/build/esm/fetch.js +0 -412
  34. package/build/esm/fetch.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 -27
  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 -43
  45. package/build/esm/utils.js +0 -205
  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/esnext/fetch.d.ts +0 -118
  51. package/build/esnext/fetch.js +0 -412
  52. package/build/esnext/fetch.js.map +0 -1
  53. package/build/esnext/index.d.ts +0 -3
  54. package/build/esnext/index.js +0 -6
  55. package/build/esnext/index.js.map +0 -1
  56. package/build/esnext/semconv.d.ts +0 -9
  57. package/build/esnext/semconv.js +0 -18
  58. package/build/esnext/semconv.js.map +0 -1
  59. package/build/esnext/types.d.ts +0 -27
  60. package/build/esnext/types.js +0 -6
  61. package/build/esnext/types.js.map +0 -1
  62. package/build/esnext/utils.d.ts +0 -43
  63. package/build/esnext/utils.js +0 -205
  64. package/build/esnext/utils.js.map +0 -1
  65. package/build/esnext/version.d.ts +0 -2
  66. package/build/esnext/version.js +0 -7
  67. package/build/esnext/version.js.map +0 -1
  68. package/build/src/fetch.d.ts +0 -118
  69. package/build/src/fetch.js +0 -416
  70. package/build/src/fetch.js.map +0 -1
  71. package/build/src/index.d.ts +0 -3
  72. package/build/src/index.js +0 -10
  73. package/build/src/index.js.map +0 -1
  74. package/build/src/semconv.d.ts +0 -9
  75. package/build/src/semconv.js +0 -21
  76. package/build/src/semconv.js.map +0 -1
  77. package/build/src/types.d.ts +0 -27
  78. package/build/src/types.js +0 -7
  79. package/build/src/types.js.map +0 -1
  80. package/build/src/utils.d.ts +0 -43
  81. package/build/src/utils.js +0 -212
  82. package/build/src/utils.js.map +0 -1
  83. package/build/src/version.d.ts +0 -2
  84. package/build/src/version.js +0 -10
  85. package/build/src/version.js.map +0 -1
@@ -1,212 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.serverPortFromUrl = exports.normalizeHttpRequestMethod = exports.getXHRBodyLength = exports.getFetchBodyLength = void 0;
8
- // Much of the logic here overlaps with the same utils file in opentelemetry-instrumentation-xml-http-request
9
- // These may be unified in the future.
10
- const api_1 = require("@opentelemetry/api");
11
- const core_1 = require("@opentelemetry/core");
12
- const DIAG_LOGGER = api_1.diag.createComponentLogger({
13
- namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',
14
- });
15
- /**
16
- * Helper function to determine payload content length for fetch requests
17
- *
18
- * The fetch API is kinda messy: there are a couple of ways the body can be passed in.
19
- *
20
- * In all cases, the body param can be some variation of ReadableStream,
21
- * and ReadableStreams can only be read once! We want to avoid consuming the body here,
22
- * because that would mean that the body never gets sent with the actual fetch request.
23
- *
24
- * Either the first arg is a Request object, which can be cloned
25
- * so we can clone that object and read the body of the clone
26
- * without disturbing the original argument
27
- * However, reading the body here can only be done async; the body() method returns a promise
28
- * this means this entire function has to return a promise
29
- *
30
- * OR the first arg is a url/string
31
- * in which case the second arg has type RequestInit
32
- * RequestInit is NOT cloneable, but RequestInit.body is writable
33
- * so we can chain it into ReadableStream.pipeThrough()
34
- *
35
- * ReadableStream.pipeThrough() lets us process a stream and returns a new stream
36
- * So we can measure the body length as it passes through the pie, but need to attach
37
- * the new stream to the original request
38
- * so that the browser still has access to the body.
39
- *
40
- * @param body
41
- * @returns promise that resolves to the content length of the body
42
- */
43
- function getFetchBodyLength(...args) {
44
- if (args[0] instanceof URL || typeof args[0] === 'string') {
45
- const requestInit = args[1];
46
- if (!requestInit?.body) {
47
- return Promise.resolve();
48
- }
49
- if (requestInit.body instanceof ReadableStream) {
50
- const { body, length } = _getBodyNonDestructively(requestInit.body);
51
- requestInit.body = body;
52
- return length;
53
- }
54
- else {
55
- return Promise.resolve(getXHRBodyLength(requestInit.body));
56
- }
57
- }
58
- else {
59
- const info = args[0];
60
- if (!info?.body) {
61
- return Promise.resolve();
62
- }
63
- return info
64
- .clone()
65
- .text()
66
- .then(t => getByteLength(t));
67
- }
68
- }
69
- exports.getFetchBodyLength = getFetchBodyLength;
70
- function _getBodyNonDestructively(body) {
71
- // can't read a ReadableStream without destroying it
72
- // but we CAN pipe it through and return a new ReadableStream
73
- // some (older) platforms don't expose the pipeThrough method and in that scenario, we're out of luck;
74
- // there's no way to read the stream without consuming it.
75
- if (!body.pipeThrough) {
76
- DIAG_LOGGER.warn('Platform has ReadableStream but not pipeThrough!');
77
- return {
78
- body,
79
- length: Promise.resolve(undefined),
80
- };
81
- }
82
- let length = 0;
83
- let resolveLength;
84
- const lengthPromise = new Promise(resolve => {
85
- resolveLength = resolve;
86
- });
87
- const transform = new TransformStream({
88
- start() { },
89
- async transform(chunk, controller) {
90
- const bytearray = (await chunk);
91
- length += bytearray.byteLength;
92
- controller.enqueue(chunk);
93
- },
94
- flush() {
95
- resolveLength(length);
96
- },
97
- });
98
- return {
99
- body: body.pipeThrough(transform),
100
- length: lengthPromise,
101
- };
102
- }
103
- function isDocument(value) {
104
- return typeof Document !== 'undefined' && value instanceof Document;
105
- }
106
- /**
107
- * Helper function to determine payload content length for XHR requests
108
- * @param body
109
- * @returns content length
110
- */
111
- function getXHRBodyLength(body) {
112
- if (isDocument(body)) {
113
- return new XMLSerializer().serializeToString(document).length;
114
- }
115
- // XMLHttpRequestBodyInit expands to the following:
116
- if (typeof body === 'string') {
117
- return getByteLength(body);
118
- }
119
- if (body instanceof Blob) {
120
- return body.size;
121
- }
122
- if (body instanceof FormData) {
123
- return getFormDataSize(body);
124
- }
125
- if (body instanceof URLSearchParams) {
126
- return getByteLength(body.toString());
127
- }
128
- // ArrayBuffer | ArrayBufferView
129
- if (body.byteLength !== undefined) {
130
- return body.byteLength;
131
- }
132
- DIAG_LOGGER.warn('unknown body type');
133
- return undefined;
134
- }
135
- exports.getXHRBodyLength = getXHRBodyLength;
136
- const TEXT_ENCODER = new TextEncoder();
137
- function getByteLength(s) {
138
- return TEXT_ENCODER.encode(s).byteLength;
139
- }
140
- function getFormDataSize(formData) {
141
- let size = 0;
142
- for (const [key, value] of formData.entries()) {
143
- size += key.length;
144
- if (value instanceof Blob) {
145
- size += value.size;
146
- }
147
- else {
148
- size += value.length;
149
- }
150
- }
151
- return size;
152
- }
153
- /**
154
- * Normalize an HTTP request method string per `http.request.method` spec
155
- * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span
156
- */
157
- function normalizeHttpRequestMethod(method) {
158
- const knownMethods = getKnownMethods();
159
- const methUpper = method.toUpperCase();
160
- if (methUpper in knownMethods) {
161
- return methUpper;
162
- }
163
- else {
164
- return '_OTHER';
165
- }
166
- }
167
- exports.normalizeHttpRequestMethod = normalizeHttpRequestMethod;
168
- const DEFAULT_KNOWN_METHODS = {
169
- CONNECT: true,
170
- DELETE: true,
171
- GET: true,
172
- HEAD: true,
173
- OPTIONS: true,
174
- PATCH: true,
175
- POST: true,
176
- PUT: true,
177
- TRACE: true,
178
- // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/
179
- QUERY: true,
180
- };
181
- let knownMethods;
182
- function getKnownMethods() {
183
- if (knownMethods === undefined) {
184
- const cfgMethods = (0, core_1.getStringListFromEnv)('OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS');
185
- if (cfgMethods && cfgMethods.length > 0) {
186
- knownMethods = {};
187
- cfgMethods.forEach(m => {
188
- knownMethods[m] = true;
189
- });
190
- }
191
- else {
192
- knownMethods = DEFAULT_KNOWN_METHODS;
193
- }
194
- }
195
- return knownMethods;
196
- }
197
- const HTTP_PORT_FROM_PROTOCOL = {
198
- 'https:': '443',
199
- 'http:': '80',
200
- };
201
- function serverPortFromUrl(url) {
202
- const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]);
203
- // Guard with `if (serverPort)` because `Number('') === 0`.
204
- if (serverPort && !isNaN(serverPort)) {
205
- return serverPort;
206
- }
207
- else {
208
- return undefined;
209
- }
210
- }
211
- exports.serverPortFromUrl = serverPortFromUrl;
212
- //#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AARD,8CAQC","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-xml-http-request\n// These may be unified in the future.\n\nimport { diag } from '@opentelemetry/api';\nimport { getStringListFromEnv } from '@opentelemetry/core';\nimport type { URLLike } from '@opentelemetry/sdk-trace-web';\n\nconst DIAG_LOGGER = diag.createComponentLogger({\n namespace: '@opentelemetry/opentelemetry-instrumentation-fetch/utils',\n});\n\n/**\n * Helper function to determine payload content length for fetch requests\n *\n * The fetch API is kinda messy: there are a couple of ways the body can be passed in.\n *\n * In all cases, the body param can be some variation of ReadableStream,\n * and ReadableStreams can only be read once! We want to avoid consuming the body here,\n * because that would mean that the body never gets sent with the actual fetch request.\n *\n * Either the first arg is a Request object, which can be cloned\n * so we can clone that object and read the body of the clone\n * without disturbing the original argument\n * However, reading the body here can only be done async; the body() method returns a promise\n * this means this entire function has to return a promise\n *\n * OR the first arg is a url/string\n * in which case the second arg has type RequestInit\n * RequestInit is NOT cloneable, but RequestInit.body is writable\n * so we can chain it into ReadableStream.pipeThrough()\n *\n * ReadableStream.pipeThrough() lets us process a stream and returns a new stream\n * So we can measure the body length as it passes through the pie, but need to attach\n * the new stream to the original request\n * so that the browser still has access to the body.\n *\n * @param body\n * @returns promise that resolves to the content length of the body\n */\nexport function getFetchBodyLength(...args: Parameters<typeof fetch>) {\n if (args[0] instanceof URL || typeof args[0] === 'string') {\n const requestInit = args[1];\n if (!requestInit?.body) {\n return Promise.resolve();\n }\n if (requestInit.body instanceof ReadableStream) {\n const { body, length } = _getBodyNonDestructively(requestInit.body);\n requestInit.body = body;\n\n return length;\n } else {\n return Promise.resolve(getXHRBodyLength(requestInit.body));\n }\n } else {\n const info = args[0];\n if (!info?.body) {\n return Promise.resolve();\n }\n\n return info\n .clone()\n .text()\n .then(t => getByteLength(t));\n }\n}\n\nfunction _getBodyNonDestructively(body: ReadableStream) {\n // can't read a ReadableStream without destroying it\n // but we CAN pipe it through and return a new ReadableStream\n\n // some (older) platforms don't expose the pipeThrough method and in that scenario, we're out of luck;\n // there's no way to read the stream without consuming it.\n if (!body.pipeThrough) {\n DIAG_LOGGER.warn('Platform has ReadableStream but not pipeThrough!');\n return {\n body,\n length: Promise.resolve(undefined),\n };\n }\n\n let length = 0;\n let resolveLength: (l: number) => void;\n const lengthPromise = new Promise<number>(resolve => {\n resolveLength = resolve;\n });\n\n const transform = new TransformStream({\n start() {},\n async transform(chunk, controller) {\n const bytearray = (await chunk) as Uint8Array;\n length += bytearray.byteLength;\n\n controller.enqueue(chunk);\n },\n flush() {\n resolveLength(length);\n },\n });\n\n return {\n body: body.pipeThrough(transform),\n length: lengthPromise,\n };\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"]}
@@ -1,2 +0,0 @@
1
- export declare const VERSION = "0.222.0";
2
- //# sourceMappingURL=version.d.ts.map
@@ -1,10 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.VERSION = void 0;
8
- // this is autogenerated file, see scripts/version-update.js
9
- exports.VERSION = '0.222.0';
10
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,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';\n"]}