@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.
Files changed (109) hide show
  1. package/build/esm/bounded-queue-export-promise-handler.js +1 -1
  2. package/build/esm/bounded-queue-export-promise-handler.js.map +1 -1
  3. package/build/esm/configuration/convert-legacy-node-http-options.js +14 -18
  4. package/build/esm/configuration/convert-legacy-node-http-options.js.map +1 -1
  5. package/build/esm/configuration/create-legacy-browser-delegate.d.ts +2 -0
  6. package/build/esm/configuration/create-legacy-browser-delegate.js +11 -5
  7. package/build/esm/configuration/create-legacy-browser-delegate.js.map +1 -1
  8. package/build/esm/configuration/legacy-node-configuration.d.ts +25 -2
  9. package/build/esm/configuration/legacy-node-configuration.js.map +1 -1
  10. package/build/esm/configuration/otlp-http-configuration.d.ts +13 -1
  11. package/build/esm/configuration/otlp-http-configuration.js +15 -7
  12. package/build/esm/configuration/otlp-http-configuration.js.map +1 -1
  13. package/build/esm/configuration/otlp-http-env-configuration.js +7 -7
  14. package/build/esm/configuration/otlp-http-env-configuration.js.map +1 -1
  15. package/build/esm/index-node-http.d.ts +1 -0
  16. package/build/esm/index-node-http.js +1 -0
  17. package/build/esm/index-node-http.js.map +1 -1
  18. package/build/esm/otlp-browser-http-export-delegate.d.ts +4 -0
  19. package/build/esm/otlp-browser-http-export-delegate.js +9 -0
  20. package/build/esm/otlp-browser-http-export-delegate.js.map +1 -1
  21. package/build/esm/transport/fetch-transport.d.ts +11 -0
  22. package/build/esm/transport/fetch-transport.js +82 -0
  23. package/build/esm/transport/fetch-transport.js.map +1 -0
  24. package/build/esm/transport/http-exporter-transport.js +15 -11
  25. package/build/esm/transport/http-exporter-transport.js.map +1 -1
  26. package/build/esm/transport/http-transport-types.d.ts +2 -7
  27. package/build/esm/transport/http-transport-types.js.map +1 -1
  28. package/build/esm/transport/http-transport-utils.d.ts +4 -4
  29. package/build/esm/transport/http-transport-utils.js +2 -32
  30. package/build/esm/transport/http-transport-utils.js.map +1 -1
  31. package/build/esm/transport/xhr-transport.d.ts +6 -0
  32. package/build/esm/transport/xhr-transport.js +2 -0
  33. package/build/esm/transport/xhr-transport.js.map +1 -1
  34. package/build/esm/version.d.ts +1 -1
  35. package/build/esm/version.js +1 -1
  36. package/build/esm/version.js.map +1 -1
  37. package/build/esnext/bounded-queue-export-promise-handler.js +1 -1
  38. package/build/esnext/bounded-queue-export-promise-handler.js.map +1 -1
  39. package/build/esnext/configuration/convert-legacy-node-http-options.js +14 -18
  40. package/build/esnext/configuration/convert-legacy-node-http-options.js.map +1 -1
  41. package/build/esnext/configuration/create-legacy-browser-delegate.d.ts +2 -0
  42. package/build/esnext/configuration/create-legacy-browser-delegate.js +11 -5
  43. package/build/esnext/configuration/create-legacy-browser-delegate.js.map +1 -1
  44. package/build/esnext/configuration/legacy-node-configuration.d.ts +25 -2
  45. package/build/esnext/configuration/legacy-node-configuration.js.map +1 -1
  46. package/build/esnext/configuration/otlp-http-configuration.d.ts +13 -1
  47. package/build/esnext/configuration/otlp-http-configuration.js +15 -7
  48. package/build/esnext/configuration/otlp-http-configuration.js.map +1 -1
  49. package/build/esnext/configuration/otlp-http-env-configuration.js +7 -7
  50. package/build/esnext/configuration/otlp-http-env-configuration.js.map +1 -1
  51. package/build/esnext/index-node-http.d.ts +1 -0
  52. package/build/esnext/index-node-http.js +1 -0
  53. package/build/esnext/index-node-http.js.map +1 -1
  54. package/build/esnext/otlp-browser-http-export-delegate.d.ts +4 -0
  55. package/build/esnext/otlp-browser-http-export-delegate.js +9 -0
  56. package/build/esnext/otlp-browser-http-export-delegate.js.map +1 -1
  57. package/build/esnext/transport/fetch-transport.d.ts +11 -0
  58. package/build/esnext/transport/fetch-transport.js +82 -0
  59. package/build/esnext/transport/fetch-transport.js.map +1 -0
  60. package/build/esnext/transport/http-exporter-transport.js +15 -11
  61. package/build/esnext/transport/http-exporter-transport.js.map +1 -1
  62. package/build/esnext/transport/http-transport-types.d.ts +2 -7
  63. package/build/esnext/transport/http-transport-types.js.map +1 -1
  64. package/build/esnext/transport/http-transport-utils.d.ts +4 -4
  65. package/build/esnext/transport/http-transport-utils.js +2 -32
  66. package/build/esnext/transport/http-transport-utils.js.map +1 -1
  67. package/build/esnext/transport/xhr-transport.d.ts +6 -0
  68. package/build/esnext/transport/xhr-transport.js +2 -0
  69. package/build/esnext/transport/xhr-transport.js.map +1 -1
  70. package/build/esnext/version.d.ts +1 -1
  71. package/build/esnext/version.js +1 -1
  72. package/build/esnext/version.js.map +1 -1
  73. package/build/src/bounded-queue-export-promise-handler.js +1 -1
  74. package/build/src/bounded-queue-export-promise-handler.js.map +1 -1
  75. package/build/src/configuration/convert-legacy-node-http-options.js +13 -17
  76. package/build/src/configuration/convert-legacy-node-http-options.js.map +1 -1
  77. package/build/src/configuration/create-legacy-browser-delegate.d.ts +2 -0
  78. package/build/src/configuration/create-legacy-browser-delegate.js +13 -6
  79. package/build/src/configuration/create-legacy-browser-delegate.js.map +1 -1
  80. package/build/src/configuration/legacy-node-configuration.d.ts +25 -2
  81. package/build/src/configuration/legacy-node-configuration.js.map +1 -1
  82. package/build/src/configuration/otlp-http-configuration.d.ts +13 -1
  83. package/build/src/configuration/otlp-http-configuration.js +17 -8
  84. package/build/src/configuration/otlp-http-configuration.js.map +1 -1
  85. package/build/src/configuration/otlp-http-env-configuration.js +6 -6
  86. package/build/src/configuration/otlp-http-env-configuration.js.map +1 -1
  87. package/build/src/index-node-http.d.ts +1 -0
  88. package/build/src/index-node-http.js +3 -1
  89. package/build/src/index-node-http.js.map +1 -1
  90. package/build/src/otlp-browser-http-export-delegate.d.ts +4 -0
  91. package/build/src/otlp-browser-http-export-delegate.js +11 -1
  92. package/build/src/otlp-browser-http-export-delegate.js.map +1 -1
  93. package/build/src/transport/fetch-transport.d.ts +11 -0
  94. package/build/src/transport/fetch-transport.js +86 -0
  95. package/build/src/transport/fetch-transport.js.map +1 -0
  96. package/build/src/transport/http-exporter-transport.js +15 -11
  97. package/build/src/transport/http-exporter-transport.js.map +1 -1
  98. package/build/src/transport/http-transport-types.d.ts +2 -7
  99. package/build/src/transport/http-transport-types.js.map +1 -1
  100. package/build/src/transport/http-transport-utils.d.ts +4 -4
  101. package/build/src/transport/http-transport-utils.js +3 -34
  102. package/build/src/transport/http-transport-utils.js.map +1 -1
  103. package/build/src/transport/xhr-transport.d.ts +6 -0
  104. package/build/src/transport/xhr-transport.js +2 -0
  105. package/build/src/transport/xhr-transport.js.map +1 -1
  106. package/build/src/version.d.ts +1 -1
  107. package/build/src/version.js +1 -1
  108. package/build/src/version.js.map +1 -1
  109. package/package.json +12 -13
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { sendWithHttp } from './http-transport-utils';
16
17
  class HttpExporterTransport {
17
18
  _parameters;
18
19
  _utils = null;
@@ -20,9 +21,9 @@ class HttpExporterTransport {
20
21
  this._parameters = _parameters;
21
22
  }
22
23
  async send(data, timeoutMillis) {
23
- const { agent, send } = this._loadUtils();
24
+ const { agent, request } = await this._loadUtils();
24
25
  return new Promise(resolve => {
25
- send(this._parameters, agent, data, result => {
26
+ sendWithHttp(request, this._parameters, agent, data, result => {
26
27
  resolve(result);
27
28
  }, timeoutMillis);
28
29
  });
@@ -30,21 +31,24 @@ class HttpExporterTransport {
30
31
  shutdown() {
31
32
  // intentionally left empty, nothing to do.
32
33
  }
33
- _loadUtils() {
34
+ async _loadUtils() {
34
35
  let utils = this._utils;
35
36
  if (utils === null) {
36
- // Lazy require to ensure that http/https is not required before instrumentations can wrap it.
37
- const { sendWithHttp, createHttpAgent,
38
- // eslint-disable-next-line @typescript-eslint/no-var-requires
39
- } = require('./http-transport-utils');
40
- utils = this._utils = {
41
- agent: createHttpAgent(this._parameters.url, this._parameters.agentOptions),
42
- send: sendWithHttp,
43
- };
37
+ const protocol = new URL(this._parameters.url).protocol;
38
+ const [agent, request] = await Promise.all([
39
+ this._parameters.agentFactory(protocol),
40
+ requestFunctionFactory(protocol),
41
+ ]);
42
+ utils = this._utils = { agent, request };
44
43
  }
45
44
  return utils;
46
45
  }
47
46
  }
47
+ async function requestFunctionFactory(protocol) {
48
+ const module = protocol === 'http:' ? import('http') : import('https');
49
+ const { request } = await module;
50
+ return request;
51
+ }
48
52
  export function createHttpExporterTransport(parameters) {
49
53
  return new HttpExporterTransport(parameters);
50
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,MAAM,qBAAqB;IAGL;IAFZ,MAAM,GAAiB,IAAI,CAAC;IAEpC,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;IAAG,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAE1C,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,IAAI,CACF,IAAI,CAAC,WAAW,EAChB,KAAK,EACL,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;IAEO,UAAU;QAChB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAExB,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,8FAA8F;YAC9F,MAAM,EACJ,YAAY,EACZ,eAAe;YACf,8DAA8D;cAC/D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;YAEtC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG;gBACpB,KAAK,EAAE,eAAe,CACpB,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B;gBACD,IAAI,EAAE,YAAY;aACnB,CAAC;SACH;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAiC;IAEjC,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\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../export-response';\nimport { IExporterTransport } from '../exporter-transport';\n\ninterface Utils {\n agent: http.Agent | https.Agent;\n send: sendWithHttp;\n}\n\nclass HttpExporterTransport implements IExporterTransport {\n private _utils: Utils | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const { agent, send } = this._loadUtils();\n\n return new Promise<ExportResponse>(resolve => {\n send(\n this._parameters,\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 _loadUtils(): Utils {\n let utils = this._utils;\n\n if (utils === null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n\n utils = this._utils = {\n agent: createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n ),\n send: sendWithHttp,\n };\n }\n\n return utils;\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
1
+ {"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../src/transport/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAOtD,MAAM,qBAAqB;IAGL;IAFZ,MAAM,GAAiB,IAAI,CAAC;IAEpC,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;IAAG,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAEnD,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,YAAY,CACV,OAAO,EACP,IAAI,CAAC,WAAW,EAChB,KAAK,EACL,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;IAEO,KAAK,CAAC,UAAU;QACtB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAExB,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;YACxD,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACzC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC;gBACvC,sBAAsB,CAAC,QAAQ,CAAC;aACjC,CAAC,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC1C;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,KAAK,UAAU,sBAAsB,CACnC,QAAgB;IAEhB,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,UAAiC;IAEjC,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\nimport type { HttpRequestParameters } from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../export-response';\nimport { IExporterTransport } from '../exporter-transport';\nimport { sendWithHttp } from './http-transport-utils';\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: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const { agent, request } = await this._loadUtils();\n\n return new Promise<ExportResponse>(resolve => {\n sendWithHttp(\n request,\n this._parameters,\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: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
@@ -1,13 +1,8 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import type * as http from 'http';
4
- import type * as https from 'https';
5
- import { ExportResponse } from '../export-response';
6
- export type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
1
+ import { HttpAgentFactory } from '../configuration/otlp-http-configuration';
7
2
  export interface HttpRequestParameters {
8
3
  url: string;
9
4
  headers: () => Record<string, string>;
10
5
  compression: 'gzip' | 'none';
11
- agentOptions: http.AgentOptions | https.AgentOptions;
6
+ agentFactory: HttpAgentFactory;
12
7
  }
13
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\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}
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 { HttpAgentFactory } from '../configuration/otlp-http-configuration';\n\nexport interface HttpRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n compression: 'gzip' | 'none';\n agentFactory: HttpAgentFactory;\n}\n"]}
@@ -1,18 +1,18 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import * as http from 'http';
4
- import * as https from 'https';
3
+ import type * as http from 'http';
4
+ import type * as https from 'https';
5
5
  import { HttpRequestParameters } from './http-transport-types';
6
6
  import { ExportResponse } from '../export-response';
7
7
  /**
8
8
  * Sends data using http
9
+ * @param requestFunction
9
10
  * @param params
10
11
  * @param agent
11
12
  * @param data
12
13
  * @param onDone
13
14
  * @param timeoutMillis
14
15
  */
15
- export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
16
+ export declare function sendWithHttp(request: typeof https.request | typeof http.request, params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
16
17
  export declare function compressAndSend(req: http.ClientRequest, compression: 'gzip' | 'none', data: Uint8Array, onError: (error: Error) => void): void;
17
- export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
18
18
  //# sourceMappingURL=http-transport-utils.d.ts.map
@@ -1,35 +1,18 @@
1
- /*
2
- * Copyright The OpenTelemetry Authors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * https://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import * as http from 'http';
17
- import * as https from 'https';
18
1
  import * as zlib from 'zlib';
19
2
  import { Readable } from 'stream';
20
3
  import { isExportRetryable, parseRetryAfterToMills, } from '../is-export-retryable';
21
4
  import { OTLPExporterError } from '../types';
22
5
  /**
23
6
  * Sends data using http
7
+ * @param requestFunction
24
8
  * @param params
25
9
  * @param agent
26
10
  * @param data
27
11
  * @param onDone
28
12
  * @param timeoutMillis
29
13
  */
30
- export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
14
+ export function sendWithHttp(request, params, agent, data, onDone, timeoutMillis) {
31
15
  const parsedUrl = new URL(params.url);
32
- const nodeVersion = Number(process.versions.node.split('.')[0]);
33
16
  const options = {
34
17
  hostname: parsedUrl.hostname,
35
18
  port: parsedUrl.port,
@@ -40,7 +23,6 @@ export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
40
23
  },
41
24
  agent: agent,
42
25
  };
43
- const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
44
26
  const req = request(options, (res) => {
45
27
  const responseData = [];
46
28
  res.on('data', chunk => responseData.push(chunk));
@@ -79,13 +61,6 @@ export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
79
61
  error,
80
62
  });
81
63
  });
82
- const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
83
- req.on(reportTimeoutErrorEvent, () => {
84
- onDone({
85
- status: 'failure',
86
- error: new Error('Request timed out'),
87
- });
88
- });
89
64
  compressAndSend(req, params.compression, data, (error) => {
90
65
  onDone({
91
66
  status: 'failure',
@@ -110,9 +85,4 @@ function readableFromUint8Array(buff) {
110
85
  readable.push(null);
111
86
  return readable;
112
87
  }
113
- export function createHttpAgent(rawUrl, agentOptions) {
114
- const parsedUrl = new URL(rawUrl);
115
- const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
116
- return new Agent(agentOptions);
117
- }
118
88
  //# sourceMappingURL=http-transport-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,UAAU,YA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,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;AAED,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,YAAoD;IAEpD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACxE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\n\n/**\n * Sends data using http\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n ...params.headers(),\n },\n agent: agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n onDone({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (res.statusCode && isExportRetryable(res.statusCode)) {\n onDone({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(\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 req.on('error', (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n\n const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';\n req.on(reportTimeoutErrorEvent, () => {\n onDone({\n status: 'failure',\n error: new Error('Request timed out'),\n });\n });\n\n compressAndSend(req, params.compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\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\nexport function createHttpAgent(\n rawUrl: string,\n agentOptions: http.AgentOptions | https.AgentOptions\n) {\n const parsedUrl = new URL(rawUrl);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent(agentOptions);\n}\n"]}
1
+ {"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../src/transport/http-transport-utils.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAmD,EACnD,MAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,MAA0C,EAC1C,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAEtC,MAAM,OAAO,GAA+C;QAC1D,QAAQ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I,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 { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../is-export-retryable';\nimport { OTLPExporterError } from '../types';\n\n/**\n * Sends data using http\n * @param requestFunction\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 params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n ...params.headers(),\n },\n agent: agent,\n };\n\n const 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, params.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,9 +1,15 @@
1
1
  import { IExporterTransport } from '../exporter-transport';
2
+ /**
3
+ * @deprecated favor the fetch transport
4
+ * @see {@link createFetchTransport}
5
+ */
2
6
  export interface XhrRequestParameters {
3
7
  url: string;
4
8
  headers: () => Record<string, string>;
5
9
  }
6
10
  /**
11
+ * @deprecated use {@link createFetchTransport} instead
12
+ *
7
13
  * Creates an exporter transport that uses XHR to send the data
8
14
  * @param parameters applied to each request made by transport
9
15
  */
@@ -75,6 +75,8 @@ class XhrTransport {
75
75
  }
76
76
  }
77
77
  /**
78
+ * @deprecated use {@link createFetchTransport} instead
79
+ *
78
80
  * Creates an exporter transport that uses XHR to send the data
79
81
  * @param parameters applied to each request made by transport
80
82
  */
@@ -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,EACj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AAE,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;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED;;;GAGG;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\nexport interface XhrRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n}\n\nclass XhrTransport implements IExporterTransport {\n constructor(private _parameters: XhrRequestParameters) {}\n\n send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const xhr = new XMLHttpRequest();\n xhr.timeout = timeoutMillis;\n xhr.open('POST', this._parameters.url);\n const headers = this._parameters.headers();\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\n shutdown() {\n // Intentionally left empty, nothing to do.\n }\n}\n\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"]}
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,GAC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ACnC,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;IACL,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';\n\n/**\n * @deprecated favor the fetch transport\n * @see {@link createFetchTransport}\n */\nexport interface XhrRequestParameters {\n url: string;\n headers: () => Record<string, string>;\n}\n\nclass XhrTransport implements IExporterTransport {\n constructor(private _parameters: XhrRequestParameters) {}\n\n send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n const xhr = new XMLHttpRequest();\n xhr.timeout = timeoutMillis;\n xhr.open('POST', this._parameters.url);\n const headers = this._parameters.headers();\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\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"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.202.0";
1
+ export declare const VERSION = "0.204.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export const VERSION = '0.202.0';
17
+ export const VERSION = '0.204.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,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// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.202.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,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// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.204.0';\n"]}
@@ -29,7 +29,7 @@ class BoundedQueueExportPromiseHandler {
29
29
  this._sendingPromises.push(promise);
30
30
  const popPromise = () => {
31
31
  const index = this._sendingPromises.indexOf(promise);
32
- this._sendingPromises.splice(index, 1);
32
+ void this._sendingPromises.splice(index, 1);
33
33
  };
34
34
  promise.then(popPromise, popPromise);
35
35
  }
@@ -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;QACzC,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,MAAM,UAAU,sCAAsC,CAAC,OAEtD;IACC,OAAO,IAAI,gCAAgC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxE,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\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 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"]}
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,MAAM,UAAU,sCAAsC,CAAC,OAEtD;IACC,OAAO,IAAI,gCAAgC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACxE,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\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"]}
@@ -1,25 +1,21 @@
1
- import { getHttpConfigurationDefaults, mergeOtlpHttpConfigurationWithDefaults, } from './otlp-http-configuration';
1
+ import { getHttpConfigurationDefaults, httpAgentFactoryFromOptions, mergeOtlpHttpConfigurationWithDefaults, } from './otlp-http-configuration';
2
2
  import { getHttpConfigurationFromEnvironment } from './otlp-http-env-configuration';
3
3
  import { diag } from '@opentelemetry/api';
4
4
  import { wrapStaticHeadersInFunction } from './shared-configuration';
5
5
  function convertLegacyAgentOptions(config) {
6
- // populate keepAlive for use with new settings
7
- if (config?.keepAlive != null) {
8
- if (config.httpAgentOptions != null) {
9
- if (config.httpAgentOptions.keepAlive == null) {
10
- // specific setting is not set, populate with non-specific setting.
11
- config.httpAgentOptions.keepAlive = config.keepAlive;
12
- }
13
- // do nothing, use specific setting otherwise
14
- }
15
- else {
16
- // populate specific option if AgentOptions does not exist.
17
- config.httpAgentOptions = {
18
- keepAlive: config.keepAlive,
19
- };
20
- }
6
+ if (typeof config.httpAgentOptions === 'function') {
7
+ return config.httpAgentOptions;
8
+ }
9
+ let legacy = config.httpAgentOptions;
10
+ if (config.keepAlive != null) {
11
+ legacy = { keepAlive: config.keepAlive, ...legacy };
12
+ }
13
+ if (legacy != null) {
14
+ return httpAgentFactoryFromOptions(legacy);
15
+ }
16
+ else {
17
+ return undefined;
21
18
  }
22
- return config.httpAgentOptions;
23
19
  }
24
20
  /**
25
21
  * @deprecated this will be removed in 2.0
@@ -39,7 +35,7 @@ export function convertLegacyHttpOptions(config, signalIdentifier, signalResourc
39
35
  concurrencyLimit: config.concurrencyLimit,
40
36
  timeoutMillis: config.timeoutMillis,
41
37
  compression: config.compression,
42
- agentOptions: convertLegacyAgentOptions(config),
38
+ agentFactory: convertLegacyAgentOptions(config),
43
39
  }, getHttpConfigurationFromEnvironment(signalIdentifier, signalResourcePath), getHttpConfigurationDefaults(requiredHeaders, signalResourcePath));
44
40
  }
45
41
  //# sourceMappingURL=convert-legacy-node-http-options.js.map
@@ -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,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GAEvC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AAGpF,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAErE,SAAS,yBAAyB,CAChC,MAAkC;IAElC,+CAA+C;IAC/C,IAAI,MAAM,EAAE,SAAS,IAAI,IAAI,EAAE;QAC7B,IAAI,MAAM,CAAC,gBAAgB,IAAI,IAAI,EAAE;YACnC,IAAI,MAAM,CAAC,gBAAgB,CAAC,SAAS,IAAI,IAAI,EAAE;gBAC7C,mEAAmE;gBACnE,MAAM,CAAC,gBAAgB,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;aACtD;YACD,6CAA6C;SAC9C;aAAM;YACL,2DAA2D;YAC3D,MAAM,CAAC,gBAAgB,GAAG;gBACxB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B,CAAC;SACH;KACF;IAED,OAAO,MAAM,CAAC,gBAAgB,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAkC,EAClC,gBAAwB,EACxB,kBAA0B,EAC1B,eAAuC;IAEvC,8DAA8D;IAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;QAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;KACrD;IAED,OAAO,sCAAsC,CAC3C;QACE,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,OAAO,EAAE,2BAA2B,CAAC,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,mCAAmC,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EACzE,4BAA4B,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAClE,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 { OTLPExporterNodeConfigBase } from './legacy-node-configuration';\nimport {\n getHttpConfigurationDefaults,\n mergeOtlpHttpConfigurationWithDefaults,\n OtlpHttpConfiguration,\n} from './otlp-http-configuration';\nimport { getHttpConfigurationFromEnvironment } from './otlp-http-env-configuration';\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { diag } from '@opentelemetry/api';\nimport { wrapStaticHeadersInFunction } from './shared-configuration';\n\nfunction convertLegacyAgentOptions(\n config: OTLPExporterNodeConfigBase\n): http.AgentOptions | https.AgentOptions | undefined {\n // populate keepAlive for use with new settings\n if (config?.keepAlive != null) {\n if (config.httpAgentOptions != null) {\n if (config.httpAgentOptions.keepAlive == null) {\n // specific setting is not set, populate with non-specific setting.\n config.httpAgentOptions.keepAlive = config.keepAlive;\n }\n // do nothing, use specific setting otherwise\n } else {\n // populate specific option if AgentOptions does not exist.\n config.httpAgentOptions = {\n keepAlive: config.keepAlive,\n };\n }\n }\n\n return config.httpAgentOptions;\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 agentOptions: convertLegacyAgentOptions(config),\n },\n getHttpConfigurationFromEnvironment(signalIdentifier, signalResourcePath),\n getHttpConfigurationDefaults(requiredHeaders, signalResourcePath)\n );\n}\n"]}
1
+ {"version":3,"file":"convert-legacy-node-http-options.js","sourceRoot":"","sources":["../../../src/configuration/convert-legacy-node-http-options.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,4BAA4B,EAE5B,2BAA2B,EAC3B,sCAAsC,GAEvC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;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,2BAA2B,CAAC,MAAM,CAAC,CAAC;KAC5C;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAkC,EAClC,gBAAwB,EACxB,kBAA0B,EAC1B,eAAuC;IAEvC,8DAA8D;IAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;QAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;KACrD;IAED,OAAO,sCAAsC,CAC3C;QACE,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,OAAO,EAAE,2BAA2B,CAAC,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,mCAAmC,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,EACzE,4BAA4B,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAClE,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 { 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,4 +1,4 @@
1
- import { createOtlpSendBeaconExportDelegate, createOtlpXhrExportDelegate, } from '../otlp-browser-http-export-delegate';
1
+ import { createOtlpFetchExportDelegate, createOtlpSendBeaconExportDelegate, createOtlpXhrExportDelegate, } from '../otlp-browser-http-export-delegate';
2
2
  import { convertLegacyBrowserHttpOptions } from './convert-legacy-browser-http-options';
3
3
  /**
4
4
  * @deprecated
@@ -8,13 +8,19 @@ import { convertLegacyBrowserHttpOptions } from './convert-legacy-browser-http-o
8
8
  * @param requiredHeaders
9
9
  */
10
10
  export function createLegacyOtlpBrowserExportDelegate(config, serializer, signalResourcePath, requiredHeaders) {
11
- const useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';
11
+ const createOtlpExportDelegate = inferExportDelegateToUse(config.headers);
12
12
  const options = convertLegacyBrowserHttpOptions(config, signalResourcePath, requiredHeaders);
13
- if (useXhr) {
14
- return createOtlpXhrExportDelegate(options, serializer);
13
+ return createOtlpExportDelegate(options, serializer);
14
+ }
15
+ export function inferExportDelegateToUse(configHeaders) {
16
+ if (!configHeaders && typeof navigator.sendBeacon === 'function') {
17
+ return createOtlpSendBeaconExportDelegate;
18
+ }
19
+ else if (typeof globalThis.fetch !== 'undefined') {
20
+ return createOtlpFetchExportDelegate;
15
21
  }
16
22
  else {
17
- return createOtlpSendBeaconExportDelegate(options, serializer);
23
+ return createOtlpXhrExportDelegate;
18
24
  }
19
25
  }
20
26
  //# 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,OAAO,EACL,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAIxF;;;;;;GAMG;AACH,MAAM,UAAU,qCAAqC,CACnD,MAA8B,EAC9B,UAA2C,EAC3C,kBAA0B,EAC1B,eAAuC;IAEvC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;IAE9E,MAAM,OAAO,GAAG,+BAA+B,CAC7C,MAAM,EACN,kBAAkB,EAClB,eAAe,CAChB,CAAC;IAEF,IAAI,MAAM,EAAE;QACV,OAAO,2BAA2B,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;KACzD;SAAM;QACL,OAAO,kCAAkC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;KAChE;AACH,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 { ISerializer } from '@opentelemetry/otlp-transformer';\nimport {\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 useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';\n\n const options = convertLegacyBrowserHttpOptions(\n config,\n signalResourcePath,\n requiredHeaders\n );\n\n if (useXhr) {\n return createOtlpXhrExportDelegate(options, serializer);\n } else {\n return createOtlpSendBeaconExportDelegate(options, serializer);\n }\n}\n"]}
1
+ {"version":3,"file":"create-legacy-browser-delegate.js","sourceRoot":"","sources":["../../../src/configuration/create-legacy-browser-delegate.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAIxF;;;;;;GAMG;AACH,MAAM,UAAU,qCAAqC,CACnD,MAA8B,EAC9B,UAA2C,EAC3C,kBAA0B,EAC1B,eAAuC;IAEvC,MAAM,wBAAwB,GAAG,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1E,MAAM,OAAO,GAAG,+BAA+B,CAC7C,MAAM,EACN,kBAAkB,EAClB,eAAe,CAChB,CAAC;IAEF,OAAO,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,aAAgD;IAEhD,IAAI,CAAC,aAAa,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,EAAE;QAChE,OAAO,kCAAkC,CAAC;KAC3C;SAAM,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE;QAClD,OAAO,6BAA6B,CAAC;KACtC;SAAM;QACL,OAAO,2BAA2B,CAAC;KACpC;AACH,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 { 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
- httpAgentOptions?: http.AgentOptions | https.AgentOptions;
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;AAiBH,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,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 { OTLPExporterConfigBase } from './legacy-base-configuration';\n\n/**\n * Collector Exporter node base config\n */\nexport interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {\n keepAlive?: boolean;\n compression?: CompressionAlgorithm;\n httpAgentOptions?: http.AgentOptions | https.AgentOptions;\n}\n\nexport enum CompressionAlgorithm {\n NONE = 'none',\n GZIP = 'gzip',\n}\n"]}
1
+ {"version":3,"file":"legacy-node-configuration.js","sourceRoot":"","sources":["../../../src/configuration/legacy-node-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwCH,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,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
- agentOptions: http.AgentOptions | https.AgentOptions;
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.
@@ -38,13 +38,21 @@ function validateUserProvidedUrl(url) {
38
38
  return undefined;
39
39
  }
40
40
  try {
41
- new URL(url);
42
- return url;
41
+ // NOTE: In non-browser environments, `globalThis.location` will be `undefined`.
42
+ const base = globalThis.location?.href;
43
+ return new URL(url, base).href;
43
44
  }
44
- catch (e) {
45
+ catch {
45
46
  throw new Error(`Configuration: Could not parse user-provided export URL: '${url}'`);
46
47
  }
47
48
  }
49
+ export function httpAgentFactoryFromOptions(options) {
50
+ return async (protocol) => {
51
+ const module = protocol === 'http:' ? import('http') : import('https');
52
+ const { Agent } = await module;
53
+ return new Agent(options);
54
+ };
55
+ }
48
56
  /**
49
57
  * @param userProvidedConfiguration Configuration options provided by the user in code.
50
58
  * @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.
@@ -57,9 +65,9 @@ export function mergeOtlpHttpConfigurationWithDefaults(userProvidedConfiguration
57
65
  url: validateUserProvidedUrl(userProvidedConfiguration.url) ??
58
66
  fallbackConfiguration.url ??
59
67
  defaultConfiguration.url,
60
- agentOptions: userProvidedConfiguration.agentOptions ??
61
- fallbackConfiguration.agentOptions ??
62
- defaultConfiguration.agentOptions,
68
+ agentFactory: userProvidedConfiguration.agentFactory ??
69
+ fallbackConfiguration.agentFactory ??
70
+ defaultConfiguration.agentFactory,
63
71
  };
64
72
  }
65
73
  export function getHttpConfigurationDefaults(requiredHeaders, signalResourcePath) {
@@ -67,7 +75,7 @@ export function getHttpConfigurationDefaults(requiredHeaders, signalResourcePath
67
75
  ...getSharedConfigurationDefaults(),
68
76
  headers: () => requiredHeaders,
69
77
  url: 'http://localhost:4318/' + signalResourcePath,
70
- agentOptions: { keepAlive: true },
78
+ agentFactory: httpAgentFactoryFromOptions({ keepAlive: true }),
71
79
  };
72
80
  }
73
81
  //# sourceMappingURL=otlp-http-configuration.js.map