@opentelemetry/otlp-exporter-base 0.202.0 → 0.204.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/bounded-queue-export-promise-handler.js +1 -1
- package/build/esm/bounded-queue-export-promise-handler.js.map +1 -1
- package/build/esm/configuration/convert-legacy-node-http-options.js +14 -18
- package/build/esm/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/esm/configuration/create-legacy-browser-delegate.d.ts +2 -0
- package/build/esm/configuration/create-legacy-browser-delegate.js +11 -5
- package/build/esm/configuration/create-legacy-browser-delegate.js.map +1 -1
- package/build/esm/configuration/legacy-node-configuration.d.ts +25 -2
- package/build/esm/configuration/legacy-node-configuration.js.map +1 -1
- package/build/esm/configuration/otlp-http-configuration.d.ts +13 -1
- package/build/esm/configuration/otlp-http-configuration.js +15 -7
- package/build/esm/configuration/otlp-http-configuration.js.map +1 -1
- package/build/esm/configuration/otlp-http-env-configuration.js +7 -7
- package/build/esm/configuration/otlp-http-env-configuration.js.map +1 -1
- package/build/esm/index-node-http.d.ts +1 -0
- package/build/esm/index-node-http.js +1 -0
- package/build/esm/index-node-http.js.map +1 -1
- package/build/esm/otlp-browser-http-export-delegate.d.ts +4 -0
- package/build/esm/otlp-browser-http-export-delegate.js +9 -0
- package/build/esm/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/esm/transport/fetch-transport.d.ts +11 -0
- package/build/esm/transport/fetch-transport.js +82 -0
- package/build/esm/transport/fetch-transport.js.map +1 -0
- package/build/esm/transport/http-exporter-transport.js +15 -11
- package/build/esm/transport/http-exporter-transport.js.map +1 -1
- package/build/esm/transport/http-transport-types.d.ts +2 -7
- package/build/esm/transport/http-transport-types.js.map +1 -1
- package/build/esm/transport/http-transport-utils.d.ts +4 -4
- package/build/esm/transport/http-transport-utils.js +2 -32
- package/build/esm/transport/http-transport-utils.js.map +1 -1
- package/build/esm/transport/xhr-transport.d.ts +6 -0
- package/build/esm/transport/xhr-transport.js +2 -0
- package/build/esm/transport/xhr-transport.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/bounded-queue-export-promise-handler.js +1 -1
- package/build/esnext/bounded-queue-export-promise-handler.js.map +1 -1
- package/build/esnext/configuration/convert-legacy-node-http-options.js +14 -18
- package/build/esnext/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/esnext/configuration/create-legacy-browser-delegate.d.ts +2 -0
- package/build/esnext/configuration/create-legacy-browser-delegate.js +11 -5
- package/build/esnext/configuration/create-legacy-browser-delegate.js.map +1 -1
- package/build/esnext/configuration/legacy-node-configuration.d.ts +25 -2
- package/build/esnext/configuration/legacy-node-configuration.js.map +1 -1
- package/build/esnext/configuration/otlp-http-configuration.d.ts +13 -1
- package/build/esnext/configuration/otlp-http-configuration.js +15 -7
- package/build/esnext/configuration/otlp-http-configuration.js.map +1 -1
- package/build/esnext/configuration/otlp-http-env-configuration.js +7 -7
- package/build/esnext/configuration/otlp-http-env-configuration.js.map +1 -1
- package/build/esnext/index-node-http.d.ts +1 -0
- package/build/esnext/index-node-http.js +1 -0
- package/build/esnext/index-node-http.js.map +1 -1
- package/build/esnext/otlp-browser-http-export-delegate.d.ts +4 -0
- package/build/esnext/otlp-browser-http-export-delegate.js +9 -0
- package/build/esnext/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/esnext/transport/fetch-transport.d.ts +11 -0
- package/build/esnext/transport/fetch-transport.js +82 -0
- package/build/esnext/transport/fetch-transport.js.map +1 -0
- package/build/esnext/transport/http-exporter-transport.js +15 -11
- package/build/esnext/transport/http-exporter-transport.js.map +1 -1
- package/build/esnext/transport/http-transport-types.d.ts +2 -7
- package/build/esnext/transport/http-transport-types.js.map +1 -1
- package/build/esnext/transport/http-transport-utils.d.ts +4 -4
- package/build/esnext/transport/http-transport-utils.js +2 -32
- package/build/esnext/transport/http-transport-utils.js.map +1 -1
- package/build/esnext/transport/xhr-transport.d.ts +6 -0
- package/build/esnext/transport/xhr-transport.js +2 -0
- package/build/esnext/transport/xhr-transport.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/bounded-queue-export-promise-handler.js +1 -1
- package/build/src/bounded-queue-export-promise-handler.js.map +1 -1
- package/build/src/configuration/convert-legacy-node-http-options.js +13 -17
- package/build/src/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/src/configuration/create-legacy-browser-delegate.d.ts +2 -0
- package/build/src/configuration/create-legacy-browser-delegate.js +13 -6
- package/build/src/configuration/create-legacy-browser-delegate.js.map +1 -1
- package/build/src/configuration/legacy-node-configuration.d.ts +25 -2
- package/build/src/configuration/legacy-node-configuration.js.map +1 -1
- package/build/src/configuration/otlp-http-configuration.d.ts +13 -1
- package/build/src/configuration/otlp-http-configuration.js +17 -8
- package/build/src/configuration/otlp-http-configuration.js.map +1 -1
- package/build/src/configuration/otlp-http-env-configuration.js +6 -6
- package/build/src/configuration/otlp-http-env-configuration.js.map +1 -1
- package/build/src/index-node-http.d.ts +1 -0
- package/build/src/index-node-http.js +3 -1
- package/build/src/index-node-http.js.map +1 -1
- package/build/src/otlp-browser-http-export-delegate.d.ts +4 -0
- package/build/src/otlp-browser-http-export-delegate.js +11 -1
- package/build/src/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/src/transport/fetch-transport.d.ts +11 -0
- package/build/src/transport/fetch-transport.js +86 -0
- package/build/src/transport/fetch-transport.js.map +1 -0
- package/build/src/transport/http-exporter-transport.js +15 -11
- package/build/src/transport/http-exporter-transport.js.map +1 -1
- package/build/src/transport/http-transport-types.d.ts +2 -7
- package/build/src/transport/http-transport-types.js.map +1 -1
- package/build/src/transport/http-transport-utils.d.ts +4 -4
- package/build/src/transport/http-transport-utils.js +3 -34
- package/build/src/transport/http-transport-utils.js.map +1 -1
- package/build/src/transport/xhr-transport.d.ts +6 -0
- package/build/src/transport/xhr-transport.js +2 -0
- package/build/src/transport/xhr-transport.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 +12 -13
|
@@ -32,7 +32,7 @@ class BoundedQueueExportPromiseHandler {
|
|
|
32
32
|
this._sendingPromises.push(promise);
|
|
33
33
|
const popPromise = () => {
|
|
34
34
|
const index = this._sendingPromises.indexOf(promise);
|
|
35
|
-
this._sendingPromises.splice(index, 1);
|
|
35
|
+
void this._sendingPromises.splice(index, 1);
|
|
36
36
|
};
|
|
37
37
|
promise.then(popPromise, popPromise);
|
|
38
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-queue-export-promise-handler.js","sourceRoot":"","sources":["../../src/bounded-queue-export-promise-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAQH,MAAM,gCAAgC;IACnB,iBAAiB,CAAS;IACnC,gBAAgB,GAAuB,EAAE,CAAC;IAElD;;OAEG;IACH,YAAY,gBAAwB;QAClC,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAC5C,CAAC;IAEM,WAAW,CAAC,OAAsB;QACvC,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;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;
|
|
1
|
+
{"version":3,"file":"bounded-queue-export-promise-handler.js","sourceRoot":"","sources":["../../src/bounded-queue-export-promise-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAQH,MAAM,gCAAgC;IACnB,iBAAiB,CAAS;IACnC,gBAAgB,GAAuB,EAAE,CAAC;IAElD;;OAEG;IACH,YAAY,gBAAwB;QAClC,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAC5C,CAAC;IAEM,WAAW,CAAC,OAAsB;QACvC,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;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,KAAK,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9C,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAEM,eAAe;QACpB,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,IAAI,CAAC,iBAAiB,CAAC;IAChE,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,sCAAsC,CAAC,OAEtD;IACC,OAAO,IAAI,gCAAgC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxE,CAAC;AAJD,wFAIC","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 interface IExportPromiseHandler {\n pushPromise(promise: Promise<void>): void;\n hasReachedLimit(): boolean;\n awaitAll(): Promise<void>;\n}\n\nclass BoundedQueueExportPromiseHandler implements IExportPromiseHandler {\n private readonly _concurrencyLimit: number;\n private _sendingPromises: Promise<unknown>[] = [];\n\n /**\n * @param concurrencyLimit maximum promises allowed in a queue at the same time.\n */\n constructor(concurrencyLimit: number) {\n this._concurrencyLimit = concurrencyLimit;\n }\n\n public pushPromise(promise: Promise<void>): void {\n if (this.hasReachedLimit()) {\n throw new Error('Concurrency Limit reached');\n }\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n void this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n public hasReachedLimit(): boolean {\n return this._sendingPromises.length >= this._concurrencyLimit;\n }\n\n public async awaitAll(): Promise<void> {\n await Promise.all(this._sendingPromises);\n }\n}\n\n/**\n * Promise queue for keeping track of export promises. Finished promises will be auto-dequeued.\n * Allows for awaiting all promises in the queue.\n */\nexport function createBoundedQueueExportPromiseHandler(options: {\n concurrencyLimit: number;\n}): IExportPromiseHandler {\n return new BoundedQueueExportPromiseHandler(options.concurrencyLimit);\n}\n"]}
|
|
@@ -6,23 +6,19 @@ const otlp_http_env_configuration_1 = require("./otlp-http-env-configuration");
|
|
|
6
6
|
const api_1 = require("@opentelemetry/api");
|
|
7
7
|
const shared_configuration_1 = require("./shared-configuration");
|
|
8
8
|
function convertLegacyAgentOptions(config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
keepAlive: config.keepAlive,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
9
|
+
if (typeof config.httpAgentOptions === 'function') {
|
|
10
|
+
return config.httpAgentOptions;
|
|
11
|
+
}
|
|
12
|
+
let legacy = config.httpAgentOptions;
|
|
13
|
+
if (config.keepAlive != null) {
|
|
14
|
+
legacy = { keepAlive: config.keepAlive, ...legacy };
|
|
15
|
+
}
|
|
16
|
+
if (legacy != null) {
|
|
17
|
+
return (0, otlp_http_configuration_1.httpAgentFactoryFromOptions)(legacy);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return undefined;
|
|
24
21
|
}
|
|
25
|
-
return config.httpAgentOptions;
|
|
26
22
|
}
|
|
27
23
|
/**
|
|
28
24
|
* @deprecated this will be removed in 2.0
|
|
@@ -42,7 +38,7 @@ function convertLegacyHttpOptions(config, signalIdentifier, signalResourcePath,
|
|
|
42
38
|
concurrencyLimit: config.concurrencyLimit,
|
|
43
39
|
timeoutMillis: config.timeoutMillis,
|
|
44
40
|
compression: config.compression,
|
|
45
|
-
|
|
41
|
+
agentFactory: convertLegacyAgentOptions(config),
|
|
46
42
|
}, (0, otlp_http_env_configuration_1.getHttpConfigurationFromEnvironment)(signalIdentifier, signalResourcePath), (0, otlp_http_configuration_1.getHttpConfigurationDefaults)(requiredHeaders, signalResourcePath));
|
|
47
43
|
}
|
|
48
44
|
exports.convertLegacyHttpOptions = convertLegacyHttpOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-legacy-node-http-options.js","sourceRoot":"","sources":["../../../src/configuration/convert-legacy-node-http-options.ts"],"names":[],"mappings":";;;AAgBA,
|
|
1
|
+
{"version":3,"file":"convert-legacy-node-http-options.js","sourceRoot":"","sources":["../../../src/configuration/convert-legacy-node-http-options.ts"],"names":[],"mappings":";;;AAgBA,uEAMmC;AACnC,+EAAoF;AACpF,4CAA0C;AAC1C,iEAAqE;AAErE,SAAS,yBAAyB,CAChC,MAAkC;IAElC,IAAI,OAAO,MAAM,CAAC,gBAAgB,KAAK,UAAU,EAAE;QACjD,OAAO,MAAM,CAAC,gBAAgB,CAAC;KAChC;IAED,IAAI,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC;IACrC,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE;QAC5B,MAAM,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,MAAM,EAAE,CAAC;KACrD;IAED,IAAI,MAAM,IAAI,IAAI,EAAE;QAClB,OAAO,IAAA,qDAA2B,EAAC,MAAM,CAAC,CAAC;KAC5C;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,MAAkC,EAClC,gBAAwB,EACxB,kBAA0B,EAC1B,eAAuC;IAEvC,8DAA8D;IAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;QAC5B,UAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;KACrD;IAED,OAAO,IAAA,gEAAsC,EAC3C;QACE,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,OAAO,EAAE,IAAA,kDAA2B,EAAC,MAAM,CAAC,OAAO,CAAC;QACpD,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,yBAAyB,CAAC,MAAM,CAAC;KAChD,EACD,IAAA,iEAAmC,EAAC,gBAAgB,EAAE,kBAAkB,CAAC,EACzE,IAAA,sDAA4B,EAAC,eAAe,EAAE,kBAAkB,CAAC,CAClE,CAAC;AACJ,CAAC;AAvBD,4DAuBC","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 { OTLPExporterNodeConfigBase } from './legacy-node-configuration';\nimport {\n getHttpConfigurationDefaults,\n HttpAgentFactory,\n httpAgentFactoryFromOptions,\n mergeOtlpHttpConfigurationWithDefaults,\n OtlpHttpConfiguration,\n} from './otlp-http-configuration';\nimport { getHttpConfigurationFromEnvironment } from './otlp-http-env-configuration';\nimport { diag } from '@opentelemetry/api';\nimport { wrapStaticHeadersInFunction } from './shared-configuration';\n\nfunction convertLegacyAgentOptions(\n config: OTLPExporterNodeConfigBase\n): HttpAgentFactory | undefined {\n if (typeof config.httpAgentOptions === 'function') {\n return config.httpAgentOptions;\n }\n\n let legacy = config.httpAgentOptions;\n if (config.keepAlive != null) {\n legacy = { keepAlive: config.keepAlive, ...legacy };\n }\n\n if (legacy != null) {\n return httpAgentFactoryFromOptions(legacy);\n } else {\n return undefined;\n }\n}\n\n/**\n * @deprecated this will be removed in 2.0\n * @param config\n * @param signalIdentifier\n * @param signalResourcePath\n * @param requiredHeaders\n */\nexport function convertLegacyHttpOptions(\n config: OTLPExporterNodeConfigBase,\n signalIdentifier: string,\n signalResourcePath: string,\n requiredHeaders: Record<string, string>\n): OtlpHttpConfiguration {\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\n return mergeOtlpHttpConfigurationWithDefaults(\n {\n url: config.url,\n headers: wrapStaticHeadersInFunction(config.headers),\n concurrencyLimit: config.concurrencyLimit,\n timeoutMillis: config.timeoutMillis,\n compression: config.compression,\n agentFactory: convertLegacyAgentOptions(config),\n },\n getHttpConfigurationFromEnvironment(signalIdentifier, signalResourcePath),\n getHttpConfigurationDefaults(requiredHeaders, signalResourcePath)\n );\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ISerializer } from '@opentelemetry/otlp-transformer';
|
|
2
|
+
import { createOtlpSendBeaconExportDelegate } from '../otlp-browser-http-export-delegate';
|
|
2
3
|
import { IOtlpExportDelegate } from '../otlp-export-delegate';
|
|
3
4
|
import { OTLPExporterConfigBase } from './legacy-base-configuration';
|
|
4
5
|
/**
|
|
@@ -9,4 +10,5 @@ import { OTLPExporterConfigBase } from './legacy-base-configuration';
|
|
|
9
10
|
* @param requiredHeaders
|
|
10
11
|
*/
|
|
11
12
|
export declare function createLegacyOtlpBrowserExportDelegate<Internal, Response>(config: OTLPExporterConfigBase, serializer: ISerializer<Internal, Response>, signalResourcePath: string, requiredHeaders: Record<string, string>): IOtlpExportDelegate<Internal>;
|
|
13
|
+
export declare function inferExportDelegateToUse(configHeaders: OTLPExporterConfigBase['headers']): typeof createOtlpSendBeaconExportDelegate;
|
|
12
14
|
//# sourceMappingURL=create-legacy-browser-delegate.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLegacyOtlpBrowserExportDelegate = void 0;
|
|
3
|
+
exports.inferExportDelegateToUse = exports.createLegacyOtlpBrowserExportDelegate = void 0;
|
|
4
4
|
const otlp_browser_http_export_delegate_1 = require("../otlp-browser-http-export-delegate");
|
|
5
5
|
const convert_legacy_browser_http_options_1 = require("./convert-legacy-browser-http-options");
|
|
6
6
|
/**
|
|
@@ -11,14 +11,21 @@ const convert_legacy_browser_http_options_1 = require("./convert-legacy-browser-
|
|
|
11
11
|
* @param requiredHeaders
|
|
12
12
|
*/
|
|
13
13
|
function createLegacyOtlpBrowserExportDelegate(config, serializer, signalResourcePath, requiredHeaders) {
|
|
14
|
-
const
|
|
14
|
+
const createOtlpExportDelegate = inferExportDelegateToUse(config.headers);
|
|
15
15
|
const options = (0, convert_legacy_browser_http_options_1.convertLegacyBrowserHttpOptions)(config, signalResourcePath, requiredHeaders);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return createOtlpExportDelegate(options, serializer);
|
|
17
|
+
}
|
|
18
|
+
exports.createLegacyOtlpBrowserExportDelegate = createLegacyOtlpBrowserExportDelegate;
|
|
19
|
+
function inferExportDelegateToUse(configHeaders) {
|
|
20
|
+
if (!configHeaders && typeof navigator.sendBeacon === 'function') {
|
|
21
|
+
return otlp_browser_http_export_delegate_1.createOtlpSendBeaconExportDelegate;
|
|
22
|
+
}
|
|
23
|
+
else if (typeof globalThis.fetch !== 'undefined') {
|
|
24
|
+
return otlp_browser_http_export_delegate_1.createOtlpFetchExportDelegate;
|
|
18
25
|
}
|
|
19
26
|
else {
|
|
20
|
-
return
|
|
27
|
+
return otlp_browser_http_export_delegate_1.createOtlpXhrExportDelegate;
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
|
-
exports.
|
|
30
|
+
exports.inferExportDelegateToUse = inferExportDelegateToUse;
|
|
24
31
|
//# sourceMappingURL=create-legacy-browser-delegate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-legacy-browser-delegate.js","sourceRoot":"","sources":["../../../src/configuration/create-legacy-browser-delegate.ts"],"names":[],"mappings":";;;AAgBA,
|
|
1
|
+
{"version":3,"file":"create-legacy-browser-delegate.js","sourceRoot":"","sources":["../../../src/configuration/create-legacy-browser-delegate.ts"],"names":[],"mappings":";;;AAgBA,4FAI8C;AAC9C,+FAAwF;AAIxF;;;;;;GAMG;AACH,SAAgB,qCAAqC,CACnD,MAA8B,EAC9B,UAA2C,EAC3C,kBAA0B,EAC1B,eAAuC;IAEvC,MAAM,wBAAwB,GAAG,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1E,MAAM,OAAO,GAAG,IAAA,qEAA+B,EAC7C,MAAM,EACN,kBAAkB,EAClB,eAAe,CAChB,CAAC;IAEF,OAAO,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC;AAfD,sFAeC;AAED,SAAgB,wBAAwB,CACtC,aAAgD;IAEhD,IAAI,CAAC,aAAa,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,EAAE;QAChE,OAAO,sEAAkC,CAAC;KAC3C;SAAM,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE;QAClD,OAAO,iEAA6B,CAAC;KACtC;SAAM;QACL,OAAO,+DAA2B,CAAC;KACpC;AACH,CAAC;AAVD,4DAUC","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 { ISerializer } from '@opentelemetry/otlp-transformer';\nimport {\n createOtlpFetchExportDelegate,\n createOtlpSendBeaconExportDelegate,\n createOtlpXhrExportDelegate,\n} from '../otlp-browser-http-export-delegate';\nimport { convertLegacyBrowserHttpOptions } from './convert-legacy-browser-http-options';\nimport { IOtlpExportDelegate } from '../otlp-export-delegate';\nimport { OTLPExporterConfigBase } from './legacy-base-configuration';\n\n/**\n * @deprecated\n * @param config\n * @param serializer\n * @param signalResourcePath\n * @param requiredHeaders\n */\nexport function createLegacyOtlpBrowserExportDelegate<Internal, Response>(\n config: OTLPExporterConfigBase,\n serializer: ISerializer<Internal, Response>,\n signalResourcePath: string,\n requiredHeaders: Record<string, string>\n): IOtlpExportDelegate<Internal> {\n const createOtlpExportDelegate = inferExportDelegateToUse(config.headers);\n\n const options = convertLegacyBrowserHttpOptions(\n config,\n signalResourcePath,\n requiredHeaders\n );\n\n return createOtlpExportDelegate(options, serializer);\n}\n\nexport function inferExportDelegateToUse(\n configHeaders: OTLPExporterConfigBase['headers']\n) {\n if (!configHeaders && typeof navigator.sendBeacon === 'function') {\n return createOtlpSendBeaconExportDelegate;\n } else if (typeof globalThis.fetch !== 'undefined') {\n return createOtlpFetchExportDelegate;\n } else {\n return createOtlpXhrExportDelegate;\n }\n}\n"]}
|
|
@@ -2,14 +2,37 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type * as http from 'http';
|
|
4
4
|
import type * as https from 'https';
|
|
5
|
-
import { OTLPExporterConfigBase } from './legacy-base-configuration';
|
|
5
|
+
import type { OTLPExporterConfigBase } from './legacy-base-configuration';
|
|
6
|
+
import type { HttpAgentFactory } from './otlp-http-configuration';
|
|
6
7
|
/**
|
|
7
8
|
* Collector Exporter node base config
|
|
8
9
|
*/
|
|
9
10
|
export interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {
|
|
10
11
|
keepAlive?: boolean;
|
|
11
12
|
compression?: CompressionAlgorithm;
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Custom HTTP agent options or a factory function for creating agents.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Prefer using `http.AgentOptions` or `https.AgentOptions` over a factory function wherever possible.
|
|
18
|
+
* If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`
|
|
19
|
+
* statically at the top of the file**.
|
|
20
|
+
* Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`
|
|
21
|
+
* module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.
|
|
22
|
+
*
|
|
23
|
+
* @example <caption> Using agent options directly: </caption>
|
|
24
|
+
* httpAgentOptions: {
|
|
25
|
+
* keepAlive: true,
|
|
26
|
+
* maxSockets: 10
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @example <caption> Using a factory with dynamic import: </caption>
|
|
30
|
+
* httpAgentOptions: async (protocol) => {
|
|
31
|
+
* const module = protocol === 'http:' ? await import('http') : await import('https');
|
|
32
|
+
* return new module.Agent({ keepAlive: true });
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
httpAgentOptions?: http.AgentOptions | https.AgentOptions | HttpAgentFactory;
|
|
13
36
|
}
|
|
14
37
|
export declare enum CompressionAlgorithm {
|
|
15
38
|
NONE = "none",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-node-configuration.js","sourceRoot":"","sources":["../../../src/configuration/legacy-node-configuration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;
|
|
1
|
+
{"version":3,"file":"legacy-node-configuration.js","sourceRoot":"","sources":["../../../src/configuration/legacy-node-configuration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAwCH,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAG/B","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\n// NOTE: do not change these imports to be actual imports, otherwise they WILL break `@opentelemetry/instrumentation-http`\nimport type * as http from 'http';\nimport type * as https from 'https';\n\nimport type { OTLPExporterConfigBase } from './legacy-base-configuration';\nimport type { HttpAgentFactory } from './otlp-http-configuration';\n\n/**\n * Collector Exporter node base config\n */\nexport interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {\n keepAlive?: boolean;\n compression?: CompressionAlgorithm;\n /**\n * Custom HTTP agent options or a factory function for creating agents.\n *\n * @remarks\n * Prefer using `http.AgentOptions` or `https.AgentOptions` over a factory function wherever possible.\n * If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`\n * statically at the top of the file**.\n * Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`\n * module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.\n *\n * @example <caption> Using agent options directly: </caption>\n * httpAgentOptions: {\n * keepAlive: true,\n * maxSockets: 10\n * }\n *\n * @example <caption> Using a factory with dynamic import: </caption>\n * httpAgentOptions: async (protocol) => {\n * const module = protocol === 'http:' ? await import('http') : await import('https');\n * return new module.Agent({ keepAlive: true });\n * }\n */\n httpAgentOptions?: http.AgentOptions | https.AgentOptions | HttpAgentFactory;\n}\n\nexport enum CompressionAlgorithm {\n NONE = 'none',\n GZIP = 'gzip',\n}\n"]}
|
|
@@ -3,11 +3,23 @@
|
|
|
3
3
|
import { OtlpSharedConfiguration } from './shared-configuration';
|
|
4
4
|
import type * as http from 'http';
|
|
5
5
|
import type * as https from 'https';
|
|
6
|
+
export type HttpAgentFactory = (protocol: string) => http.Agent | https.Agent | Promise<http.Agent> | Promise<https.Agent>;
|
|
6
7
|
export interface OtlpHttpConfiguration extends OtlpSharedConfiguration {
|
|
7
8
|
url: string;
|
|
8
9
|
headers: () => Record<string, string>;
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Factory function for creating agents.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Prefer using {@link httpAgentFactoryFromOptions} over manually writing a factory function wherever possible.
|
|
15
|
+
* If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`
|
|
16
|
+
* statically at the top of the file**.
|
|
17
|
+
* Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`
|
|
18
|
+
* module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.
|
|
19
|
+
*/
|
|
20
|
+
agentFactory: HttpAgentFactory;
|
|
10
21
|
}
|
|
22
|
+
export declare function httpAgentFactoryFromOptions(options: http.AgentOptions | https.AgentOptions): HttpAgentFactory;
|
|
11
23
|
/**
|
|
12
24
|
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
13
25
|
* @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getHttpConfigurationDefaults = exports.mergeOtlpHttpConfigurationWithDefaults = void 0;
|
|
18
|
+
exports.getHttpConfigurationDefaults = exports.mergeOtlpHttpConfigurationWithDefaults = exports.httpAgentFactoryFromOptions = void 0;
|
|
19
19
|
const shared_configuration_1 = require("./shared-configuration");
|
|
20
20
|
const util_1 = require("../util");
|
|
21
21
|
function mergeHeaders(userProvidedHeaders, fallbackHeaders, defaultHeaders) {
|
|
@@ -41,13 +41,22 @@ function validateUserProvidedUrl(url) {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// NOTE: In non-browser environments, `globalThis.location` will be `undefined`.
|
|
45
|
+
const base = globalThis.location?.href;
|
|
46
|
+
return new URL(url, base).href;
|
|
46
47
|
}
|
|
47
|
-
catch
|
|
48
|
+
catch {
|
|
48
49
|
throw new Error(`Configuration: Could not parse user-provided export URL: '${url}'`);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
function httpAgentFactoryFromOptions(options) {
|
|
53
|
+
return async (protocol) => {
|
|
54
|
+
const module = protocol === 'http:' ? import('http') : import('https');
|
|
55
|
+
const { Agent } = await module;
|
|
56
|
+
return new Agent(options);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.httpAgentFactoryFromOptions = httpAgentFactoryFromOptions;
|
|
51
60
|
/**
|
|
52
61
|
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
53
62
|
* @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
|
|
@@ -60,9 +69,9 @@ function mergeOtlpHttpConfigurationWithDefaults(userProvidedConfiguration, fallb
|
|
|
60
69
|
url: validateUserProvidedUrl(userProvidedConfiguration.url) ??
|
|
61
70
|
fallbackConfiguration.url ??
|
|
62
71
|
defaultConfiguration.url,
|
|
63
|
-
|
|
64
|
-
fallbackConfiguration.
|
|
65
|
-
defaultConfiguration.
|
|
72
|
+
agentFactory: userProvidedConfiguration.agentFactory ??
|
|
73
|
+
fallbackConfiguration.agentFactory ??
|
|
74
|
+
defaultConfiguration.agentFactory,
|
|
66
75
|
};
|
|
67
76
|
}
|
|
68
77
|
exports.mergeOtlpHttpConfigurationWithDefaults = mergeOtlpHttpConfigurationWithDefaults;
|
|
@@ -71,7 +80,7 @@ function getHttpConfigurationDefaults(requiredHeaders, signalResourcePath) {
|
|
|
71
80
|
...(0, shared_configuration_1.getSharedConfigurationDefaults)(),
|
|
72
81
|
headers: () => requiredHeaders,
|
|
73
82
|
url: 'http://localhost:4318/' + signalResourcePath,
|
|
74
|
-
|
|
83
|
+
agentFactory: httpAgentFactoryFromOptions({ keepAlive: true }),
|
|
75
84
|
};
|
|
76
85
|
}
|
|
77
86
|
exports.getHttpConfigurationDefaults = getHttpConfigurationDefaults;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-configuration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iEAIgC;AAChC,kCAAsD;
|
|
1
|
+
{"version":3,"file":"otlp-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-configuration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iEAIgC;AAChC,kCAAsD;AA0BtD,SAAS,YAAY,CACnB,mBAAsE,EACtE,eAAkE,EAClE,cAA4C;IAE5C,MAAM,eAAe,GAAG;QACtB,GAAG,cAAc,EAAE;KACpB,CAAC;IACF,MAAM,OAAO,GAAG,EAAE,CAAC;IAEnB,OAAO,GAAG,EAAE;QACV,0BAA0B;QAC1B,IAAI,eAAe,IAAI,IAAI,EAAE;YAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;SAC3C;QAED,mCAAmC;QACnC,IAAI,mBAAmB,IAAI,IAAI,EAAE;YAC/B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAC;SAC/C;QAED,0BAA0B;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAuB;IACtD,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,OAAO,SAAS,CAAC;KAClB;IACD,IAAI;QACF,gFAAgF;QAChF,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC;QACvC,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;KAChC;IAAC,MAAM;QACN,MAAM,IAAI,KAAK,CACb,6DAA6D,GAAG,GAAG,CACpE,CAAC;KACH;AACH,CAAC;AAED,SAAgB,2BAA2B,CACzC,OAA+C;IAE/C,OAAO,KAAK,EAAC,QAAQ,EAAC,EAAE;QACtB,MAAM,MAAM,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;QAC/B,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AARD,kEAQC;AAED;;;;GAIG;AACH,SAAgB,sCAAsC,CACpD,yBAAyD,EACzD,qBAAqD,EACrD,oBAA2C;IAE3C,OAAO;QACL,GAAG,IAAA,+DAAwC,EACzC,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,CACrB;QACD,OAAO,EAAE,YAAY,CACnB,IAAA,kCAA2B,EAAC,yBAAyB,CAAC,OAAO,CAAC,EAC9D,qBAAqB,CAAC,OAAO,EAC7B,oBAAoB,CAAC,OAAO,CAC7B;QACD,GAAG,EACD,uBAAuB,CAAC,yBAAyB,CAAC,GAAG,CAAC;YACtD,qBAAqB,CAAC,GAAG;YACzB,oBAAoB,CAAC,GAAG;QAC1B,YAAY,EACV,yBAAyB,CAAC,YAAY;YACtC,qBAAqB,CAAC,YAAY;YAClC,oBAAoB,CAAC,YAAY;KACpC,CAAC;AACJ,CAAC;AAzBD,wFAyBC;AAED,SAAgB,4BAA4B,CAC1C,eAAuC,EACvC,kBAA0B;IAE1B,OAAO;QACL,GAAG,IAAA,qDAA8B,GAAE;QACnC,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe;QAC9B,GAAG,EAAE,wBAAwB,GAAG,kBAAkB;QAClD,YAAY,EAAE,2BAA2B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC;AAVD,oEAUC","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 {\n getSharedConfigurationDefaults,\n mergeOtlpSharedConfigurationWithDefaults,\n OtlpSharedConfiguration,\n} from './shared-configuration';\nimport { validateAndNormalizeHeaders } from '../util';\n\n// NOTE: do not change these imports to be actual imports, otherwise they WILL break `@opentelemetry/instrumentation-http`\nimport type * as http from 'http';\nimport type * as https from 'https';\n\nexport type HttpAgentFactory = (\n protocol: string\n) => http.Agent | https.Agent | Promise<http.Agent> | Promise<https.Agent>;\n\nexport interface OtlpHttpConfiguration extends OtlpSharedConfiguration {\n url: string;\n headers: () => Record<string, string>;\n /**\n * Factory function for creating agents.\n *\n * @remarks\n * Prefer using {@link httpAgentFactoryFromOptions} over manually writing a factory function wherever possible.\n * If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`\n * statically at the top of the file**.\n * Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`\n * module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.\n */\n agentFactory: HttpAgentFactory;\n}\n\nfunction mergeHeaders(\n userProvidedHeaders: (() => Record<string, string>) | undefined | null,\n fallbackHeaders: (() => Record<string, string>) | undefined | null,\n defaultHeaders: () => Record<string, string>\n): () => Record<string, string> {\n const requiredHeaders = {\n ...defaultHeaders(),\n };\n const headers = {};\n\n return () => {\n // add fallback ones first\n if (fallbackHeaders != null) {\n Object.assign(headers, fallbackHeaders());\n }\n\n // override with user-provided ones\n if (userProvidedHeaders != null) {\n Object.assign(headers, userProvidedHeaders());\n }\n\n // override required ones.\n return Object.assign(headers, requiredHeaders);\n };\n}\n\nfunction validateUserProvidedUrl(url: string | undefined): string | undefined {\n if (url == null) {\n return undefined;\n }\n try {\n // NOTE: In non-browser environments, `globalThis.location` will be `undefined`.\n const base = globalThis.location?.href;\n return new URL(url, base).href;\n } catch {\n throw new Error(\n `Configuration: Could not parse user-provided export URL: '${url}'`\n );\n }\n}\n\nexport function httpAgentFactoryFromOptions(\n options: http.AgentOptions | https.AgentOptions\n): HttpAgentFactory {\n return async protocol => {\n const module = protocol === 'http:' ? import('http') : import('https');\n const { Agent } = await module;\n return new Agent(options);\n };\n}\n\n/**\n * @param userProvidedConfiguration Configuration options provided by the user in code.\n * @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.\n * @param defaultConfiguration The defaults as defined by the exporter specification\n */\nexport function mergeOtlpHttpConfigurationWithDefaults(\n userProvidedConfiguration: Partial<OtlpHttpConfiguration>,\n fallbackConfiguration: Partial<OtlpHttpConfiguration>,\n defaultConfiguration: OtlpHttpConfiguration\n): OtlpHttpConfiguration {\n return {\n ...mergeOtlpSharedConfigurationWithDefaults(\n userProvidedConfiguration,\n fallbackConfiguration,\n defaultConfiguration\n ),\n headers: mergeHeaders(\n validateAndNormalizeHeaders(userProvidedConfiguration.headers),\n fallbackConfiguration.headers,\n defaultConfiguration.headers\n ),\n url:\n validateUserProvidedUrl(userProvidedConfiguration.url) ??\n fallbackConfiguration.url ??\n defaultConfiguration.url,\n agentFactory:\n userProvidedConfiguration.agentFactory ??\n fallbackConfiguration.agentFactory ??\n defaultConfiguration.agentFactory,\n };\n}\n\nexport function getHttpConfigurationDefaults(\n requiredHeaders: Record<string, string>,\n signalResourcePath: string\n): OtlpHttpConfiguration {\n return {\n ...getSharedConfigurationDefaults(),\n headers: () => requiredHeaders,\n url: 'http://localhost:4318/' + signalResourcePath,\n agentFactory: httpAgentFactoryFromOptions({ keepAlive: true }),\n };\n}\n"]}
|
|
@@ -21,8 +21,8 @@ const api_1 = require("@opentelemetry/api");
|
|
|
21
21
|
const shared_env_configuration_1 = require("./shared-env-configuration");
|
|
22
22
|
const shared_configuration_1 = require("./shared-configuration");
|
|
23
23
|
function getStaticHeadersFromEnv(signalIdentifier) {
|
|
24
|
-
const signalSpecificRawHeaders =
|
|
25
|
-
const nonSignalSpecificRawHeaders =
|
|
24
|
+
const signalSpecificRawHeaders = (0, core_1.getStringFromEnv)(`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`);
|
|
25
|
+
const nonSignalSpecificRawHeaders = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
|
|
26
26
|
const signalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(signalSpecificRawHeaders);
|
|
27
27
|
const nonSignalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(nonSignalSpecificRawHeaders);
|
|
28
28
|
if (Object.keys(signalSpecificHeaders).length === 0 &&
|
|
@@ -68,15 +68,15 @@ function appendResourcePathToUrl(url, path) {
|
|
|
68
68
|
return url;
|
|
69
69
|
}
|
|
70
70
|
function getNonSpecificUrlFromEnv(signalResourcePath) {
|
|
71
|
-
const envUrl =
|
|
72
|
-
if (envUrl
|
|
71
|
+
const envUrl = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT');
|
|
72
|
+
if (envUrl === undefined) {
|
|
73
73
|
return undefined;
|
|
74
74
|
}
|
|
75
75
|
return appendResourcePathToUrl(envUrl, signalResourcePath);
|
|
76
76
|
}
|
|
77
77
|
function getSpecificUrlFromEnv(signalIdentifier) {
|
|
78
|
-
const envUrl =
|
|
79
|
-
if (envUrl
|
|
78
|
+
const envUrl = (0, core_1.getStringFromEnv)(`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`);
|
|
79
|
+
if (envUrl === undefined) {
|
|
80
80
|
return undefined;
|
|
81
81
|
}
|
|
82
82
|
return appendRootPathToUrlIfNeeded(envUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-http-env-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-env-configuration.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,
|
|
1
|
+
{"version":3,"file":"otlp-http-env-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-env-configuration.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,8CAAgF;AAChF,4CAA0C;AAC1C,yEAAmF;AAEnF,iEAAqE;AAErE,SAAS,uBAAuB,CAC9B,gBAAwB;IAExB,MAAM,wBAAwB,GAAG,IAAA,uBAAgB,EAC/C,sBAAsB,gBAAgB,UAAU,CACjD,CAAC;IACF,MAAM,2BAA2B,GAAG,IAAA,uBAAgB,EAClD,4BAA4B,CAC7B,CAAC;IAEF,MAAM,qBAAqB,GAAG,IAAA,8BAAuB,EACnD,wBAAwB,CACzB,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAA,8BAAuB,EACtD,2BAA2B,CAC5B,CAAC;IAEF,IACE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,MAAM,KAAK,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,MAAM,KAAK,CAAC,EAClD;QACA,OAAO,SAAS,CAAC;KAClB;IAED,gGAAgG;IAChG,yBAAyB;IACzB,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,IAAA,8BAAuB,EAAC,2BAA2B,CAAC,EACpD,IAAA,8BAAuB,EAAC,wBAAwB,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,GAAW;IAC9C,IAAI;QACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,8DAA8D;QAC9D,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;KAC7B;IAAC,MAAM;QACN,UAAI,CAAC,IAAI,CACP,oEAAoE,GAAG,8BAA8B,CACtG,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,SAAS,uBAAuB,CAC9B,GAAW,EACX,IAAY;IAEZ,IAAI;QACF,oDAAoD;QACpD,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;KACd;IAAC,MAAM;QACN,UAAI,CAAC,IAAI,CACP,oEAAoE,GAAG,8BAA8B,CACtG,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACtB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IACD,GAAG,IAAI,IAAI,CAAC;IAEZ,IAAI;QACF,oDAAoD;QACpD,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;KACd;IAAC,MAAM;QACN,UAAI,CAAC,IAAI,CACP,8CAA8C,IAAI,uDAAuD,GAAG,GAAG,CAChH,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,wBAAwB,CAC/B,kBAA0B;IAE1B,MAAM,MAAM,GAAG,IAAA,uBAAgB,EAAC,6BAA6B,CAAC,CAAC;IAC/D,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,qBAAqB,CAAC,gBAAwB;IACrD,MAAM,MAAM,GAAG,IAAA,uBAAgB,EAC7B,sBAAsB,gBAAgB,WAAW,CAClD,CAAC;IACF,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mCAAmC,CACjD,gBAAwB,EACxB,kBAA0B;IAE1B,OAAO;QACL,GAAG,IAAA,gEAAqC,EAAC,gBAAgB,CAAC;QAC1D,GAAG,EACD,qBAAqB,CAAC,gBAAgB,CAAC;YACvC,wBAAwB,CAAC,kBAAkB,CAAC;QAC9C,OAAO,EAAE,IAAA,kDAA2B,EAClC,uBAAuB,CAAC,gBAAgB,CAAC,CAC1C;KACF,CAAC;AACJ,CAAC;AAbD,kFAaC","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 { getStringFromEnv, parseKeyPairsIntoRecord } from '@opentelemetry/core';\nimport { diag } from '@opentelemetry/api';\nimport { getSharedConfigurationFromEnvironment } from './shared-env-configuration';\nimport { OtlpHttpConfiguration } from './otlp-http-configuration';\nimport { wrapStaticHeadersInFunction } from './shared-configuration';\n\nfunction getStaticHeadersFromEnv(\n signalIdentifier: string\n): Record<string, string> | undefined {\n const signalSpecificRawHeaders = getStringFromEnv(\n `OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`\n );\n const nonSignalSpecificRawHeaders = getStringFromEnv(\n 'OTEL_EXPORTER_OTLP_HEADERS'\n );\n\n const signalSpecificHeaders = parseKeyPairsIntoRecord(\n signalSpecificRawHeaders\n );\n const nonSignalSpecificHeaders = parseKeyPairsIntoRecord(\n nonSignalSpecificRawHeaders\n );\n\n if (\n Object.keys(signalSpecificHeaders).length === 0 &&\n Object.keys(nonSignalSpecificHeaders).length === 0\n ) {\n return undefined;\n }\n\n // headers are combined instead of overwritten, with the specific headers taking precedence over\n // the non-specific ones.\n return Object.assign(\n {},\n parseKeyPairsIntoRecord(nonSignalSpecificRawHeaders),\n parseKeyPairsIntoRecord(signalSpecificRawHeaders)\n );\n}\n\nfunction appendRootPathToUrlIfNeeded(url: string): string | undefined {\n try {\n const parsedUrl = new URL(url);\n // This will automatically append '/' if there's no root path.\n return parsedUrl.toString();\n } catch {\n diag.warn(\n `Configuration: Could not parse environment-provided export URL: '${url}', falling back to undefined`\n );\n return undefined;\n }\n}\n\nfunction appendResourcePathToUrl(\n url: string,\n path: string\n): string | undefined {\n try {\n // just try to parse, if it fails we catch and warn.\n new URL(url);\n } catch {\n diag.warn(\n `Configuration: Could not parse environment-provided export URL: '${url}', falling back to undefined`\n );\n return undefined;\n }\n\n if (!url.endsWith('/')) {\n url = url + '/';\n }\n url += path;\n\n try {\n // just try to parse, if it fails we catch and warn.\n new URL(url);\n } catch {\n diag.warn(\n `Configuration: Provided URL appended with '${path}' is not a valid URL, using 'undefined' instead of '${url}'`\n );\n return undefined;\n }\n\n return url;\n}\n\nfunction getNonSpecificUrlFromEnv(\n signalResourcePath: string\n): string | undefined {\n const envUrl = getStringFromEnv('OTEL_EXPORTER_OTLP_ENDPOINT');\n if (envUrl === undefined) {\n return undefined;\n }\n return appendResourcePathToUrl(envUrl, signalResourcePath);\n}\n\nfunction getSpecificUrlFromEnv(signalIdentifier: string): string | undefined {\n const envUrl = getStringFromEnv(\n `OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`\n );\n if (envUrl === undefined) {\n return undefined;\n }\n return appendRootPathToUrlIfNeeded(envUrl);\n}\n\n/**\n * Reads and returns configuration from the environment\n *\n * @param signalIdentifier all caps part in environment variables that identifies the signal (e.g.: METRICS, TRACES, LOGS)\n * @param signalResourcePath signal resource path to append if necessary (e.g.: v1/metrics, v1/traces, v1/logs)\n */\nexport function getHttpConfigurationFromEnvironment(\n signalIdentifier: string,\n signalResourcePath: string\n): Partial<OtlpHttpConfiguration> {\n return {\n ...getSharedConfigurationFromEnvironment(signalIdentifier),\n url:\n getSpecificUrlFromEnv(signalIdentifier) ??\n getNonSpecificUrlFromEnv(signalResourcePath),\n headers: wrapStaticHeadersInFunction(\n getStaticHeadersFromEnv(signalIdentifier)\n ),\n };\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { httpAgentFactoryFromOptions } from './configuration/otlp-http-configuration';
|
|
1
2
|
export { createOtlpHttpExportDelegate } from './otlp-http-export-delegate';
|
|
2
3
|
export { getSharedConfigurationFromEnvironment } from './configuration/shared-env-configuration';
|
|
3
4
|
export { convertLegacyHttpOptions } from './configuration/convert-legacy-node-http-options';
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.convertLegacyHttpOptions = exports.getSharedConfigurationFromEnvironment = exports.createOtlpHttpExportDelegate = void 0;
|
|
18
|
+
exports.convertLegacyHttpOptions = exports.getSharedConfigurationFromEnvironment = exports.createOtlpHttpExportDelegate = exports.httpAgentFactoryFromOptions = void 0;
|
|
19
|
+
var otlp_http_configuration_1 = require("./configuration/otlp-http-configuration");
|
|
20
|
+
Object.defineProperty(exports, "httpAgentFactoryFromOptions", { enumerable: true, get: function () { return otlp_http_configuration_1.httpAgentFactoryFromOptions; } });
|
|
19
21
|
var otlp_http_export_delegate_1 = require("./otlp-http-export-delegate");
|
|
20
22
|
Object.defineProperty(exports, "createOtlpHttpExportDelegate", { enumerable: true, get: function () { return otlp_http_export_delegate_1.createOtlpHttpExportDelegate; } });
|
|
21
23
|
var shared_env_configuration_1 = require("./configuration/shared-env-configuration");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node-http.js","sourceRoot":"","sources":["../../src/index-node-http.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,yEAA2E;AAAlE,yIAAA,4BAA4B,OAAA;AACrC,qFAAiG;AAAxF,iJAAA,qCAAqC,OAAA;AAC9C,qGAA4F;AAAnF,4IAAA,wBAAwB,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 { createOtlpHttpExportDelegate } from './otlp-http-export-delegate';\nexport { getSharedConfigurationFromEnvironment } from './configuration/shared-env-configuration';\nexport { convertLegacyHttpOptions } from './configuration/convert-legacy-node-http-options';\n"]}
|
|
1
|
+
{"version":3,"file":"index-node-http.js","sourceRoot":"","sources":["../../src/index-node-http.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,mFAAsF;AAA7E,sIAAA,2BAA2B,OAAA;AACpC,yEAA2E;AAAlE,yIAAA,4BAA4B,OAAA;AACrC,qFAAiG;AAAxF,iJAAA,qCAAqC,OAAA;AAC9C,qGAA4F;AAAnF,4IAAA,wBAAwB,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 { httpAgentFactoryFromOptions } from './configuration/otlp-http-configuration';\nexport { createOtlpHttpExportDelegate } from './otlp-http-export-delegate';\nexport { getSharedConfigurationFromEnvironment } from './configuration/shared-env-configuration';\nexport { convertLegacyHttpOptions } from './configuration/convert-legacy-node-http-options';\n"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { OtlpHttpConfiguration } from './configuration/otlp-http-configuration';
|
|
2
2
|
import { ISerializer } from '@opentelemetry/otlp-transformer';
|
|
3
3
|
import { IOtlpExportDelegate } from './otlp-export-delegate';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use {@link createOtlpFetchExportDelegate}
|
|
6
|
+
*/
|
|
4
7
|
export declare function createOtlpXhrExportDelegate<Internal, Response>(options: OtlpHttpConfiguration, serializer: ISerializer<Internal, Response>): IOtlpExportDelegate<Internal>;
|
|
8
|
+
export declare function createOtlpFetchExportDelegate<Internal, Response>(options: OtlpHttpConfiguration, serializer: ISerializer<Internal, Response>): IOtlpExportDelegate<Internal>;
|
|
5
9
|
export declare function createOtlpSendBeaconExportDelegate<Internal, Response>(options: OtlpHttpConfiguration, serializer: ISerializer<Internal, Response>): IOtlpExportDelegate<Internal>;
|
|
6
10
|
//# sourceMappingURL=otlp-browser-http-export-delegate.d.ts.map
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOtlpSendBeaconExportDelegate = exports.createOtlpXhrExportDelegate = void 0;
|
|
3
|
+
exports.createOtlpSendBeaconExportDelegate = exports.createOtlpFetchExportDelegate = exports.createOtlpXhrExportDelegate = void 0;
|
|
4
4
|
const retrying_transport_1 = require("./retrying-transport");
|
|
5
5
|
const xhr_transport_1 = require("./transport/xhr-transport");
|
|
6
6
|
const send_beacon_transport_1 = require("./transport/send-beacon-transport");
|
|
7
7
|
const otlp_network_export_delegate_1 = require("./otlp-network-export-delegate");
|
|
8
|
+
const fetch_transport_1 = require("./transport/fetch-transport");
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated use {@link createOtlpFetchExportDelegate}
|
|
11
|
+
*/
|
|
8
12
|
function createOtlpXhrExportDelegate(options, serializer) {
|
|
9
13
|
return (0, otlp_network_export_delegate_1.createOtlpNetworkExportDelegate)(options, serializer, (0, retrying_transport_1.createRetryingTransport)({
|
|
10
14
|
transport: (0, xhr_transport_1.createXhrTransport)(options),
|
|
11
15
|
}));
|
|
12
16
|
}
|
|
13
17
|
exports.createOtlpXhrExportDelegate = createOtlpXhrExportDelegate;
|
|
18
|
+
function createOtlpFetchExportDelegate(options, serializer) {
|
|
19
|
+
return (0, otlp_network_export_delegate_1.createOtlpNetworkExportDelegate)(options, serializer, (0, retrying_transport_1.createRetryingTransport)({
|
|
20
|
+
transport: (0, fetch_transport_1.createFetchTransport)(options),
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
exports.createOtlpFetchExportDelegate = createOtlpFetchExportDelegate;
|
|
14
24
|
function createOtlpSendBeaconExportDelegate(options, serializer) {
|
|
15
25
|
return (0, otlp_network_export_delegate_1.createOtlpNetworkExportDelegate)(options, serializer, (0, retrying_transport_1.createRetryingTransport)({
|
|
16
26
|
transport: (0, send_beacon_transport_1.createSendBeaconTransport)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-browser-http-export-delegate.js","sourceRoot":"","sources":["../../src/otlp-browser-http-export-delegate.ts"],"names":[],"mappings":";;;AAkBA,6DAA+D;AAC/D,6DAA+D;AAC/D,6EAA8E;AAC9E,iFAAiF;
|
|
1
|
+
{"version":3,"file":"otlp-browser-http-export-delegate.js","sourceRoot":"","sources":["../../src/otlp-browser-http-export-delegate.ts"],"names":[],"mappings":";;;AAkBA,6DAA+D;AAC/D,6DAA+D;AAC/D,6EAA8E;AAC9E,iFAAiF;AACjF,iEAAmE;AAEnE;;GAEG;AACH,SAAgB,2BAA2B,CACzC,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,IAAA,8DAA+B,EACpC,OAAO,EACP,UAAU,EACV,IAAA,4CAAuB,EAAC;QACtB,SAAS,EAAE,IAAA,kCAAkB,EAAC,OAAO,CAAC;KACvC,CAAC,CACH,CAAC;AACJ,CAAC;AAXD,kEAWC;AAED,SAAgB,6BAA6B,CAC3C,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,IAAA,8DAA+B,EACpC,OAAO,EACP,UAAU,EACV,IAAA,4CAAuB,EAAC;QACtB,SAAS,EAAE,IAAA,sCAAoB,EAAC,OAAO,CAAC;KACzC,CAAC,CACH,CAAC;AACJ,CAAC;AAXD,sEAWC;AAED,SAAgB,kCAAkC,CAChD,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,IAAA,8DAA+B,EACpC,OAAO,EACP,UAAU,EACV,IAAA,4CAAuB,EAAC;QACtB,SAAS,EAAE,IAAA,iDAAyB,EAAC;YACnC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,cAAc,CAAC;SAC5C,CAAC;KACH,CAAC,CACH,CAAC;AACJ,CAAC;AAdD,gFAcC","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 { OtlpHttpConfiguration } from './configuration/otlp-http-configuration';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { IOtlpExportDelegate } from './otlp-export-delegate';\nimport { createRetryingTransport } from './retrying-transport';\nimport { createXhrTransport } from './transport/xhr-transport';\nimport { createSendBeaconTransport } from './transport/send-beacon-transport';\nimport { createOtlpNetworkExportDelegate } from './otlp-network-export-delegate';\nimport { createFetchTransport } from './transport/fetch-transport';\n\n/**\n * @deprecated use {@link createOtlpFetchExportDelegate}\n */\nexport function createOtlpXhrExportDelegate<Internal, Response>(\n options: OtlpHttpConfiguration,\n serializer: ISerializer<Internal, Response>\n): IOtlpExportDelegate<Internal> {\n return createOtlpNetworkExportDelegate(\n options,\n serializer,\n createRetryingTransport({\n transport: createXhrTransport(options),\n })\n );\n}\n\nexport function createOtlpFetchExportDelegate<Internal, Response>(\n options: OtlpHttpConfiguration,\n serializer: ISerializer<Internal, Response>\n): IOtlpExportDelegate<Internal> {\n return createOtlpNetworkExportDelegate(\n options,\n serializer,\n createRetryingTransport({\n transport: createFetchTransport(options),\n })\n );\n}\n\nexport function createOtlpSendBeaconExportDelegate<Internal, Response>(\n options: OtlpHttpConfiguration,\n serializer: ISerializer<Internal, Response>\n): IOtlpExportDelegate<Internal> {\n return createOtlpNetworkExportDelegate(\n options,\n serializer,\n createRetryingTransport({\n transport: createSendBeaconTransport({\n url: options.url,\n blobType: options.headers()['Content-Type'],\n }),\n })\n );\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IExporterTransport } from '../exporter-transport';
|
|
2
|
+
export interface FetchTransportParameters {
|
|
3
|
+
url: string;
|
|
4
|
+
headers: () => Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates an exporter transport that uses `fetch` to send the data
|
|
8
|
+
* @param parameters applied to each request made by transport
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFetchTransport(parameters: FetchTransportParameters): IExporterTransport;
|
|
11
|
+
//# sourceMappingURL=fetch-transport.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
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.createFetchTransport = void 0;
|
|
19
|
+
const api_1 = require("@opentelemetry/api");
|
|
20
|
+
const is_export_retryable_1 = require("../is-export-retryable");
|
|
21
|
+
class FetchTransport {
|
|
22
|
+
_parameters;
|
|
23
|
+
constructor(_parameters) {
|
|
24
|
+
this._parameters = _parameters;
|
|
25
|
+
}
|
|
26
|
+
async send(data, timeoutMillis) {
|
|
27
|
+
const abortController = new AbortController();
|
|
28
|
+
const timeout = setTimeout(() => abortController.abort(), timeoutMillis);
|
|
29
|
+
try {
|
|
30
|
+
const isBrowserEnvironment = !!globalThis.location;
|
|
31
|
+
const url = new URL(this._parameters.url);
|
|
32
|
+
const response = await fetch(url.href, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: this._parameters.headers(),
|
|
35
|
+
body: data,
|
|
36
|
+
signal: abortController.signal,
|
|
37
|
+
keepalive: isBrowserEnvironment,
|
|
38
|
+
mode: isBrowserEnvironment
|
|
39
|
+
? globalThis.location?.origin === url.origin
|
|
40
|
+
? 'same-origin'
|
|
41
|
+
: 'cors'
|
|
42
|
+
: 'no-cors',
|
|
43
|
+
});
|
|
44
|
+
if (response.status >= 200 && response.status <= 299) {
|
|
45
|
+
api_1.diag.debug('response success');
|
|
46
|
+
return { status: 'success' };
|
|
47
|
+
}
|
|
48
|
+
else if ((0, is_export_retryable_1.isExportRetryable)(response.status)) {
|
|
49
|
+
const retryAfter = response.headers.get('Retry-After');
|
|
50
|
+
const retryInMillis = (0, is_export_retryable_1.parseRetryAfterToMills)(retryAfter);
|
|
51
|
+
return { status: 'retryable', retryInMillis };
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
status: 'failure',
|
|
55
|
+
error: new Error('Fetch request failed with non-retryable status'),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error?.name === 'AbortError') {
|
|
60
|
+
return {
|
|
61
|
+
status: 'failure',
|
|
62
|
+
error: new Error('Fetch request timed out', { cause: error }),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
status: 'failure',
|
|
67
|
+
error: new Error('Fetch request errored', { cause: error }),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
clearTimeout(timeout);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
shutdown() {
|
|
75
|
+
// Intentionally left empty, nothing to do.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates an exporter transport that uses `fetch` to send the data
|
|
80
|
+
* @param parameters applied to each request made by transport
|
|
81
|
+
*/
|
|
82
|
+
function createFetchTransport(parameters) {
|
|
83
|
+
return new FetchTransport(parameters);
|
|
84
|
+
}
|
|
85
|
+
exports.createFetchTransport = createFetchTransport;
|
|
86
|
+
//# sourceMappingURL=fetch-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-transport.js","sourceRoot":"","sources":["../../../src/transport/fetch-transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,4CAA0C;AAC1C,gEAGgC;AAOhC,MAAM,cAAc;IACE;IAApB,YAAoB,WAAqC;QAArC,gBAAW,GAAX,WAAW,CAA0B;IAAG,CAAC;IAE7D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,aAAa,CAAC,CAAC;QACzE,IAAI;YACF,MAAM,oBAAoB,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;YACnD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YAC1C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;gBACrC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;gBACnC,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,eAAe,CAAC,MAAM;gBAC9B,SAAS,EAAE,oBAAoB;gBAC/B,IAAI,EAAE,oBAAoB;oBACxB,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,MAAM;wBAC1C,CAAC,CAAC,aAAa;wBACf,CAAC,CAAC,MAAM;oBACV,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;YAEH,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;gBACpD,UAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBAC/B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;aAC9B;iBAAM,IAAI,IAAA,uCAAiB,EAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBAC7C,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBACvD,MAAM,aAAa,GAAG,IAAA,4CAAsB,EAAC,UAAU,CAAC,CAAC;gBACzD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC;aAC/C;YACD,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,gDAAgD,CAAC;aACnE,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,KAAK,EAAE,IAAI,KAAK,YAAY,EAAE;gBAChC,OAAO;oBACL,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;iBAC9D,CAAC;aACH;YACD,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;aAC5D,CAAC;SACH;gBAAS;YACR,YAAY,CAAC,OAAO,CAAC,CAAC;SACvB;IACH,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,UAAoC;IAEpC,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AAJD,oDAIC","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 { IExporterTransport } from '../exporter-transport';\nimport { ExportResponse } from '../export-response';\nimport { diag } from '@opentelemetry/api';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\n\nexport interface FetchTransportParameters {\n url: string;\n headers: () => Record<string, string>;\n}\n\nclass FetchTransport implements IExporterTransport {\n constructor(private _parameters: FetchTransportParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const abortController = new AbortController();\n const timeout = setTimeout(() => abortController.abort(), timeoutMillis);\n try {\n const isBrowserEnvironment = !!globalThis.location;\n const url = new URL(this._parameters.url);\n const response = await fetch(url.href, {\n method: 'POST',\n headers: this._parameters.headers(),\n body: data,\n signal: abortController.signal,\n keepalive: isBrowserEnvironment,\n mode: isBrowserEnvironment\n ? globalThis.location?.origin === url.origin\n ? 'same-origin'\n : 'cors'\n : 'no-cors',\n });\n\n if (response.status >= 200 && response.status <= 299) {\n diag.debug('response success');\n return { status: 'success' };\n } else if (isExportRetryable(response.status)) {\n const retryAfter = response.headers.get('Retry-After');\n const retryInMillis = parseRetryAfterToMills(retryAfter);\n return { status: 'retryable', retryInMillis };\n }\n return {\n status: 'failure',\n error: new Error('Fetch request failed with non-retryable status'),\n };\n } catch (error) {\n if (error?.name === 'AbortError') {\n return {\n status: 'failure',\n error: new Error('Fetch request timed out', { cause: error }),\n };\n }\n return {\n status: 'failure',\n error: new Error('Fetch request errored', { cause: error }),\n };\n } finally {\n clearTimeout(timeout);\n }\n }\n\n shutdown() {\n // Intentionally left empty, nothing to do.\n }\n}\n\n/**\n * Creates an exporter transport that uses `fetch` to send the data\n * @param parameters applied to each request made by transport\n */\nexport function createFetchTransport(\n parameters: FetchTransportParameters\n): IExporterTransport {\n return new FetchTransport(parameters);\n}\n"]}
|