@opentelemetry/otlp-exporter-base 0.206.0 → 0.208.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/configuration/convert-legacy-browser-http-options.js +2 -2
- package/build/esm/configuration/convert-legacy-browser-http-options.js.map +1 -1
- package/build/esm/configuration/convert-legacy-http-options.d.ts +4 -0
- package/build/esm/configuration/convert-legacy-http-options.js +23 -0
- package/build/esm/configuration/convert-legacy-http-options.js.map +1 -0
- package/build/esm/configuration/convert-legacy-node-http-options.js +3 -2
- package/build/esm/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/esm/configuration/legacy-base-configuration.d.ts +26 -1
- package/build/esm/configuration/legacy-base-configuration.js.map +1 -1
- package/build/esm/configuration/legacy-node-configuration.d.ts +6 -0
- package/build/esm/configuration/legacy-node-configuration.js.map +1 -1
- package/build/esm/configuration/otlp-http-configuration.d.ts +2 -1
- package/build/esm/configuration/otlp-http-configuration.js +9 -9
- package/build/esm/configuration/otlp-http-configuration.js.map +1 -1
- package/build/esm/configuration/otlp-node-http-configuration.d.ts +6 -0
- package/build/esm/configuration/otlp-node-http-configuration.js +8 -1
- package/build/esm/configuration/otlp-node-http-configuration.js.map +1 -1
- package/build/esm/configuration/otlp-node-http-env-configuration.js +35 -0
- package/build/esm/configuration/otlp-node-http-env-configuration.js.map +1 -1
- package/build/esm/configuration/shared-configuration.d.ts +2 -1
- package/build/esm/configuration/shared-configuration.js +1 -1
- package/build/esm/configuration/shared-configuration.js.map +1 -1
- package/build/esm/otlp-browser-http-export-delegate.js +1 -1
- package/build/esm/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/esm/transport/fetch-transport.d.ts +2 -1
- package/build/esm/transport/fetch-transport.js +1 -1
- package/build/esm/transport/fetch-transport.js.map +1 -1
- package/build/esm/transport/http-exporter-transport.js +2 -1
- package/build/esm/transport/http-exporter-transport.js.map +1 -1
- package/build/esm/transport/http-transport-types.d.ts +3 -1
- package/build/esm/transport/http-transport-types.js.map +1 -1
- package/build/esm/transport/http-transport-utils.d.ts +1 -2
- package/build/esm/transport/http-transport-utils.js +13 -7
- package/build/esm/transport/http-transport-utils.js.map +1 -1
- package/build/esm/transport/send-beacon-transport.d.ts +4 -2
- package/build/esm/transport/send-beacon-transport.js +3 -2
- package/build/esm/transport/send-beacon-transport.js.map +1 -1
- package/build/esm/transport/xhr-transport.d.ts +2 -1
- package/build/esm/transport/xhr-transport.js +4 -3
- package/build/esm/transport/xhr-transport.js.map +1 -1
- package/build/esm/util.d.ts +1 -1
- package/build/esm/util.js +10 -12
- package/build/esm/util.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/configuration/convert-legacy-browser-http-options.js +2 -2
- package/build/esnext/configuration/convert-legacy-browser-http-options.js.map +1 -1
- package/build/esnext/configuration/convert-legacy-http-options.d.ts +4 -0
- package/build/esnext/configuration/convert-legacy-http-options.js +23 -0
- package/build/esnext/configuration/convert-legacy-http-options.js.map +1 -0
- package/build/esnext/configuration/convert-legacy-node-http-options.js +3 -2
- package/build/esnext/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/esnext/configuration/legacy-base-configuration.d.ts +26 -1
- package/build/esnext/configuration/legacy-base-configuration.js.map +1 -1
- package/build/esnext/configuration/legacy-node-configuration.d.ts +6 -0
- package/build/esnext/configuration/legacy-node-configuration.js.map +1 -1
- package/build/esnext/configuration/otlp-http-configuration.d.ts +2 -1
- package/build/esnext/configuration/otlp-http-configuration.js +9 -9
- package/build/esnext/configuration/otlp-http-configuration.js.map +1 -1
- package/build/esnext/configuration/otlp-node-http-configuration.d.ts +6 -0
- package/build/esnext/configuration/otlp-node-http-configuration.js +8 -1
- package/build/esnext/configuration/otlp-node-http-configuration.js.map +1 -1
- package/build/esnext/configuration/otlp-node-http-env-configuration.js +35 -0
- package/build/esnext/configuration/otlp-node-http-env-configuration.js.map +1 -1
- package/build/esnext/configuration/shared-configuration.d.ts +2 -1
- package/build/esnext/configuration/shared-configuration.js +1 -1
- package/build/esnext/configuration/shared-configuration.js.map +1 -1
- package/build/esnext/otlp-browser-http-export-delegate.js +1 -1
- package/build/esnext/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/esnext/transport/fetch-transport.d.ts +2 -1
- package/build/esnext/transport/fetch-transport.js +1 -1
- package/build/esnext/transport/fetch-transport.js.map +1 -1
- package/build/esnext/transport/http-exporter-transport.js +2 -1
- package/build/esnext/transport/http-exporter-transport.js.map +1 -1
- package/build/esnext/transport/http-transport-types.d.ts +3 -1
- package/build/esnext/transport/http-transport-types.js.map +1 -1
- package/build/esnext/transport/http-transport-utils.d.ts +1 -2
- package/build/esnext/transport/http-transport-utils.js +13 -7
- package/build/esnext/transport/http-transport-utils.js.map +1 -1
- package/build/esnext/transport/send-beacon-transport.d.ts +4 -2
- package/build/esnext/transport/send-beacon-transport.js +3 -2
- package/build/esnext/transport/send-beacon-transport.js.map +1 -1
- package/build/esnext/transport/xhr-transport.d.ts +2 -1
- package/build/esnext/transport/xhr-transport.js +4 -3
- package/build/esnext/transport/xhr-transport.js.map +1 -1
- package/build/esnext/util.d.ts +1 -1
- package/build/esnext/util.js +10 -12
- package/build/esnext/util.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/configuration/convert-legacy-browser-http-options.js +2 -2
- package/build/src/configuration/convert-legacy-browser-http-options.js.map +1 -1
- package/build/src/configuration/convert-legacy-http-options.d.ts +4 -0
- package/build/src/configuration/convert-legacy-http-options.js +27 -0
- package/build/src/configuration/convert-legacy-http-options.js.map +1 -0
- package/build/src/configuration/convert-legacy-node-http-options.js +3 -2
- package/build/src/configuration/convert-legacy-node-http-options.js.map +1 -1
- package/build/src/configuration/legacy-base-configuration.d.ts +26 -1
- package/build/src/configuration/legacy-base-configuration.js.map +1 -1
- package/build/src/configuration/legacy-node-configuration.d.ts +6 -0
- package/build/src/configuration/legacy-node-configuration.js.map +1 -1
- package/build/src/configuration/otlp-http-configuration.d.ts +2 -1
- package/build/src/configuration/otlp-http-configuration.js +9 -9
- package/build/src/configuration/otlp-http-configuration.js.map +1 -1
- package/build/src/configuration/otlp-node-http-configuration.d.ts +6 -0
- package/build/src/configuration/otlp-node-http-configuration.js +8 -1
- package/build/src/configuration/otlp-node-http-configuration.js.map +1 -1
- package/build/src/configuration/otlp-node-http-env-configuration.js +35 -0
- package/build/src/configuration/otlp-node-http-env-configuration.js.map +1 -1
- package/build/src/configuration/shared-configuration.d.ts +2 -1
- package/build/src/configuration/shared-configuration.js +1 -1
- package/build/src/configuration/shared-configuration.js.map +1 -1
- package/build/src/otlp-browser-http-export-delegate.js +1 -1
- package/build/src/otlp-browser-http-export-delegate.js.map +1 -1
- package/build/src/transport/fetch-transport.d.ts +2 -1
- package/build/src/transport/fetch-transport.js +1 -1
- package/build/src/transport/fetch-transport.js.map +1 -1
- package/build/src/transport/http-exporter-transport.js +2 -1
- package/build/src/transport/http-exporter-transport.js.map +1 -1
- package/build/src/transport/http-transport-types.d.ts +3 -1
- package/build/src/transport/http-transport-types.js.map +1 -1
- package/build/src/transport/http-transport-utils.d.ts +1 -2
- package/build/src/transport/http-transport-utils.js +13 -7
- package/build/src/transport/http-transport-utils.js.map +1 -1
- package/build/src/transport/send-beacon-transport.d.ts +4 -2
- package/build/src/transport/send-beacon-transport.js +3 -2
- package/build/src/transport/send-beacon-transport.js.map +1 -1
- package/build/src/transport/xhr-transport.d.ts +2 -1
- package/build/src/transport/xhr-transport.js +4 -3
- package/build/src/transport/xhr-transport.js.map +1 -1
- package/build/src/util.d.ts +1 -1
- package/build/src/util.js +10 -12
- package/build/src/util.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 +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,GAEzC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"otlp-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-http-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,GAEzC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAStD,SAAS,YAAY,CACnB,mBAAsD,EACtD,eAAkD,EAClD,cAA8B;IAE9B,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,eAAe,GAAG;YACtB,GAAG,CAAC,MAAM,cAAc,EAAE,CAAC;SAC5B,CAAC;QACF,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,0BAA0B;QAC1B,IAAI,eAAe,IAAI,IAAI,EAAE;YAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,eAAe,EAAE,CAAC,CAAC;SACjD;QAED,mCAAmC;QACnC,IAAI,mBAAmB,IAAI,IAAI,EAAE;YAC/B,MAAM,CAAC,MAAM,CACX,OAAO,EACP,2BAA2B,CAAC,MAAM,mBAAmB,EAAE,CAAC,CACzD,CAAC;SACH;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;;;;GAIG;AACH,MAAM,UAAU,sCAAsC,CACpD,yBAAyD,EACzD,qBAAqD,EACrD,oBAA2C;IAE3C,OAAO;QACL,GAAG,wCAAwC,CACzC,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,CACrB;QACD,OAAO,EAAE,YAAY,CACnB,yBAAyB,CAAC,OAAO,EACjC,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;KAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,eAAuC,EACvC,kBAA0B;IAE1B,OAAO;QACL,GAAG,8BAA8B,EAAE;QACnC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe;QACpC,GAAG,EAAE,wBAAwB,GAAG,kBAAkB;KACnD,CAAC;AACJ,CAAC","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\nexport type HeadersFactory = () => Promise<Record<string, string>>;\n\nexport interface OtlpHttpConfiguration extends OtlpSharedConfiguration {\n url: string;\n headers: HeadersFactory;\n}\n\nfunction mergeHeaders(\n userProvidedHeaders: HeadersFactory | undefined | null,\n fallbackHeaders: HeadersFactory | undefined | null,\n defaultHeaders: HeadersFactory\n): HeadersFactory {\n return async () => {\n const requiredHeaders = {\n ...(await defaultHeaders()),\n };\n const headers = {};\n\n // add fallback ones first\n if (fallbackHeaders != null) {\n Object.assign(headers, await fallbackHeaders());\n }\n\n // override with user-provided ones\n if (userProvidedHeaders != null) {\n Object.assign(\n headers,\n validateAndNormalizeHeaders(await userProvidedHeaders())\n );\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\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 userProvidedConfiguration.headers,\n fallbackConfiguration.headers,\n defaultConfiguration.headers\n ),\n url:\n validateUserProvidedUrl(userProvidedConfiguration.url) ??\n fallbackConfiguration.url ??\n defaultConfiguration.url,\n };\n}\n\nexport function getHttpConfigurationDefaults(\n requiredHeaders: Record<string, string>,\n signalResourcePath: string\n): OtlpHttpConfiguration {\n return {\n ...getSharedConfigurationDefaults(),\n headers: async () => requiredHeaders,\n url: 'http://localhost:4318/' + signalResourcePath,\n };\n}\n"]}
|
|
@@ -16,6 +16,12 @@ export interface OtlpNodeHttpConfiguration extends OtlpHttpConfiguration {
|
|
|
16
16
|
* module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.
|
|
17
17
|
*/
|
|
18
18
|
agentFactory: HttpAgentFactory;
|
|
19
|
+
/**
|
|
20
|
+
* User agent header string to be appended to the exporter's value as a prefix.
|
|
21
|
+
* Availablie since v1.49.0 of the spec.
|
|
22
|
+
* Ref: https://opentelemetry.io/docs/specs/otel/protocol/exporter/#user-agent
|
|
23
|
+
*/
|
|
24
|
+
userAgent?: string;
|
|
19
25
|
}
|
|
20
26
|
export declare function httpAgentFactoryFromOptions(options: http.AgentOptions | https.AgentOptions): HttpAgentFactory;
|
|
21
27
|
/**
|
|
@@ -16,8 +16,14 @@
|
|
|
16
16
|
import { getHttpConfigurationDefaults, mergeOtlpHttpConfigurationWithDefaults, } from './otlp-http-configuration';
|
|
17
17
|
export function httpAgentFactoryFromOptions(options) {
|
|
18
18
|
return async (protocol) => {
|
|
19
|
-
const
|
|
19
|
+
const isInsecure = protocol === 'http:';
|
|
20
|
+
const module = isInsecure ? import('http') : import('https');
|
|
20
21
|
const { Agent } = await module;
|
|
22
|
+
if (isInsecure) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- these props should not be used in agent options
|
|
24
|
+
const { ca, cert, key, ...insecureOptions } = options;
|
|
25
|
+
return new Agent(insecureOptions);
|
|
26
|
+
}
|
|
21
27
|
return new Agent(options);
|
|
22
28
|
};
|
|
23
29
|
}
|
|
@@ -32,6 +38,7 @@ export function mergeOtlpNodeHttpConfigurationWithDefaults(userProvidedConfigura
|
|
|
32
38
|
agentFactory: userProvidedConfiguration.agentFactory ??
|
|
33
39
|
fallbackConfiguration.agentFactory ??
|
|
34
40
|
defaultConfiguration.agentFactory,
|
|
41
|
+
userAgent: userProvidedConfiguration.userAgent,
|
|
35
42
|
};
|
|
36
43
|
}
|
|
37
44
|
export function getNodeHttpConfigurationDefaults(requiredHeaders, signalResourcePath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-node-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-node-http-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GAEvC,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"otlp-node-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-node-http-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GAEvC,MAAM,2BAA2B,CAAC;AA8BnC,MAAM,UAAU,2BAA2B,CACzC,OAA+C;IAE/C,OAAO,KAAK,EAAC,QAAQ,EAAC,EAAE;QACtB,MAAM,UAAU,GAAG,QAAQ,KAAK,OAAO,CAAC;QACxC,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;QAE/B,IAAI,UAAU,EAAE;YACd,gHAAgH;YAChH,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,eAAe,EAAE,GACzC,OAA6B,CAAC;YAChC,OAAO,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;SACnC;QACD,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0CAA0C,CACxD,yBAA6D,EAC7D,qBAAyD,EACzD,oBAA+C;IAE/C,OAAO;QACL,GAAG,sCAAsC,CACvC,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,CACrB;QACD,YAAY,EACV,yBAAyB,CAAC,YAAY;YACtC,qBAAqB,CAAC,YAAY;YAClC,oBAAoB,CAAC,YAAY;QACnC,SAAS,EAAE,yBAAyB,CAAC,SAAS;KAC/C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,eAAuC,EACvC,kBAA0B;IAE1B,OAAO;QACL,GAAG,4BAA4B,CAAC,eAAe,EAAE,kBAAkB,CAAC;QACpE,YAAY,EAAE,2BAA2B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC","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 {\n getHttpConfigurationDefaults,\n mergeOtlpHttpConfigurationWithDefaults,\n OtlpHttpConfiguration,\n} from './otlp-http-configuration';\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 OtlpNodeHttpConfiguration extends OtlpHttpConfiguration {\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 * User agent header string to be appended to the exporter's value as a prefix.\n * Availablie since v1.49.0 of the spec.\n * Ref: https://opentelemetry.io/docs/specs/otel/protocol/exporter/#user-agent\n */\n userAgent?: string;\n}\n\nexport function httpAgentFactoryFromOptions(\n options: http.AgentOptions | https.AgentOptions\n): HttpAgentFactory {\n return async protocol => {\n const isInsecure = protocol === 'http:';\n const module = isInsecure ? import('http') : import('https');\n const { Agent } = await module;\n\n if (isInsecure) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- these props should not be used in agent options\n const { ca, cert, key, ...insecureOptions } =\n options as https.AgentOptions;\n return new Agent(insecureOptions);\n }\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 mergeOtlpNodeHttpConfigurationWithDefaults(\n userProvidedConfiguration: Partial<OtlpNodeHttpConfiguration>,\n fallbackConfiguration: Partial<OtlpNodeHttpConfiguration>,\n defaultConfiguration: OtlpNodeHttpConfiguration\n): OtlpNodeHttpConfiguration {\n return {\n ...mergeOtlpHttpConfigurationWithDefaults(\n userProvidedConfiguration,\n fallbackConfiguration,\n defaultConfiguration\n ),\n agentFactory:\n userProvidedConfiguration.agentFactory ??\n fallbackConfiguration.agentFactory ??\n defaultConfiguration.agentFactory,\n userAgent: userProvidedConfiguration.userAgent,\n };\n}\n\nexport function getNodeHttpConfigurationDefaults(\n requiredHeaders: Record<string, string>,\n signalResourcePath: string\n): OtlpNodeHttpConfiguration {\n return {\n ...getHttpConfigurationDefaults(requiredHeaders, signalResourcePath),\n agentFactory: httpAgentFactoryFromOptions({ keepAlive: true }),\n };\n}\n"]}
|
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import * as fs from 'fs';
|
|
17
|
+
import * as path from 'path';
|
|
16
18
|
import { getStringFromEnv, parseKeyPairsIntoRecord } from '@opentelemetry/core';
|
|
17
19
|
import { diag } from '@opentelemetry/api';
|
|
18
20
|
import { getSharedConfigurationFromEnvironment } from './shared-env-configuration';
|
|
19
21
|
import { wrapStaticHeadersInFunction } from './shared-configuration';
|
|
22
|
+
import { httpAgentFactoryFromOptions, } from './otlp-node-http-configuration';
|
|
20
23
|
function getStaticHeadersFromEnv(signalIdentifier) {
|
|
21
24
|
const signalSpecificRawHeaders = getStringFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`);
|
|
22
25
|
const nonSignalSpecificRawHeaders = getStringFromEnv('OTEL_EXPORTER_OTLP_HEADERS');
|
|
@@ -78,6 +81,32 @@ function getSpecificUrlFromEnv(signalIdentifier) {
|
|
|
78
81
|
}
|
|
79
82
|
return appendRootPathToUrlIfNeeded(envUrl);
|
|
80
83
|
}
|
|
84
|
+
function readFileFromEnv(signalSpecificEnvVar, nonSignalSpecificEnvVar, warningMessage) {
|
|
85
|
+
const signalSpecificPath = getStringFromEnv(signalSpecificEnvVar);
|
|
86
|
+
const nonSignalSpecificPath = getStringFromEnv(nonSignalSpecificEnvVar);
|
|
87
|
+
const filePath = signalSpecificPath ?? nonSignalSpecificPath;
|
|
88
|
+
if (filePath != null) {
|
|
89
|
+
try {
|
|
90
|
+
return fs.readFileSync(path.resolve(process.cwd(), filePath));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
diag.warn(warningMessage);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getClientCertificateFromEnv(signalIdentifier) {
|
|
102
|
+
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE', 'Failed to read client certificate chain file');
|
|
103
|
+
}
|
|
104
|
+
function getClientKeyFromEnv(signalIdentifier) {
|
|
105
|
+
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_KEY`, 'OTEL_EXPORTER_OTLP_CLIENT_KEY', 'Failed to read client certificate private key file');
|
|
106
|
+
}
|
|
107
|
+
function getRootCertificateFromEnv(signalIdentifier) {
|
|
108
|
+
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CERTIFICATE', 'Failed to read root certificate file');
|
|
109
|
+
}
|
|
81
110
|
/**
|
|
82
111
|
* Reads and returns configuration from the environment
|
|
83
112
|
*
|
|
@@ -90,6 +119,12 @@ export function getNodeHttpConfigurationFromEnvironment(signalIdentifier, signal
|
|
|
90
119
|
url: getSpecificUrlFromEnv(signalIdentifier) ??
|
|
91
120
|
getNonSpecificUrlFromEnv(signalResourcePath),
|
|
92
121
|
headers: wrapStaticHeadersInFunction(getStaticHeadersFromEnv(signalIdentifier)),
|
|
122
|
+
agentFactory: httpAgentFactoryFromOptions({
|
|
123
|
+
keepAlive: true,
|
|
124
|
+
ca: getRootCertificateFromEnv(signalIdentifier),
|
|
125
|
+
cert: getClientCertificateFromEnv(signalIdentifier),
|
|
126
|
+
key: getClientKeyFromEnv(signalIdentifier),
|
|
127
|
+
}),
|
|
93
128
|
};
|
|
94
129
|
}
|
|
95
130
|
//# sourceMappingURL=otlp-node-http-env-configuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-node-http-env-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-node-http-env-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,qCAAqC,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"otlp-node-http-env-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-node-http-env-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,qCAAqC,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAEL,2BAA2B,GAC5B,MAAM,gCAAgC,CAAC;AAExC,SAAS,uBAAuB,CAC9B,gBAAwB;IAExB,MAAM,wBAAwB,GAAG,gBAAgB,CAC/C,sBAAsB,gBAAgB,UAAU,CACjD,CAAC;IACF,MAAM,2BAA2B,GAAG,gBAAgB,CAClD,4BAA4B,CAC7B,CAAC;IAEF,MAAM,qBAAqB,GAAG,uBAAuB,CACnD,wBAAwB,CACzB,CAAC;IACF,MAAM,wBAAwB,GAAG,uBAAuB,CACtD,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,uBAAuB,CAAC,2BAA2B,CAAC,EACpD,uBAAuB,CAAC,wBAAwB,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,GAAW;I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C,OAAO,EAAE,2BAA2B,CAClC,uBAAuB,CAAC,gBAAgB,CAAC,CAC1C;QACD,YAAY,EAAE,2BAA2B,CAAC;YACxC,SAAS,EAAE,IAAI;YACf,EAAE,EAAE,yBAAyB,CAAC,gBAAgB,CAAC;YAC/C,IAAI,EAAE,2BAA2B,CAAC,gBAAgB,CAAC;YACnD,GAAG,EAAE,mBAAmB,CAAC,gBAAgB,CAAC;SAC3C,CAAC;KACH,CAAC;AACJ,CAAC","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 fs from 'fs';\nimport * as path from 'path';\nimport { getStringFromEnv, parseKeyPairsIntoRecord } from '@opentelemetry/core';\nimport { diag } from '@opentelemetry/api';\nimport { getSharedConfigurationFromEnvironment } from './shared-env-configuration';\nimport { wrapStaticHeadersInFunction } from './shared-configuration';\nimport {\n OtlpNodeHttpConfiguration,\n httpAgentFactoryFromOptions,\n} from './otlp-node-http-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\nfunction readFileFromEnv(\n signalSpecificEnvVar: string,\n nonSignalSpecificEnvVar: string,\n warningMessage: string\n): Buffer | undefined {\n const signalSpecificPath = getStringFromEnv(signalSpecificEnvVar);\n const nonSignalSpecificPath = getStringFromEnv(nonSignalSpecificEnvVar);\n const filePath = signalSpecificPath ?? nonSignalSpecificPath;\n\n if (filePath != null) {\n try {\n return fs.readFileSync(path.resolve(process.cwd(), filePath));\n } catch {\n diag.warn(warningMessage);\n return undefined;\n }\n } else {\n return undefined;\n }\n}\n\nfunction getClientCertificateFromEnv(\n signalIdentifier: string\n): Buffer | undefined {\n return readFileFromEnv(\n `OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_CERTIFICATE`,\n 'OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE',\n 'Failed to read client certificate chain file'\n );\n}\n\nfunction getClientKeyFromEnv(signalIdentifier: string): Buffer | undefined {\n return readFileFromEnv(\n `OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_KEY`,\n 'OTEL_EXPORTER_OTLP_CLIENT_KEY',\n 'Failed to read client certificate private key file'\n );\n}\n\nfunction getRootCertificateFromEnv(\n signalIdentifier: string\n): Buffer | undefined {\n return readFileFromEnv(\n `OTEL_EXPORTER_OTLP_${signalIdentifier}_CERTIFICATE`,\n 'OTEL_EXPORTER_OTLP_CERTIFICATE',\n 'Failed to read root certificate file'\n );\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 getNodeHttpConfigurationFromEnvironment(\n signalIdentifier: string,\n signalResourcePath: string\n): Partial<OtlpNodeHttpConfiguration> {\n return {\n ...getSharedConfigurationFromEnvironment(signalIdentifier),\n url:\n getSpecificUrlFromEnv(signalIdentifier) ??\n getNonSpecificUrlFromEnv(signalResourcePath),\n headers: wrapStaticHeadersInFunction(\n getStaticHeadersFromEnv(signalIdentifier)\n ),\n agentFactory: httpAgentFactoryFromOptions({\n keepAlive: true,\n ca: getRootCertificateFromEnv(signalIdentifier),\n cert: getClientCertificateFromEnv(signalIdentifier),\n key: getClientKeyFromEnv(signalIdentifier),\n }),\n };\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HeadersFactory } from './otlp-http-configuration';
|
|
1
2
|
/**
|
|
2
3
|
* Configuration shared across all OTLP exporters
|
|
3
4
|
*
|
|
@@ -12,7 +13,7 @@ export interface OtlpSharedConfiguration {
|
|
|
12
13
|
compression: 'gzip' | 'none';
|
|
13
14
|
}
|
|
14
15
|
export declare function validateTimeoutMillis(timeoutMillis: number): number;
|
|
15
|
-
export declare function wrapStaticHeadersInFunction(headers: Record<string, string> | undefined):
|
|
16
|
+
export declare function wrapStaticHeadersInFunction(headers: Record<string, string> | undefined): HeadersFactory | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
18
19
|
* @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
|
|
@@ -23,7 +23,7 @@ export function wrapStaticHeadersInFunction(headers) {
|
|
|
23
23
|
if (headers == null) {
|
|
24
24
|
return undefined;
|
|
25
25
|
}
|
|
26
|
-
return () => headers;
|
|
26
|
+
return async () => headers;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @param userProvidedConfiguration Configuration options provided by the user in code.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-configuration.js","sourceRoot":"","sources":["../../../src/configuration/shared-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"shared-configuration.js","sourceRoot":"","sources":["../../../src/configuration/shared-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,MAAM,UAAU,qBAAqB,CAAC,aAAqB;IACzD,IAAI,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE;QACvD,OAAO,aAAa,CAAC;KACtB;IACD,MAAM,IAAI,KAAK,CACb,qFAAqF,aAAa,IAAI,CACvG,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,OAA2C;IAE3C,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CACtD,yBAA2D,EAC3D,qBAAuD,EACvD,oBAA6C;IAE7C,OAAO;QACL,aAAa,EAAE,qBAAqB,CAClC,yBAAyB,CAAC,aAAa;YACrC,qBAAqB,CAAC,aAAa;YACnC,oBAAoB,CAAC,aAAa,CACrC;QACD,gBAAgB,EACd,yBAAyB,CAAC,gBAAgB;YAC1C,qBAAqB,CAAC,gBAAgB;YACtC,oBAAoB,CAAC,gBAAgB;QACvC,WAAW,EACT,yBAAyB,CAAC,WAAW;YACrC,qBAAqB,CAAC,WAAW;YACjC,oBAAoB,CAAC,WAAW;KACnC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,OAAO;QACL,aAAa,EAAE,KAAK;QACpB,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,MAAM;KACpB,CAAC;AACJ,CAAC","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 { HeadersFactory } from './otlp-http-configuration';\n\n/**\n * Configuration shared across all OTLP exporters\n *\n * Implementation note: anything added here MUST be\n * - platform-agnostic\n * - signal-agnostic\n * - transport-agnostic\n */\nexport interface OtlpSharedConfiguration {\n timeoutMillis: number;\n concurrencyLimit: number;\n compression: 'gzip' | 'none';\n}\n\nexport function validateTimeoutMillis(timeoutMillis: number) {\n if (Number.isFinite(timeoutMillis) && timeoutMillis > 0) {\n return timeoutMillis;\n }\n throw new Error(\n `Configuration: timeoutMillis is invalid, expected number greater than 0 (actual: '${timeoutMillis}')`\n );\n}\n\nexport function wrapStaticHeadersInFunction(\n headers: Record<string, string> | undefined\n): HeadersFactory | undefined {\n if (headers == null) {\n return undefined;\n }\n\n return async () => headers;\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 mergeOtlpSharedConfigurationWithDefaults(\n userProvidedConfiguration: Partial<OtlpSharedConfiguration>,\n fallbackConfiguration: Partial<OtlpSharedConfiguration>,\n defaultConfiguration: OtlpSharedConfiguration\n): OtlpSharedConfiguration {\n return {\n timeoutMillis: validateTimeoutMillis(\n userProvidedConfiguration.timeoutMillis ??\n fallbackConfiguration.timeoutMillis ??\n defaultConfiguration.timeoutMillis\n ),\n concurrencyLimit:\n userProvidedConfiguration.concurrencyLimit ??\n fallbackConfiguration.concurrencyLimit ??\n defaultConfiguration.concurrencyLimit,\n compression:\n userProvidedConfiguration.compression ??\n fallbackConfiguration.compression ??\n defaultConfiguration.compression,\n };\n}\n\nexport function getSharedConfigurationDefaults(): OtlpSharedConfiguration {\n return {\n timeoutMillis: 10000,\n concurrencyLimit: 30,\n compression: 'none',\n };\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export function createOtlpSendBeaconExportDelegate(options, serializer) {
|
|
|
20
20
|
return createOtlpNetworkExportDelegate(options, serializer, createRetryingTransport({
|
|
21
21
|
transport: createSendBeaconTransport({
|
|
22
22
|
url: options.url,
|
|
23
|
-
|
|
23
|
+
headers: options.headers,
|
|
24
24
|
}),
|
|
25
25
|
}));
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-browser-http-export-delegate.js","sourceRoot":"","sources":["../../src/otlp-browser-http-export-delegate.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACvC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,oBAAoB,CAAC,OAAO,CAAC;KACzC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,yBAAyB,CAAC;YACnC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,
|
|
1
|
+
{"version":3,"file":"otlp-browser-http-export-delegate.js","sourceRoot":"","sources":["../../src/otlp-browser-http-export-delegate.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACvC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,oBAAoB,CAAC,OAAO,CAAC;KACzC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,OAA8B,EAC9B,UAA2C;IAE3C,OAAO,+BAA+B,CACpC,OAAO,EACP,UAAU,EACV,uBAAuB,CAAC;QACtB,SAAS,EAAE,yBAAyB,CAAC;YACnC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;KACH,CAAC,CACH,CAAC;AACJ,CAAC","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 headers: options.headers,\n }),\n })\n );\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IExporterTransport } from '../exporter-transport';
|
|
2
|
+
import { HeadersFactory } from '../configuration/otlp-http-configuration';
|
|
2
3
|
export interface FetchTransportParameters {
|
|
3
4
|
url: string;
|
|
4
|
-
headers:
|
|
5
|
+
headers: HeadersFactory;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
8
|
* Creates an exporter transport that uses `fetch` to send the data
|
|
@@ -28,7 +28,7 @@ class FetchTransport {
|
|
|
28
28
|
const url = new URL(this._parameters.url);
|
|
29
29
|
const response = await fetch(url.href, {
|
|
30
30
|
method: 'POST',
|
|
31
|
-
headers: this._parameters.headers(),
|
|
31
|
+
headers: await this._parameters.headers(),
|
|
32
32
|
body: data,
|
|
33
33
|
signal: abortController.signal,
|
|
34
34
|
keepalive: isBrowserEnvironment,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-transport.js","sourceRoot":"","sources":["../../../src/transport/fetch-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-transport.js","sourceRoot":"","sources":["../../../src/transport/fetch-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAQhC,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,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;gBACzC,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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AAC","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';\nimport { HeadersFactory } from '../configuration/otlp-http-configuration';\n\nexport interface FetchTransportParameters {\n url: string;\n headers: HeadersFactory;\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: await 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"]}
|
|
@@ -22,8 +22,9 @@ class HttpExporterTransport {
|
|
|
22
22
|
}
|
|
23
23
|
async send(data, timeoutMillis) {
|
|
24
24
|
const { agent, request } = await this._loadUtils();
|
|
25
|
+
const headers = await this._parameters.headers();
|
|
25
26
|
return new Promise(resolve => {
|
|
26
|
-
sendWithHttp(request, this._parameters, agent, data, result => {
|
|
27
|
+
sendWithHttp(request, this._parameters.url, headers, this._parameters.compression, this._parameters.userAgent, agent, data, result => {
|
|
27
28
|
resolve(result);
|
|
28
29
|
}, timeoutMillis);
|
|
29
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQtD,MAAM,qBAAqB;IAGL;IAFZ,MAAM,GAAiB,IAAI,CAAC;IAEpC,YAAoB,WAAsC;QAAtC,gBAAW,GAAX,WAAW,CAA2B;IAAG,CAAC;IAE9D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQtD,MAAM,qBAAqB;IAGL;IAFZ,MAAM,GAAiB,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hB,MAAM,MAAM,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAqC;IAErC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC","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 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';\nimport { sendWithHttp } from './http-transport-utils';\nimport { NodeHttpRequestParameters } from './node-http-transport-types';\n\ninterface Utils {\n agent: http.Agent | https.Agent;\n request: typeof http.request | typeof https.request;\n}\n\nclass HttpExporterTransport implements IExporterTransport {\n private _utils: Utils | null = null;\n\n constructor(private _parameters: NodeHttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const { agent, request } = await this._loadUtils();\n const headers = await this._parameters.headers();\n\n return new Promise<ExportResponse>(resolve => {\n sendWithHttp(\n request,\n this._parameters.url,\n headers,\n this._parameters.compression,\n this._parameters.userAgent,\n agent,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n\n private async _loadUtils(): Promise<Utils> {\n let utils = this._utils;\n\n if (utils === null) {\n const protocol = new URL(this._parameters.url).protocol;\n const [agent, request] = await Promise.all([\n this._parameters.agentFactory(protocol),\n requestFunctionFactory(protocol),\n ]);\n utils = this._utils = { agent, request };\n }\n\n return utils;\n }\n}\n\nasync function requestFunctionFactory(\n protocol: string\n): Promise<typeof http.request | typeof https.request> {\n const module = protocol === 'http:' ? import('http') : import('https');\n const { request } = await module;\n return request;\n}\n\nexport function createHttpExporterTransport(\n parameters: NodeHttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { HeadersFactory } from '../configuration/otlp-http-configuration';
|
|
1
2
|
export interface HttpRequestParameters {
|
|
2
3
|
url: string;
|
|
3
|
-
headers:
|
|
4
|
+
headers: HeadersFactory;
|
|
4
5
|
compression: 'gzip' | 'none';
|
|
6
|
+
userAgent?: string;
|
|
5
7
|
}
|
|
6
8
|
//# sourceMappingURL=http-transport-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../src/transport/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\nexport interface HttpRequestParameters {\n url: string;\n headers:
|
|
1
|
+
{"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../src/transport/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 { HeadersFactory } from '../configuration/otlp-http-configuration';\n\nexport interface HttpRequestParameters {\n url: string;\n headers: HeadersFactory;\n compression: 'gzip' | 'none';\n userAgent?: string;\n}\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type * as http from 'http';
|
|
4
4
|
import type * as https from 'https';
|
|
5
|
-
import { HttpRequestParameters } from './http-transport-types';
|
|
6
5
|
import { ExportResponse } from '../export-response';
|
|
7
6
|
/**
|
|
8
7
|
* Sends data using http
|
|
@@ -13,6 +12,6 @@ import { ExportResponse } from '../export-response';
|
|
|
13
12
|
* @param onDone
|
|
14
13
|
* @param timeoutMillis
|
|
15
14
|
*/
|
|
16
|
-
export declare function sendWithHttp(request: typeof https.request | typeof http.request,
|
|
15
|
+
export declare function sendWithHttp(request: typeof https.request | typeof http.request, url: string, headers: Record<string, string>, compression: 'gzip' | 'none', userAgent: string | undefined, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
|
|
17
16
|
export declare function compressAndSend(req: http.ClientRequest, compression: 'gzip' | 'none', data: Uint8Array, onError: (error: Error) => void): void;
|
|
18
17
|
//# sourceMappingURL=http-transport-utils.d.ts.map
|
|
@@ -2,6 +2,8 @@ import * as zlib from 'zlib';
|
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
|
|
4
4
|
import { OTLPExporterError } from '../types';
|
|
5
|
+
import { VERSION } from '../version';
|
|
6
|
+
const DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;
|
|
5
7
|
/**
|
|
6
8
|
* Sends data using http
|
|
7
9
|
* @param request
|
|
@@ -11,17 +13,21 @@ import { OTLPExporterError } from '../types';
|
|
|
11
13
|
* @param onDone
|
|
12
14
|
* @param timeoutMillis
|
|
13
15
|
*/
|
|
14
|
-
export function sendWithHttp(request,
|
|
15
|
-
const parsedUrl = new URL(
|
|
16
|
+
export function sendWithHttp(request, url, headers, compression, userAgent, agent, data, onDone, timeoutMillis) {
|
|
17
|
+
const parsedUrl = new URL(url);
|
|
18
|
+
if (userAgent) {
|
|
19
|
+
headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
headers['User-Agent'] = DEFAULT_USER_AGENT;
|
|
23
|
+
}
|
|
16
24
|
const options = {
|
|
17
25
|
hostname: parsedUrl.hostname,
|
|
18
26
|
port: parsedUrl.port,
|
|
19
27
|
path: parsedUrl.pathname,
|
|
20
28
|
method: 'POST',
|
|
21
|
-
headers
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
agent: agent,
|
|
29
|
+
headers,
|
|
30
|
+
agent,
|
|
25
31
|
};
|
|
26
32
|
const req = request(options, (res) => {
|
|
27
33
|
const responseData = [];
|
|
@@ -61,7 +67,7 @@ export function sendWithHttp(request, params, agent, data, onDone, timeoutMillis
|
|
|
61
67
|
error,
|
|
62
68
|
});
|
|
63
69
|
});
|
|
64
|
-
compressAndSend(req,
|
|
70
|
+
compressAndSend(req, compression, data, (error) => {
|
|
65
71
|
onDone({
|
|
66
72
|
status: 'failure',
|
|
67
73
|
error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAi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AEH,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,KAAY,EAAE,EAAE;QACvD,MAAM,CAAC;YACL,MAAM,EAAE,SAAS;YACjB,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAuB,EACvB,WAA4B,EAC5B,IAAgB,EAChB,OAA+B;IAE/B,IAAI,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAE9C,IAAI,WAAW,KAAK,MAAM,EAAE;QAC1B,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QAC1C,UAAU,GAAG,UAAU;aACpB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;aACpB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;aACvB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC","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 type * as http from 'http';\nimport type * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { ExportResponse } from '../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\nimport { VERSION } from '../version';\n\nconst DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION}`;\n\n/**\n * Sends data using http\n * @param request\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n request: typeof https.request | typeof http.request,\n url: string,\n headers: Record<string, string>,\n compression: 'gzip' | 'none',\n userAgent: string | undefined,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(url);\n\n if (userAgent) {\n headers['User-Agent'] = `${userAgent} ${DEFAULT_USER_AGENT}`;\n } else {\n headers['User-Agent'] = DEFAULT_USER_AGENT;\n }\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers,\n agent,\n };\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n 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(\n res.statusMessage,\n res.statusCode,\n Buffer.concat(responseData).toString()\n );\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\n req.on('error', (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n\n compressAndSend(req, compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\nexport function compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req).on('error', onError);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { IExporterTransport } from '../exporter-transport';
|
|
2
|
+
import { HeadersFactory } from '../configuration/otlp-http-configuration';
|
|
2
3
|
export interface SendBeaconParameters {
|
|
3
4
|
url: string;
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Only `Content-Type` will be used, sendBeacon does not support custom headers
|
|
7
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
|
|
6
8
|
*/
|
|
7
|
-
|
|
9
|
+
headers: HeadersFactory;
|
|
8
10
|
}
|
|
9
11
|
export declare function createSendBeaconTransport(parameters: SendBeaconParameters): IExporterTransport;
|
|
10
12
|
//# sourceMappingURL=send-beacon-transport.d.ts.map
|
|
@@ -19,9 +19,10 @@ class SendBeaconTransport {
|
|
|
19
19
|
constructor(_params) {
|
|
20
20
|
this._params = _params;
|
|
21
21
|
}
|
|
22
|
-
send(data) {
|
|
22
|
+
async send(data) {
|
|
23
|
+
const blobType = (await this._params.headers())['Content-Type'];
|
|
23
24
|
return new Promise(resolve => {
|
|
24
|
-
if (navigator.sendBeacon(this._params.url, new Blob([data], { type:
|
|
25
|
+
if (navigator.sendBeacon(this._params.url, new Blob([data], { type: blobType }))) {
|
|
25
26
|
// no way to signal retry, treat everything as success
|
|
26
27
|
diag.debug('SendBeacon success');
|
|
27
28
|
resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../src/transport/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../src/transport/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAY1C,MAAM,mBAAmB;IACH;IAApB,YAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,KAAK,CAAC,IAAI,CAAC,IAAgB;QACzB,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC;QAChE,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,IACE,SAAS,CAAC,UAAU,CAClB,IAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CACrC,EACD;gBACA,sDAAsD;gBACtD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","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 { HeadersFactory } from '../configuration/otlp-http-configuration';\n\nexport interface SendBeaconParameters {\n url: string;\n /**\n * Only `Content-Type` will be used, sendBeacon does not support custom headers\n * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon\n */\n headers: HeadersFactory;\n}\n\nclass SendBeaconTransport implements IExporterTransport {\n constructor(private _params: SendBeaconParameters) {}\n async send(data: Uint8Array): Promise<ExportResponse> {\n const blobType = (await this._params.headers())['Content-Type'];\n return new Promise<ExportResponse>(resolve => {\n if (\n navigator.sendBeacon(\n this._params.url,\n new Blob([data], { type: blobType })\n )\n ) {\n // no way to signal retry, treat everything as success\n diag.debug('SendBeacon success');\n resolve({\n status: 'success',\n });\n } else {\n resolve({\n status: 'failure',\n error: new Error('SendBeacon failed'),\n });\n }\n });\n }\n\n shutdown(): void {\n // Intentionally left empty, nothing to do.\n }\n}\n\nexport function createSendBeaconTransport(\n parameters: SendBeaconParameters\n): IExporterTransport {\n return new SendBeaconTransport(parameters);\n}\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IExporterTransport } from '../exporter-transport';
|
|
2
|
+
import { HeadersFactory } from '../configuration/otlp-http-configuration';
|
|
2
3
|
/**
|
|
3
4
|
* @deprecated favor the fetch transport
|
|
4
5
|
* @see {@link createFetchTransport}
|
|
5
6
|
*/
|
|
6
7
|
export interface XhrRequestParameters {
|
|
7
8
|
url: string;
|
|
8
|
-
headers:
|
|
9
|
+
headers: HeadersFactory;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* @deprecated use {@link createFetchTransport} instead
|
|
@@ -20,12 +20,12 @@ class XhrTransport {
|
|
|
20
20
|
constructor(_parameters) {
|
|
21
21
|
this._parameters = _parameters;
|
|
22
22
|
}
|
|
23
|
-
send(data, timeoutMillis) {
|
|
24
|
-
|
|
23
|
+
async send(data, timeoutMillis) {
|
|
24
|
+
const headers = await this._parameters.headers();
|
|
25
|
+
const response = await new Promise(resolve => {
|
|
25
26
|
const xhr = new XMLHttpRequest();
|
|
26
27
|
xhr.timeout = timeoutMillis;
|
|
27
28
|
xhr.open('POST', this._parameters.url);
|
|
28
|
-
const headers = this._parameters.headers();
|
|
29
29
|
Object.entries(headers).forEach(([k, v]) => {
|
|
30
30
|
xhr.setRequestHeader(k, v);
|
|
31
31
|
});
|
|
@@ -69,6 +69,7 @@ class XhrTransport {
|
|
|
69
69
|
};
|
|
70
70
|
xhr.send(data);
|
|
71
71
|
});
|
|
72
|
+
return response;
|
|
72
73
|
}
|
|
73
74
|
shutdown() {
|
|
74
75
|
// Intentionally left empty, nothing to do.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xhr-transport.js","sourceRoot":"","sources":["../../../src/transport/xhr-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"xhr-transport.js","sourceRoot":"","sources":["../../../src/transport/xhr-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC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E,sBAAsB,CACnC,GAAG,CAAC,iBAAiB,CAAC,aAAa,CAAC,CACrC;qBACF,CAAC,CAAC;iBACJ;qBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC3B,OAAO,CAAC;wBACN,MAAM,EAAE,SAAS;wBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,8CAA8C,CAAC;qBACjE,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC;YAEF,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE;gBACjB,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,qBAAqB,CAAC;iBACxC,CAAC,CAAC;YACL,CAAC,CAAC;YACF,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE;gBACjB,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,qBAAqB,CAAC;iBACxC,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAgC;IAEhC,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC","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// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { createFetchTransport } from './fetch-transport';\nimport { HeadersFactory } from '../configuration/otlp-http-configuration';\n\n/**\n * @deprecated favor the fetch transport\n * @see {@link createFetchTransport}\n */\nexport interface XhrRequestParameters {\n url: string;\n headers: HeadersFactory;\n}\n\nclass XhrTransport implements IExporterTransport {\n constructor(private _parameters: XhrRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const headers = await this._parameters.headers();\n const response = await new Promise<ExportResponse>(resolve => {\n const xhr = new XMLHttpRequest();\n xhr.timeout = timeoutMillis;\n xhr.open('POST', this._parameters.url);\n Object.entries(headers).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.ontimeout = _ => {\n resolve({\n status: 'failure',\n error: new Error('XHR request timed out'),\n });\n };\n\n xhr.onreadystatechange = () => {\n if (xhr.status >= 200 && xhr.status <= 299) {\n diag.debug('XHR success');\n resolve({\n status: 'success',\n });\n } else if (xhr.status && isExportRetryable(xhr.status)) {\n resolve({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(\n xhr.getResponseHeader('Retry-After')\n ),\n });\n } else if (xhr.status !== 0) {\n resolve({\n status: 'failure',\n error: new Error('XHR request failed with non-retryable status'),\n });\n }\n };\n\n xhr.onabort = () => {\n resolve({\n status: 'failure',\n error: new Error('XHR request aborted'),\n });\n };\n xhr.onerror = () => {\n resolve({\n status: 'failure',\n error: new Error('XHR request errored'),\n });\n };\n\n xhr.send(data);\n });\n\n return response;\n }\n\n shutdown() {\n // Intentionally left empty, nothing to do.\n }\n}\n\n/**\n * @deprecated use {@link createFetchTransport} instead\n *\n * Creates an exporter transport that uses XHR to send the data\n * @param parameters applied to each request made by transport\n */\nexport function createXhrTransport(\n parameters: XhrRequestParameters\n): IExporterTransport {\n return new XhrTransport(parameters);\n}\n"]}
|