@opentelemetry/otlp-exporter-base 0.214.0 → 0.216.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/build/esm/transport/http-transport-utils.d.ts +6 -0
- package/build/esm/transport/http-transport-utils.js +23 -1
- package/build/esm/transport/http-transport-utils.js.map +1 -1
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/transport/http-transport-utils.d.ts +6 -0
- package/build/esnext/transport/http-transport-utils.js +23 -1
- package/build/esnext/transport/http-transport-utils.js.map +1 -1
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/src/transport/http-transport-utils.d.ts +6 -0
- package/build/src/transport/http-transport-utils.js +24 -2
- package/build/src/transport/http-transport-utils.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +4 -4
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
import type * as http from 'http';
|
|
4
4
|
import type * as https from 'https';
|
|
5
5
|
import type { ExportResponse } from '../export-response';
|
|
6
|
+
/**
|
|
7
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
8
|
+
* If the server sends more data the connection is destroyed and the export
|
|
9
|
+
* is treated as a non-retryable error regardless of status code.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_RESPONSE_BODY_SIZE: number;
|
|
6
12
|
/**
|
|
7
13
|
* Sends data using http
|
|
8
14
|
* @param request
|
|
@@ -4,6 +4,12 @@ import { isExportHTTPErrorRetryable, parseRetryAfterToMills, } from '../is-expor
|
|
|
4
4
|
import { OTLPExporterError } from '../types';
|
|
5
5
|
import { VERSION } from '../version';
|
|
6
6
|
const DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;
|
|
7
|
+
/**
|
|
8
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
9
|
+
* If the server sends more data the connection is destroyed and the export
|
|
10
|
+
* is treated as a non-retryable error regardless of status code.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;
|
|
7
13
|
/**
|
|
8
14
|
* Sends data using http
|
|
9
15
|
* @param request
|
|
@@ -34,7 +40,23 @@ export function sendWithHttp(request, url, headers, compression, userAgent, agen
|
|
|
34
40
|
};
|
|
35
41
|
const req = request(options, (res) => {
|
|
36
42
|
const responseData = [];
|
|
37
|
-
|
|
43
|
+
let responseSize = 0;
|
|
44
|
+
res.on('data', (chunk) => {
|
|
45
|
+
responseSize += chunk.length;
|
|
46
|
+
if (responseSize > MAX_RESPONSE_BODY_SIZE) {
|
|
47
|
+
const sizeError = new Error(`OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`);
|
|
48
|
+
// Oversized responses are treated as non-retryable errors
|
|
49
|
+
// regardless of status code.
|
|
50
|
+
// Resolve before destroying: res.destroy() tears down the socket which
|
|
51
|
+
// triggers ECONNRESET on req.on('error'), so, resolving first makes that
|
|
52
|
+
// a no-op. res.on('error') does not fire because destroy() is called
|
|
53
|
+
// without an error argument.
|
|
54
|
+
resolve({ status: 'failure', error: sizeError });
|
|
55
|
+
res.destroy();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
responseData.push(chunk);
|
|
59
|
+
});
|
|
38
60
|
res.on('end', () => {
|
|
39
61
|
if (res.statusCode && res.statusCode <= 299) {
|
|
40
62
|
resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,wB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C,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,kBAAkB,GAAG,iCAAiC,OAAO,EAAE,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAmD,EACnD,GAAW,EACX,OAA+B,EAC/B,WAA4B,EAC5B,SAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,aAAqB;IAErB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CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Maximum response body size (4 MB) that the HTTP transport will read.\n * If the server sends more data the connection is destroyed and the export\n * is treated as a non-retryable error regardless of status code.\n */\nexport const MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n let responseSize = 0;\n res.on('data', (chunk: Buffer) => {\n responseSize += chunk.length;\n if (responseSize > MAX_RESPONSE_BODY_SIZE) {\n const sizeError = new Error(\n `OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`\n );\n // Oversized responses are treated as non-retryable errors\n // regardless of status code.\n // Resolve before destroying: res.destroy() tears down the socket which\n // triggers ECONNRESET on req.on('error'), so, resolving first makes that\n // a no-op. res.on('error') does not fire because destroy() is called\n // without an error argument.\n resolve({ status: 'failure', error: sizeError });\n res.destroy();\n return;\n }\n responseData.push(chunk);\n });\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
package/build/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.216.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esm/version.js
CHANGED
package/build/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,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.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,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.216.0';\n"]}
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
import type * as http from 'http';
|
|
4
4
|
import type * as https from 'https';
|
|
5
5
|
import type { ExportResponse } from '../export-response';
|
|
6
|
+
/**
|
|
7
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
8
|
+
* If the server sends more data the connection is destroyed and the export
|
|
9
|
+
* is treated as a non-retryable error regardless of status code.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_RESPONSE_BODY_SIZE: number;
|
|
6
12
|
/**
|
|
7
13
|
* Sends data using http
|
|
8
14
|
* @param request
|
|
@@ -4,6 +4,12 @@ import { isExportHTTPErrorRetryable, parseRetryAfterToMills, } from '../is-expor
|
|
|
4
4
|
import { OTLPExporterError } from '../types';
|
|
5
5
|
import { VERSION } from '../version';
|
|
6
6
|
const DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;
|
|
7
|
+
/**
|
|
8
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
9
|
+
* If the server sends more data the connection is destroyed and the export
|
|
10
|
+
* is treated as a non-retryable error regardless of status code.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;
|
|
7
13
|
/**
|
|
8
14
|
* Sends data using http
|
|
9
15
|
* @param request
|
|
@@ -34,7 +40,23 @@ export function sendWithHttp(request, url, headers, compression, userAgent, agen
|
|
|
34
40
|
};
|
|
35
41
|
const req = request(options, (res) => {
|
|
36
42
|
const responseData = [];
|
|
37
|
-
|
|
43
|
+
let responseSize = 0;
|
|
44
|
+
res.on('data', (chunk) => {
|
|
45
|
+
responseSize += chunk.length;
|
|
46
|
+
if (responseSize > MAX_RESPONSE_BODY_SIZE) {
|
|
47
|
+
const sizeError = new Error(`OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`);
|
|
48
|
+
// Oversized responses are treated as non-retryable errors
|
|
49
|
+
// regardless of status code.
|
|
50
|
+
// Resolve before destroying: res.destroy() tears down the socket which
|
|
51
|
+
// triggers ECONNRESET on req.on('error'), so, resolving first makes that
|
|
52
|
+
// a no-op. res.on('error') does not fire because destroy() is called
|
|
53
|
+
// without an error argument.
|
|
54
|
+
resolve({ status: 'failure', error: sizeError });
|
|
55
|
+
res.destroy();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
responseData.push(chunk);
|
|
59
|
+
});
|
|
38
60
|
res.on('end', () => {
|
|
39
61
|
if (res.statusCode && res.statusCode <= 299) {
|
|
40
62
|
resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAA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AAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,kBAAkB,GAAG,iCAAiC,OAAO,EAAE,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAmD,EACnD,GAAW,EACX,OAA+B,EAC/B,WAA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AAC,UAAU,EAAE,CAAC;aACvB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Maximum response body size (4 MB) that the HTTP transport will read.\n * If the server sends more data the connection is destroyed and the export\n * is treated as a non-retryable error regardless of status code.\n */\nexport const MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n let responseSize = 0;\n res.on('data', (chunk: Buffer) => {\n responseSize += chunk.length;\n if (responseSize > MAX_RESPONSE_BODY_SIZE) {\n const sizeError = new Error(\n `OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`\n );\n // Oversized responses are treated as non-retryable errors\n // regardless of status code.\n // Resolve before destroying: res.destroy() tears down the socket which\n // triggers ECONNRESET on req.on('error'), so, resolving first makes that\n // a no-op. res.on('error') does not fire because destroy() is called\n // without an error argument.\n resolve({ status: 'failure', error: sizeError });\n res.destroy();\n return;\n }\n responseData.push(chunk);\n });\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.216.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,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.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,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.216.0';\n"]}
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
import type * as http from 'http';
|
|
4
4
|
import type * as https from 'https';
|
|
5
5
|
import type { ExportResponse } from '../export-response';
|
|
6
|
+
/**
|
|
7
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
8
|
+
* If the server sends more data the connection is destroyed and the export
|
|
9
|
+
* is treated as a non-retryable error regardless of status code.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_RESPONSE_BODY_SIZE: number;
|
|
6
12
|
/**
|
|
7
13
|
* Sends data using http
|
|
8
14
|
* @param request
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compressAndSend = exports.sendWithHttp = void 0;
|
|
3
|
+
exports.compressAndSend = exports.sendWithHttp = exports.MAX_RESPONSE_BODY_SIZE = void 0;
|
|
4
4
|
const zlib = require("zlib");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
6
|
const is_export_retryable_1 = require("../is-export-retryable");
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const version_1 = require("../version");
|
|
9
9
|
const DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${version_1.VERSION}`;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum response body size (4 MB) that the HTTP transport will read.
|
|
12
|
+
* If the server sends more data the connection is destroyed and the export
|
|
13
|
+
* is treated as a non-retryable error regardless of status code.
|
|
14
|
+
*/
|
|
15
|
+
exports.MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;
|
|
10
16
|
/**
|
|
11
17
|
* Sends data using http
|
|
12
18
|
* @param request
|
|
@@ -37,7 +43,23 @@ function sendWithHttp(request, url, headers, compression, userAgent, agent, data
|
|
|
37
43
|
};
|
|
38
44
|
const req = request(options, (res) => {
|
|
39
45
|
const responseData = [];
|
|
40
|
-
|
|
46
|
+
let responseSize = 0;
|
|
47
|
+
res.on('data', (chunk) => {
|
|
48
|
+
responseSize += chunk.length;
|
|
49
|
+
if (responseSize > exports.MAX_RESPONSE_BODY_SIZE) {
|
|
50
|
+
const sizeError = new Error(`OTLP export response body exceeded size limit of ${exports.MAX_RESPONSE_BODY_SIZE} bytes`);
|
|
51
|
+
// Oversized responses are treated as non-retryable errors
|
|
52
|
+
// regardless of status code.
|
|
53
|
+
// Resolve before destroying: res.destroy() tears down the socket which
|
|
54
|
+
// triggers ECONNRESET on req.on('error'), so, resolving first makes that
|
|
55
|
+
// a no-op. res.on('error') does not fire because destroy() is called
|
|
56
|
+
// without an error argument.
|
|
57
|
+
resolve({ status: 'failure', error: sizeError });
|
|
58
|
+
res.destroy();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
responseData.push(chunk);
|
|
62
|
+
});
|
|
41
63
|
res.on('end', () => {
|
|
42
64
|
if (res.statusCode && res.statusCode <= 299) {
|
|
43
65
|
resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":";;;AAMA,6BAA6B;AAC7B,mCAAkC;AAElC,gEAGgC;AAChC,oCAA6C;AAC7C,wCAAqC;AAErC,MAAM,kBAAkB,GAAG,iCAAiC,iBAAO,EAAE,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAC1B,OAAmD,EACnD,GAAW,EACX,OAA+B,EAC/B,WAA4B,EAC5B,SAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,aAAqB;IAErB,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;QAC3C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAE/B,IAAI,SAAS,EAAE;YACb,OAAO,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,IAAI,kBAAkB,EAAE,CAAC;SAC9D;aAAM;YACL,OAAO,CAAC,YAAY,CAAC,GAAG,kBAAkB,CAAC;SAC5C;QAED,MAAM,OAAO,GAA+C;YAC1D,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,IAAI,EAAE,SAAS,CAAC,QAAQ;YACxB,MAAM,EAAE,MAAM;YACd,OAAO;YACP,KAAK;SACN,CAAC;QAEF,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,GAAyB,EAAE,EAAE;YACzD,MAAM,YAAY,GAAa,EAAE,CAAC;YAClC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAElD,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACjB,IAAI,GAAG,CAAC,UAAU,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,OAAO,EAAE,OAAO,CAAC,CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAjBD,0CAiBC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":";;;AAMA,6BAA6B;AAC7B,mCAAkC;AAElC,gEAGgC;AAChC,oCAA6C;AAC7C,wCAAqC;AAErC,MAAM,kBAAkB,GAAG,iCAAiC,iBAAO,EAAE,CAAC;AAEtE;;;;GAIG;AACU,QAAA,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAC1B,OAAmD,EACnD,GAAW,EACX,OAA+B,EAC/B,WAA4B,EAC5B,SAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,aAAqB;IAErB,OAAO,IAAI,OAAO,C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OAAO,CAAC,CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAjBD,0CAiBC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oCAAoC,CAAC,KAAY;IACxD,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;QAC5C,YAAY;QACZ,cAAc;QACd,OAAO;QACP,WAAW;QACX,WAAW;QACX,WAAW;QACX,aAAa;QACb,cAAc;KACf,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QACrD,OAAO,6BAA6B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACtD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport type { ExportResponse } from '../export-response';\nimport {\n isExportHTTPErrorRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Maximum response body size (4 MB) that the HTTP transport will read.\n * If the server sends more data the connection is destroyed and the export\n * is treated as a non-retryable error regardless of status code.\n */\nexport const MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;\n\n/**\n * Sends data using http\n * @param request\n * @param url\n * @param headers\n * @param compression\n * @param userAgent\n * @param agent\n * @param data\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n timeoutMillis: number\n): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n let responseSize = 0;\n res.on('data', (chunk: Buffer) => {\n responseSize += chunk.length;\n if (responseSize > MAX_RESPONSE_BODY_SIZE) {\n const sizeError = new Error(\n `OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`\n );\n // Oversized responses are treated as non-retryable errors\n // regardless of status code.\n // Resolve before destroying: res.destroy() tears down the socket which\n // triggers ECONNRESET on req.on('error'), so, resolving first makes that\n // a no-op. res.on('error') does not fire because destroy() is called\n // without an error argument.\n resolve({ status: 'failure', error: sizeError });\n res.destroy();\n return;\n }\n responseData.push(chunk);\n });\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode <= 299) {\n resolve({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n res.on('error', (error: Error) => {\n // Note: 'end' may still be emitted after 'error' on the same response object, since we're resolving a promise,\n // the first call to resolve() will determine the final state.\n if (res.statusCode && res.statusCode <= 299) {\n // If the response is successful but an error occurs while reading the response,\n // we consider it a success since the data has been sent successfully.\n resolve({\n status: 'success',\n });\n } else if (\n res.statusCode &&\n isExportHTTPErrorRetryable(res.statusCode)\n ) {\n resolve({\n status: 'retryable',\n error: error,\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n resolve({\n status: 'retryable',\n error: new Error('Request timed out'),\n });\n });\n\n req.on('error', (error: Error) => {\n if (isHttpTransportNetworkErrorRetryable(error)) {\n resolve({\n status: 'retryable',\n error,\n });\n } else {\n resolve({\n status: 'failure',\n error,\n });\n }\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n resolve({\n status: 'failure',\n error,\n });\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nfunction isHttpTransportNetworkErrorRetryable(error: Error): boolean {\n const RETRYABLE_NETWORK_ERROR_CODES = new Set([\n 'ECONNRESET',\n 'ECONNREFUSED',\n 'EPIPE',\n 'ETIMEDOUT',\n 'EAI_AGAIN',\n 'ENOTFOUND',\n 'ENETUNREACH',\n 'EHOSTUNREACH',\n ]);\n\n if ('code' in error && typeof error.code === 'string') {\n return RETRYABLE_NETWORK_ERROR_CODES.has(error.code);\n }\n\n return false;\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.216.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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.
|
|
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.216.0';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/otlp-exporter-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.216.0",
|
|
4
4
|
"description": "OpenTelemetry OTLP Exporter base (for internal use only)",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@opentelemetry/core": "2.
|
|
78
|
-
"@opentelemetry/otlp-transformer": "0.
|
|
77
|
+
"@opentelemetry/core": "2.7.1",
|
|
78
|
+
"@opentelemetry/otlp-transformer": "0.216.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@babel/core": "7.27.1",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
},
|
|
105
105
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-exporter-base",
|
|
106
106
|
"sideEffects": false,
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "2400d8389a4469f7a81ccd3be2f0b2c2dd6faaf7"
|
|
108
108
|
}
|