@opentelemetry/otlp-exporter-base 0.52.1 → 0.53.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/OTLPExporterBase.d.ts +3 -0
- package/build/esm/OTLPExporterBase.js.map +1 -1
- package/build/esm/export-response.d.ts +14 -0
- package/build/esm/export-response.js +17 -0
- package/build/esm/export-response.js.map +1 -0
- package/build/esm/exporter-transport.d.ts +6 -0
- package/build/esm/exporter-transport.js +17 -0
- package/build/esm/exporter-transport.js.map +1 -0
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/is-export-retryable.d.ts +3 -0
- package/build/esm/is-export-retryable.js +35 -0
- package/build/esm/is-export-retryable.js.map +1 -0
- package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js +36 -27
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/esm/platform/browser/index.d.ts +0 -1
- package/build/esm/platform/browser/index.js +0 -1
- package/build/esm/platform/browser/index.js.map +1 -1
- package/build/esm/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/esm/platform/browser/send-beacon-transport.js +47 -0
- package/build/esm/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/esm/platform/browser/xhr-transport.d.ts +11 -0
- package/build/esm/platform/browser/xhr-transport.js +101 -0
- package/build/esm/platform/browser/xhr-transport.js.map +1 -0
- package/build/esm/platform/index.d.ts +2 -2
- package/build/esm/platform/index.js +2 -2
- package/build/esm/platform/index.js.map +1 -1
- package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +5 -12
- package/build/esm/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/esm/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/esm/platform/node/http-exporter-transport.js +87 -0
- package/build/esm/platform/node/http-exporter-transport.js.map +1 -0
- package/build/esm/platform/node/http-transport-types.d.ts +12 -0
- package/build/esm/platform/node/http-transport-types.js +17 -0
- package/build/esm/platform/node/http-transport-types.js.map +1 -0
- package/build/esm/platform/node/http-transport-utils.d.ts +16 -0
- package/build/esm/platform/node/http-transport-utils.js +127 -0
- package/build/esm/platform/node/http-transport-utils.js.map +1 -0
- package/build/esm/platform/node/index.d.ts +0 -1
- package/build/esm/platform/node/index.js +0 -1
- package/build/esm/platform/node/index.js.map +1 -1
- package/build/esm/platform/node/util.d.ts +0 -16
- package/build/esm/platform/node/util.js +0 -164
- package/build/esm/platform/node/util.js.map +1 -1
- package/build/esm/retrying-transport.d.ts +8 -0
- package/build/esm/retrying-transport.js +119 -0
- package/build/esm/retrying-transport.js.map +1 -0
- 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/OTLPExporterBase.d.ts +3 -0
- package/build/esnext/OTLPExporterBase.js.map +1 -1
- package/build/esnext/export-response.d.ts +14 -0
- package/build/esnext/export-response.js +17 -0
- package/build/esnext/export-response.js.map +1 -0
- package/build/esnext/exporter-transport.d.ts +6 -0
- package/build/esnext/exporter-transport.js +17 -0
- package/build/esnext/exporter-transport.js.map +1 -0
- package/build/esnext/index.d.ts +2 -0
- package/build/esnext/index.js +3 -0
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/is-export-retryable.d.ts +3 -0
- package/build/esnext/is-export-retryable.js +35 -0
- package/build/esnext/is-export-retryable.js.map +1 -0
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +36 -16
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/esnext/platform/browser/index.d.ts +0 -1
- package/build/esnext/platform/browser/index.js +0 -1
- package/build/esnext/platform/browser/index.js.map +1 -1
- package/build/esnext/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/esnext/platform/browser/send-beacon-transport.js +45 -0
- package/build/esnext/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/esnext/platform/browser/xhr-transport.d.ts +11 -0
- package/build/esnext/platform/browser/xhr-transport.js +82 -0
- package/build/esnext/platform/browser/xhr-transport.js.map +1 -0
- package/build/esnext/platform/index.d.ts +2 -2
- package/build/esnext/platform/index.js +2 -2
- package/build/esnext/platform/index.js.map +1 -1
- package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +5 -12
- package/build/esnext/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/esnext/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/esnext/platform/node/http-exporter-transport.js +47 -0
- package/build/esnext/platform/node/http-exporter-transport.js.map +1 -0
- package/build/esnext/platform/node/http-transport-types.d.ts +12 -0
- package/build/esnext/platform/node/http-transport-types.js +17 -0
- package/build/esnext/platform/node/http-transport-types.js.map +1 -0
- package/build/esnext/platform/node/http-transport-utils.d.ts +16 -0
- package/build/esnext/platform/node/http-transport-utils.js +116 -0
- package/build/esnext/platform/node/http-transport-utils.js.map +1 -0
- package/build/esnext/platform/node/index.d.ts +0 -1
- package/build/esnext/platform/node/index.js +0 -1
- package/build/esnext/platform/node/index.js.map +1 -1
- package/build/esnext/platform/node/util.d.ts +0 -16
- package/build/esnext/platform/node/util.js +0 -151
- package/build/esnext/platform/node/util.js.map +1 -1
- package/build/esnext/retrying-transport.d.ts +8 -0
- package/build/esnext/retrying-transport.js +69 -0
- package/build/esnext/retrying-transport.js.map +1 -0
- 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/OTLPExporterBase.d.ts +3 -0
- package/build/src/OTLPExporterBase.js.map +1 -1
- package/build/src/export-response.d.ts +14 -0
- package/build/src/export-response.js +18 -0
- package/build/src/export-response.js.map +1 -0
- package/build/src/exporter-transport.d.ts +6 -0
- package/build/src/exporter-transport.js +18 -0
- package/build/src/exporter-transport.js.map +1 -0
- package/build/src/index.d.ts +2 -0
- package/build/src/index.js +15 -12
- package/build/src/index.js.map +1 -1
- package/build/src/is-export-retryable.d.ts +3 -0
- package/build/src/is-export-retryable.js +40 -0
- package/build/src/is-export-retryable.js.map +1 -0
- package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/src/platform/browser/OTLPExporterBrowserBase.js +36 -16
- package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/src/platform/browser/index.d.ts +0 -1
- package/build/src/platform/browser/index.js +1 -3
- package/build/src/platform/browser/index.js.map +1 -1
- package/build/src/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/src/platform/browser/send-beacon-transport.js +49 -0
- package/build/src/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/src/platform/browser/xhr-transport.d.ts +11 -0
- package/build/src/platform/browser/xhr-transport.js +86 -0
- package/build/src/platform/browser/xhr-transport.js.map +1 -0
- package/build/src/platform/index.d.ts +2 -2
- package/build/src/platform/index.js +1 -5
- package/build/src/platform/index.js.map +1 -1
- package/build/src/platform/node/OTLPExporterNodeBase.d.ts +5 -12
- package/build/src/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/src/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/src/platform/node/http-exporter-transport.js +51 -0
- package/build/src/platform/node/http-exporter-transport.js.map +1 -0
- package/build/src/platform/node/http-transport-types.d.ts +12 -0
- package/build/src/platform/node/http-transport-types.js +18 -0
- package/build/src/platform/node/http-transport-types.js.map +1 -0
- package/build/src/platform/node/http-transport-utils.d.ts +16 -0
- package/build/src/platform/node/http-transport-utils.js +121 -0
- package/build/src/platform/node/http-transport-utils.js.map +1 -0
- package/build/src/platform/node/index.d.ts +0 -1
- package/build/src/platform/node/index.js +1 -5
- package/build/src/platform/node/index.js.map +1 -1
- package/build/src/platform/node/util.d.ts +0 -16
- package/build/src/platform/node/util.js +2 -155
- package/build/src/platform/node/util.js.map +1 -1
- package/build/src/retrying-transport.d.ts +8 -0
- package/build/src/retrying-transport.js +73 -0
- package/build/src/retrying-transport.js.map +1 -0
- 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 +11 -12
- package/build/esm/platform/browser/util.d.ts +0 -21
- package/build/esm/platform/browser/util.js +0 -152
- package/build/esm/platform/browser/util.js.map +0 -1
- package/build/esnext/platform/browser/util.d.ts +0 -21
- package/build/esnext/platform/browser/util.js +0 -122
- package/build/esnext/platform/browser/util.js.map +0 -1
- package/build/src/platform/browser/util.d.ts +0 -21
- package/build/src/platform/browser/util.js +0 -127
- package/build/src/platform/browser/util.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|
1
|
+
{"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6DAA0D;AAE1D,iCAA8C;AAC9C,4CAA0C;AAC1C,8CAA2D;AAG3D,uEAAwE;AACxE,uCAAgD;AAChD,iEAAmE;AAEnE;;GAEG;AACH,MAAsB,oBAGpB,SAAQ,mCAAwD;IAIhE,YACE,SAAqC,EAAE,EACvC,UAAsD,EACtD,qBAA6C;;QAE7C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,UAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,+CAA+C;QAC/C,IAAI,CAAA,MAAM,aAAN,M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AAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;YAClD,OAAO;SACR;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU;aAC5B,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC;aAC9B,IAAI,CAAC,QAAQ,CAAC,EAAE;YACf,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE;gBACjC,SAAS,EAAE,CAAC;aACb;iBAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE;gBAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW,EAAE;gBAC1C,OAAO,CAAC,IAAI,yBAAiB,CAAC,qCAAqC,CAAC,CAAC,CAAC;aACvE;iBAAM;gBACL,OAAO,CAAC,IAAI,yBAAiB,CAAC,kCAAkC,CAAC,CAAC,CAAC;aACpE;QACH,CAAC,EAAE,OAAO,CAAC,CAAC;QAEd,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,KAAU,CAAC;CACtB;AA9FD,oDA8FC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterNodeConfigBase } from './types';\nimport { configureCompression } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { IExporterTransport } from '../../exporter-transport';\nimport { createHttpExporterTransport } from './http-exporter-transport';\nimport { OTLPExporterError } from '../../types';\nimport { createRetryingTransport } from '../../retrying-transport';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _transport: IExporterTransport;\n\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n signalSpecificHeaders: Record<string, string>\n ) {\n super(config);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((config as any).metadata) {\n diag.warn('Metadata cannot be set when using http');\n }\n this._serializer = serializer;\n\n // populate keepAlive for use with new settings\n if (config?.keepAlive != null) {\n if (config.httpAgentOptions != null) {\n if (config.httpAgentOptions.keepAlive == null) {\n // specific setting is not set, populate with non-specific setting.\n config.httpAgentOptions.keepAlive = config.keepAlive;\n }\n // do nothing, use specific setting otherwise\n } else {\n // populate specific option if AgentOptions does not exist.\n config.httpAgentOptions = {\n keepAlive: config.keepAlive,\n };\n }\n }\n const nonSignalSpecificHeaders = baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n );\n\n this._transport = createRetryingTransport({\n transport: createHttpExporterTransport({\n agentOptions: config.httpAgentOptions ?? { keepAlive: true },\n compression: configureCompression(config.compression),\n headers: Object.assign(\n {},\n nonSignalSpecificHeaders,\n signalSpecificHeaders\n ),\n url: this.url,\n }),\n });\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const data = this._serializer.serializeRequest(objects);\n\n if (data == null) {\n onError(new Error('Could not serialize message'));\n return;\n }\n\n const promise = this._transport\n .send(data, this.timeoutMillis)\n .then(response => {\n if (response.status === 'success') {\n onSuccess();\n } else if (response.status === 'failure' && response.error) {\n onError(response.error);\n } else if (response.status === 'retryable') {\n onError(new OTLPExporterError('Export failed with retryable status'));\n } else {\n onError(new OTLPExporterError('Export failed with unknown error'));\n }\n }, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n onShutdown(): void {}\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HttpRequestParameters } from './http-transport-types';
|
|
2
|
+
import { IExporterTransport } from '../../exporter-transport';
|
|
3
|
+
export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
|
|
4
|
+
//# sourceMappingURL=http-exporter-transport.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createHttpExporterTransport = void 0;
|
|
19
|
+
class HttpExporterTransport {
|
|
20
|
+
constructor(_parameters) {
|
|
21
|
+
this._parameters = _parameters;
|
|
22
|
+
this._send = null;
|
|
23
|
+
this._agent = null;
|
|
24
|
+
}
|
|
25
|
+
async send(data, timeoutMillis) {
|
|
26
|
+
if (this._send == null) {
|
|
27
|
+
// Lazy require to ensure that http/https is not required before instrumentations can wrap it.
|
|
28
|
+
const { sendWithHttp, createHttpAgent,
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
|
+
} = require('./http-transport-utils');
|
|
31
|
+
this._agent = createHttpAgent(this._parameters.url, this._parameters.agentOptions);
|
|
32
|
+
this._send = sendWithHttp;
|
|
33
|
+
}
|
|
34
|
+
return new Promise(resolve => {
|
|
35
|
+
var _a;
|
|
36
|
+
// this will always be defined
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
38
|
+
(_a = this._send) === null || _a === void 0 ? void 0 : _a.call(this, this._parameters, this._agent, data, result => {
|
|
39
|
+
resolve(result);
|
|
40
|
+
}, timeoutMillis);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
shutdown() {
|
|
44
|
+
// intentionally left empty, nothing to do.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function createHttpExporterTransport(parameters) {
|
|
48
|
+
return new HttpExporterTransport(parameters);
|
|
49
|
+
}
|
|
50
|
+
exports.createHttpExporterTransport = createHttpExporterTransport;
|
|
51
|
+
//# sourceMappingURL=http-exporter-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../../src/platform/node/http-exporter-transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAcH,MAAM,qBAAqB;IAIzB,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;QAH9C,UAAK,GAAwB,IAAI,CAAC;QAClC,WAAM,GAAoC,IAAI,CAAC;IAEE,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,8FAA8F;YAC9F,MAAM,EACJ,YAAY,EACZ,eAAe;YACf,8DAA8D;cAC/D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,GAAG,eAAe,CAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B,CAAC;YACF,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;SAC3B;QAED,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;;YAC3C,8BAA8B;YAC9B,oEAAoE;YACpE,MAAA,IAAI,CAAC,KAAK,+CAAV,IAAI,EACF,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAO,EACZ,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,SAAgB,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC;AAJD,kEAIC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../../export-response';\nimport { IExporterTransport } from '../../exporter-transport';\n\nclass HttpExporterTransport implements IExporterTransport {\n private _send: sendWithHttp | null = null;\n private _agent: http.Agent | https.Agent | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n if (this._send == null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n this._agent = createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n );\n this._send = sendWithHttp;\n }\n\n return new Promise<ExportResponse>(resolve => {\n // this will always be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._send?.(\n this._parameters,\n this._agent!,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type * as https from 'https';
|
|
4
|
+
import { ExportResponse } from '../../export-response';
|
|
5
|
+
export declare type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
|
|
6
|
+
export interface HttpRequestParameters {
|
|
7
|
+
url: string;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
compression: 'gzip' | 'none';
|
|
10
|
+
agentOptions: http.AgentOptions | https.AgentOptions;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=http-transport-types.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
//# sourceMappingURL=http-transport-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
import { HttpRequestParameters } from './http-transport-types';
|
|
5
|
+
import { ExportResponse } from '../../export-response';
|
|
6
|
+
/**
|
|
7
|
+
* Sends data using http
|
|
8
|
+
* @param params
|
|
9
|
+
* @param agent
|
|
10
|
+
* @param data
|
|
11
|
+
* @param onDone
|
|
12
|
+
* @param timeoutMillis
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
|
|
15
|
+
export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
|
|
16
|
+
//# sourceMappingURL=http-transport-utils.d.ts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHttpAgent = exports.sendWithHttp = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright The OpenTelemetry Authors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const http = require("http");
|
|
20
|
+
const https = require("https");
|
|
21
|
+
const zlib = require("zlib");
|
|
22
|
+
const stream_1 = require("stream");
|
|
23
|
+
const is_export_retryable_1 = require("../../is-export-retryable");
|
|
24
|
+
const types_1 = require("../../types");
|
|
25
|
+
/**
|
|
26
|
+
* Sends data using http
|
|
27
|
+
* @param params
|
|
28
|
+
* @param agent
|
|
29
|
+
* @param data
|
|
30
|
+
* @param onDone
|
|
31
|
+
* @param timeoutMillis
|
|
32
|
+
*/
|
|
33
|
+
function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
|
|
34
|
+
const parsedUrl = new URL(params.url);
|
|
35
|
+
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
36
|
+
const options = {
|
|
37
|
+
hostname: parsedUrl.hostname,
|
|
38
|
+
port: parsedUrl.port,
|
|
39
|
+
path: parsedUrl.pathname,
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: Object.assign({}, params.headers),
|
|
42
|
+
agent: agent,
|
|
43
|
+
};
|
|
44
|
+
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
45
|
+
const req = request(options, (res) => {
|
|
46
|
+
const responseData = [];
|
|
47
|
+
res.on('data', chunk => responseData.push(chunk));
|
|
48
|
+
res.on('end', () => {
|
|
49
|
+
if (res.statusCode && res.statusCode < 299) {
|
|
50
|
+
onDone({
|
|
51
|
+
status: 'success',
|
|
52
|
+
data: Buffer.concat(responseData),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (res.statusCode && (0, is_export_retryable_1.isExportRetryable)(res.statusCode)) {
|
|
56
|
+
onDone({
|
|
57
|
+
status: 'retryable',
|
|
58
|
+
retryInMillis: (0, is_export_retryable_1.parseRetryAfterToMills)(res.headers['retry-after']),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const error = new types_1.OTLPExporterError(res.statusMessage, res.statusCode);
|
|
63
|
+
onDone({
|
|
64
|
+
status: 'failure',
|
|
65
|
+
error,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
req.setTimeout(timeoutMillis, () => {
|
|
71
|
+
req.destroy();
|
|
72
|
+
onDone({
|
|
73
|
+
status: 'failure',
|
|
74
|
+
error: new Error('Request Timeout'),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
req.on('error', (error) => {
|
|
78
|
+
onDone({
|
|
79
|
+
status: 'failure',
|
|
80
|
+
error: error,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
|
|
84
|
+
req.on(reportTimeoutErrorEvent, () => {
|
|
85
|
+
onDone({
|
|
86
|
+
status: 'failure',
|
|
87
|
+
error: new Error('Request timed out'),
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
compressAndSend(req, params.compression, data, (error) => {
|
|
91
|
+
onDone({
|
|
92
|
+
status: 'failure',
|
|
93
|
+
error,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.sendWithHttp = sendWithHttp;
|
|
98
|
+
function compressAndSend(req, compression, data, onError) {
|
|
99
|
+
let dataStream = readableFromUint8Array(data);
|
|
100
|
+
if (compression === 'gzip') {
|
|
101
|
+
req.setHeader('Content-Encoding', 'gzip');
|
|
102
|
+
dataStream = dataStream
|
|
103
|
+
.on('error', onError)
|
|
104
|
+
.pipe(zlib.createGzip())
|
|
105
|
+
.on('error', onError);
|
|
106
|
+
}
|
|
107
|
+
dataStream.pipe(req);
|
|
108
|
+
}
|
|
109
|
+
function readableFromUint8Array(buff) {
|
|
110
|
+
const readable = new stream_1.Readable();
|
|
111
|
+
readable.push(buff);
|
|
112
|
+
readable.push(null);
|
|
113
|
+
return readable;
|
|
114
|
+
}
|
|
115
|
+
function createHttpAgent(rawUrl, agentOptions) {
|
|
116
|
+
const parsedUrl = new URL(rawUrl);
|
|
117
|
+
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
|
|
118
|
+
return new Agent(agentOptions);
|
|
119
|
+
}
|
|
120
|
+
exports.createHttpAgent = createHttpAgent;
|
|
121
|
+
//# sourceMappingURL=http-transport-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAAkC;AAGlC,mEAGmC;AACnC,uCAAgD;AAEhD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,MAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,MAA0C,EAC1C,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhE,MAAM,OAAO,GAA+C;QAC1D,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,QAAQ;QACxB,MAAM,EAAE,MAAM;QACd,OAAO,oBACF,MAAM,CAAC,OAAO,CAClB;QACD,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAE9E,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,E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ClB,CAAC;AAED,SAAgB,eAAe,CAC7B,MAAc,EACd,YAAoD;IAEpD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACxE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AAPD,0CAOC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../is-export-retryable';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Sends data using http\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\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 ...params.headers,\n },\n agent: agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\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 onDone({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (res.statusCode && isExportRetryable(res.statusCode)) {\n onDone({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(res.statusMessage, res.statusCode);\n onDone({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n onDone({\n status: 'failure',\n error: new Error('Request Timeout'),\n });\n });\n req.on('error', (error: Error | any) => {\n onDone({\n status: 'failure',\n error: error,\n });\n });\n\n const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';\n req.on(reportTimeoutErrorEvent, () => {\n onDone({\n status: 'failure',\n error: new Error('Request timed out'),\n });\n });\n\n compressAndSend(req, params.compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\nfunction 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);\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\nexport function createHttpAgent(\n rawUrl: string,\n agentOptions: http.AgentOptions | https.AgentOptions\n) {\n const parsedUrl = new URL(rawUrl);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent(agentOptions);\n}\n"]}
|
|
@@ -15,13 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CompressionAlgorithm = exports.
|
|
18
|
+
exports.CompressionAlgorithm = exports.OTLPExporterNodeBase = void 0;
|
|
19
19
|
var OTLPExporterNodeBase_1 = require("./OTLPExporterNodeBase");
|
|
20
20
|
Object.defineProperty(exports, "OTLPExporterNodeBase", { enumerable: true, get: function () { return OTLPExporterNodeBase_1.OTLPExporterNodeBase; } });
|
|
21
|
-
var util_1 = require("./util");
|
|
22
|
-
Object.defineProperty(exports, "sendWithHttp", { enumerable: true, get: function () { return util_1.sendWithHttp; } });
|
|
23
|
-
Object.defineProperty(exports, "createHttpAgent", { enumerable: true, get: function () { return util_1.createHttpAgent; } });
|
|
24
|
-
Object.defineProperty(exports, "configureCompression", { enumerable: true, get: function () { return util_1.configureCompression; } });
|
|
25
21
|
var types_1 = require("./types");
|
|
26
22
|
Object.defineProperty(exports, "CompressionAlgorithm", { enumerable: true, get: function () { return types_1.CompressionAlgorithm; } });
|
|
27
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,iCAA2E;AAAtC,6GAAA,oBAAoB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as http from 'http';
|
|
3
|
-
import * as https from 'https';
|
|
4
|
-
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
|
|
5
|
-
import { OTLPExporterNodeConfigBase } from '.';
|
|
6
1
|
import { CompressionAlgorithm } from './types';
|
|
7
|
-
import { OTLPExporterError } from '../../types';
|
|
8
|
-
/**
|
|
9
|
-
* Sends data using http
|
|
10
|
-
* @param collector
|
|
11
|
-
* @param data
|
|
12
|
-
* @param contentType
|
|
13
|
-
* @param onSuccess
|
|
14
|
-
* @param onError
|
|
15
|
-
*/
|
|
16
|
-
export declare function sendWithHttp<ExportItem, ServiceResponse>(collector: OTLPExporterNodeBase<ExportItem, ServiceResponse>, data: string | Uint8Array, contentType: string, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
17
|
-
export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
|
|
18
2
|
export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
|
|
19
3
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp = void 0;
|
|
4
2
|
/*
|
|
5
3
|
* Copyright The OpenTelemetry Authors
|
|
6
4
|
*
|
|
@@ -16,161 +14,10 @@ exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp =
|
|
|
16
14
|
* See the License for the specific language governing permissions and
|
|
17
15
|
* limitations under the License.
|
|
18
16
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const https = require("https");
|
|
22
|
-
const zlib = require("zlib");
|
|
23
|
-
const stream_1 = require("stream");
|
|
24
|
-
const api_1 = require("@opentelemetry/api");
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.configureCompression = void 0;
|
|
25
19
|
const types_1 = require("./types");
|
|
26
20
|
const core_1 = require("@opentelemetry/core");
|
|
27
|
-
const types_2 = require("../../types");
|
|
28
|
-
const util_1 = require("../../util");
|
|
29
|
-
/**
|
|
30
|
-
* Sends data using http
|
|
31
|
-
* @param collector
|
|
32
|
-
* @param data
|
|
33
|
-
* @param contentType
|
|
34
|
-
* @param onSuccess
|
|
35
|
-
* @param onError
|
|
36
|
-
*/
|
|
37
|
-
function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
38
|
-
const exporterTimeout = collector.timeoutMillis;
|
|
39
|
-
const parsedUrl = new url.URL(collector.url);
|
|
40
|
-
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
41
|
-
let retryTimer;
|
|
42
|
-
let req;
|
|
43
|
-
let reqIsDestroyed = false;
|
|
44
|
-
const exporterTimer = setTimeout(() => {
|
|
45
|
-
clearTimeout(retryTimer);
|
|
46
|
-
reqIsDestroyed = true;
|
|
47
|
-
if (req.destroyed) {
|
|
48
|
-
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
49
|
-
onError(err);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// req.abort() was deprecated since v14
|
|
53
|
-
nodeVersion >= 14 ? req.destroy() : req.abort();
|
|
54
|
-
}
|
|
55
|
-
}, exporterTimeout);
|
|
56
|
-
const options = {
|
|
57
|
-
hostname: parsedUrl.hostname,
|
|
58
|
-
port: parsedUrl.port,
|
|
59
|
-
path: parsedUrl.pathname,
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: Object.assign({ 'Content-Type': contentType }, collector.headers),
|
|
62
|
-
agent: collector.agent,
|
|
63
|
-
};
|
|
64
|
-
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
65
|
-
const sendWithRetry = (retries = util_1.DEFAULT_EXPORT_MAX_ATTEMPTS, minDelay = util_1.DEFAULT_EXPORT_INITIAL_BACKOFF) => {
|
|
66
|
-
req = request(options, (res) => {
|
|
67
|
-
let responseData = '';
|
|
68
|
-
res.on('data', chunk => (responseData += chunk));
|
|
69
|
-
res.on('aborted', () => {
|
|
70
|
-
if (reqIsDestroyed) {
|
|
71
|
-
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
72
|
-
onError(err);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
res.on('end', () => {
|
|
76
|
-
if (reqIsDestroyed === false) {
|
|
77
|
-
if (res.statusCode && res.statusCode < 299) {
|
|
78
|
-
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
79
|
-
onSuccess();
|
|
80
|
-
// clear all timers since request was completed and promise was resolved
|
|
81
|
-
clearTimeout(exporterTimer);
|
|
82
|
-
clearTimeout(retryTimer);
|
|
83
|
-
}
|
|
84
|
-
else if (res.statusCode &&
|
|
85
|
-
(0, util_1.isExportRetryable)(res.statusCode) &&
|
|
86
|
-
retries > 0) {
|
|
87
|
-
let retryTime;
|
|
88
|
-
minDelay = util_1.DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
|
|
89
|
-
// retry after interval specified in Retry-After header
|
|
90
|
-
if (res.headers['retry-after']) {
|
|
91
|
-
retryTime = (0, util_1.parseRetryAfterToMills)(res.headers['retry-after']);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// exponential backoff with jitter
|
|
95
|
-
retryTime = Math.round(Math.random() * (util_1.DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +
|
|
96
|
-
minDelay);
|
|
97
|
-
}
|
|
98
|
-
retryTimer = setTimeout(() => {
|
|
99
|
-
sendWithRetry(retries - 1, minDelay);
|
|
100
|
-
}, retryTime);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
104
|
-
onError(error);
|
|
105
|
-
// clear all timers since request was completed and promise was resolved
|
|
106
|
-
clearTimeout(exporterTimer);
|
|
107
|
-
clearTimeout(retryTimer);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
req.on('error', (error) => {
|
|
113
|
-
if (reqIsDestroyed) {
|
|
114
|
-
const err = new types_2.OTLPExporterError('Request Timeout', error.code);
|
|
115
|
-
onError(err);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
onError(error);
|
|
119
|
-
}
|
|
120
|
-
clearTimeout(exporterTimer);
|
|
121
|
-
clearTimeout(retryTimer);
|
|
122
|
-
});
|
|
123
|
-
req.on('abort', () => {
|
|
124
|
-
if (reqIsDestroyed) {
|
|
125
|
-
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
126
|
-
onError(err);
|
|
127
|
-
}
|
|
128
|
-
clearTimeout(exporterTimer);
|
|
129
|
-
clearTimeout(retryTimer);
|
|
130
|
-
});
|
|
131
|
-
switch (collector.compression) {
|
|
132
|
-
case types_1.CompressionAlgorithm.GZIP: {
|
|
133
|
-
req.setHeader('Content-Encoding', 'gzip');
|
|
134
|
-
const dataStream = readableFromUnit8Array(data);
|
|
135
|
-
dataStream
|
|
136
|
-
.on('error', onError)
|
|
137
|
-
.pipe(zlib.createGzip())
|
|
138
|
-
.on('error', onError)
|
|
139
|
-
.pipe(req);
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
default:
|
|
143
|
-
req.end(Buffer.from(data));
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
sendWithRetry();
|
|
148
|
-
}
|
|
149
|
-
exports.sendWithHttp = sendWithHttp;
|
|
150
|
-
function readableFromUnit8Array(buff) {
|
|
151
|
-
const readable = new stream_1.Readable();
|
|
152
|
-
readable.push(buff);
|
|
153
|
-
readable.push(null);
|
|
154
|
-
return readable;
|
|
155
|
-
}
|
|
156
|
-
function createHttpAgent(config) {
|
|
157
|
-
if (config.httpAgentOptions && config.keepAlive === false) {
|
|
158
|
-
api_1.diag.warn('httpAgentOptions is used only when keepAlive is true');
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
if (config.keepAlive === false || !config.url)
|
|
162
|
-
return undefined;
|
|
163
|
-
try {
|
|
164
|
-
const parsedUrl = new url.URL(config.url);
|
|
165
|
-
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
|
|
166
|
-
return new Agent(Object.assign({ keepAlive: true }, config.httpAgentOptions));
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
api_1.diag.error(`collector exporter failed to create http agent. err: ${err.message}`);
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.createHttpAgent = createHttpAgent;
|
|
174
21
|
function configureCompression(compression) {
|
|
175
22
|
if (compression) {
|
|
176
23
|
return compression;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,2BAA2B;AAC3B,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAAkC;AAGlC,4CAA0C;AAC1C,mCAA+C;AAC/C,8CAA6C;AAC7C,uCAAgD;AAChD,qCAOoB;AAEpB;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,SAA4D,EAC5D,IAAyB,EACzB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IAE3C,MAAM,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAChD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK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,UAAI,CAAC,KAAK,CACR,wDAAwD,GAAG,CAAC,OAAO,EAAE,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AApBD,0CAoBC;AAED,SAAgB,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,IAAA,aAAM,GAAE,CAAC,qCAAqC;YAC9C,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,4BAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,4BAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC;AAbD,oDAaC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as url from 'url';\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nimport { OTLPExporterNodeConfigBase } from '.';\nimport { diag } from '@opentelemetry/api';\nimport { CompressionAlgorithm } from './types';\nimport { getEnv } from '@opentelemetry/core';\nimport { OTLPExporterError } from '../../types';\nimport {\n DEFAULT_EXPORT_MAX_ATTEMPTS,\n DEFAULT_EXPORT_INITIAL_BACKOFF,\n DEFAULT_EXPORT_BACKOFF_MULTIPLIER,\n DEFAULT_EXPORT_MAX_BACKOFF,\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../util';\n\n/**\n * Sends data using http\n * @param collector\n * @param data\n * @param contentType\n * @param onSuccess\n * @param onError\n */\nexport function sendWithHttp<ExportItem, ServiceResponse>(\n collector: OTLPExporterNodeBase<ExportItem, ServiceResponse>,\n data: string | Uint8Array,\n contentType: string,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n const exporterTimeout = collector.timeoutMillis;\n const parsedUrl = new url.URL(collector.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n let retryTimer: ReturnType<typeof setTimeout>;\n let req: http.ClientRequest;\n let reqIsDestroyed = false;\n\n const exporterTimer = setTimeout(() => {\n clearTimeout(retryTimer);\n reqIsDestroyed = true;\n\n if (req.destroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n } else {\n // req.abort() was deprecated since v14\n nodeVersion >= 14 ? req.destroy() : req.abort();\n }\n }, exporterTimeout);\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 'Content-Type': contentType,\n ...collector.headers,\n },\n agent: collector.agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const sendWithRetry = (\n retries = DEFAULT_EXPORT_MAX_ATTEMPTS,\n minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF\n ) => {\n req = request(options, (res: http.IncomingMessage) => {\n let responseData = '';\n res.on('data', chunk => (responseData += chunk));\n\n res.on('aborted', () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n });\n\n res.on('end', () => {\n if (reqIsDestroyed === false) {\n if (res.statusCode && res.statusCode < 299) {\n diag.debug(`statusCode: ${res.statusCode}`, responseData);\n onSuccess();\n // clear all timers since request was completed and promise was resolved\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n } else if (\n res.statusCode &&\n isExportRetryable(res.statusCode) &&\n retries > 0\n ) {\n let retryTime: number;\n minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;\n\n // retry after interval specified in Retry-After header\n if (res.headers['retry-after']) {\n retryTime = parseRetryAfterToMills(res.headers['retry-after']!);\n } else {\n // exponential backoff with jitter\n retryTime = Math.round(\n Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +\n minDelay\n );\n }\n\n retryTimer = setTimeout(() => {\n sendWithRetry(retries - 1, minDelay);\n }, retryTime);\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n responseData\n );\n onError(error);\n // clear all timers since request was completed and promise was resolved\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n }\n }\n });\n });\n\n req.on('error', (error: Error | any) => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout', error.code);\n onError(err);\n } else {\n onError(error);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n });\n\n req.on('abort', () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n });\n\n switch (collector.compression) {\n case CompressionAlgorithm.GZIP: {\n req.setHeader('Content-Encoding', 'gzip');\n const dataStream = readableFromUnit8Array(data);\n dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError)\n .pipe(req);\n\n break;\n }\n default:\n req.end(Buffer.from(data));\n break;\n }\n };\n sendWithRetry();\n}\n\nfunction readableFromUnit8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n config: OTLPExporterNodeConfigBase\n): http.Agent | https.Agent | undefined {\n if (config.httpAgentOptions && config.keepAlive === false) {\n diag.warn('httpAgentOptions is used only when keepAlive is true');\n return undefined;\n }\n\n if (config.keepAlive === false || !config.url) return undefined;\n\n try {\n const parsedUrl = new url.URL(config.url as string);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent({ keepAlive: true, ...config.httpAgentOptions });\n } catch (err) {\n diag.error(\n `collector exporter failed to create http agent. err: ${err.message}`\n );\n return undefined;\n }\n}\n\nexport function configureCompression(\n compression: CompressionAlgorithm | undefined\n): CompressionAlgorithm {\n if (compression) {\n return compression;\n } else {\n const definedCompression =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||\n getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n return definedCompression === CompressionAlgorithm.GZIP\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,mCAA+C;AAC/C,8CAA6C;AAE7C,SAAgB,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,IAAA,aAAM,GAAE,CAAC,qCAAqC;YAC9C,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,4BAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,4BAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC;AAbD,oDAaC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CompressionAlgorithm } from './types';\nimport { getEnv } from '@opentelemetry/core';\n\nexport function configureCompression(\n compression: CompressionAlgorithm | undefined\n): CompressionAlgorithm {\n if (compression) {\n return compression;\n } else {\n const definedCompression =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||\n getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n return definedCompression === CompressionAlgorithm.GZIP\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE;\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IExporterTransport } from './exporter-transport';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an Exporter Transport that retries on 'retryable' response.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createRetryingTransport(options: {
|
|
6
|
+
transport: IExporterTransport;
|
|
7
|
+
}): IExporterTransport;
|
|
8
|
+
//# sourceMappingURL=retrying-transport.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createRetryingTransport = void 0;
|
|
19
|
+
const MAX_ATTEMPTS = 5;
|
|
20
|
+
const INITIAL_BACKOFF = 1000;
|
|
21
|
+
const MAX_BACKOFF = 5000;
|
|
22
|
+
const BACKOFF_MULTIPLIER = 1.5;
|
|
23
|
+
const JITTER = 0.2;
|
|
24
|
+
/**
|
|
25
|
+
* Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]
|
|
26
|
+
*/
|
|
27
|
+
function getJitter() {
|
|
28
|
+
return Math.random() * (2 * JITTER) - JITTER;
|
|
29
|
+
}
|
|
30
|
+
class RetryingTransport {
|
|
31
|
+
constructor(_transport) {
|
|
32
|
+
this._transport = _transport;
|
|
33
|
+
}
|
|
34
|
+
retry(data, timeoutMillis, inMillis) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
this._transport.send(data, timeoutMillis).then(resolve, reject);
|
|
38
|
+
}, inMillis);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async send(data, timeoutMillis) {
|
|
42
|
+
var _a;
|
|
43
|
+
const deadline = Date.now() + timeoutMillis;
|
|
44
|
+
let result = await this._transport.send(data, timeoutMillis);
|
|
45
|
+
let attempts = MAX_ATTEMPTS;
|
|
46
|
+
let nextBackoff = INITIAL_BACKOFF;
|
|
47
|
+
while (result.status === 'retryable' && attempts > 0) {
|
|
48
|
+
attempts--;
|
|
49
|
+
// use maximum of computed backoff and 0 to avoid negative timeouts
|
|
50
|
+
const backoff = Math.max(Math.min(nextBackoff, MAX_BACKOFF) + getJitter(), 0);
|
|
51
|
+
nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;
|
|
52
|
+
const retryInMillis = (_a = result.retryInMillis) !== null && _a !== void 0 ? _a : backoff;
|
|
53
|
+
// return when expected retry time is after the export deadline.
|
|
54
|
+
const remainingTimeoutMillis = deadline - Date.now();
|
|
55
|
+
if (retryInMillis > remainingTimeoutMillis) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
result = await this.retry(data, remainingTimeoutMillis, retryInMillis);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
shutdown() {
|
|
63
|
+
return this._transport.shutdown();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates an Exporter Transport that retries on 'retryable' response.
|
|
68
|
+
*/
|
|
69
|
+
function createRetryingTransport(options) {
|
|
70
|
+
return new RetryingTransport(options.transport);
|
|
71
|
+
}
|
|
72
|
+
exports.createRetryingTransport = createRetryingTransport;
|
|
73
|
+
//# sourceMappingURL=retrying-transport.js.map
|