@opentelemetry/otlp-exporter-base 0.52.1 → 0.54.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 (232) hide show
  1. package/build/esm/OTLPExporterBase.d.ts +0 -5
  2. package/build/esm/OTLPExporterBase.js +0 -8
  3. package/build/esm/OTLPExporterBase.js.map +1 -1
  4. package/build/esm/configuration/otlp-http-configuration.d.ts +13 -0
  5. package/build/esm/configuration/otlp-http-configuration.js +67 -0
  6. package/build/esm/configuration/otlp-http-configuration.js.map +1 -0
  7. package/build/esm/configuration/otlp-http-env-configuration.d.ts +9 -0
  8. package/build/esm/configuration/otlp-http-env-configuration.js +104 -0
  9. package/build/esm/configuration/otlp-http-env-configuration.js.map +1 -0
  10. package/build/esm/configuration/shared-configuration.d.ts +22 -0
  11. package/build/esm/configuration/shared-configuration.js +44 -0
  12. package/build/esm/configuration/shared-configuration.js.map +1 -0
  13. package/build/esm/configuration/shared-env-configuration.d.ts +3 -0
  14. package/build/esm/configuration/shared-env-configuration.js +44 -0
  15. package/build/esm/configuration/shared-env-configuration.js.map +1 -0
  16. package/build/esm/export-response.d.ts +14 -0
  17. package/build/esm/export-response.js +17 -0
  18. package/build/esm/export-response.js.map +1 -0
  19. package/build/esm/exporter-transport.d.ts +6 -0
  20. package/build/esm/exporter-transport.js +17 -0
  21. package/build/esm/exporter-transport.js.map +1 -0
  22. package/build/esm/index.d.ts +5 -1
  23. package/build/esm/index.js +6 -1
  24. package/build/esm/index.js.map +1 -1
  25. package/build/esm/is-export-retryable.d.ts +3 -0
  26. package/build/esm/is-export-retryable.js +35 -0
  27. package/build/esm/is-export-retryable.js.map +1 -0
  28. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +7 -9
  29. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +49 -32
  30. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  31. package/build/esm/platform/browser/index.d.ts +0 -1
  32. package/build/esm/platform/browser/index.js +0 -1
  33. package/build/esm/platform/browser/index.js.map +1 -1
  34. package/build/esm/platform/browser/send-beacon-transport.d.ts +10 -0
  35. package/build/esm/platform/browser/send-beacon-transport.js +47 -0
  36. package/build/esm/platform/browser/send-beacon-transport.js.map +1 -0
  37. package/build/esm/platform/browser/xhr-transport.d.ts +11 -0
  38. package/build/esm/platform/browser/xhr-transport.js +101 -0
  39. package/build/esm/platform/browser/xhr-transport.js.map +1 -0
  40. package/build/esm/platform/index.d.ts +2 -2
  41. package/build/esm/platform/index.js +2 -2
  42. package/build/esm/platform/index.js.map +1 -1
  43. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +6 -13
  44. package/build/esm/platform/node/OTLPExporterNodeBase.js +45 -14
  45. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -1
  46. package/build/esm/platform/node/convert-legacy-agent-options.d.ts +12 -0
  47. package/build/esm/platform/node/convert-legacy-agent-options.js +27 -0
  48. package/build/esm/platform/node/convert-legacy-agent-options.js.map +1 -0
  49. package/build/esm/platform/node/http-exporter-transport.d.ts +4 -0
  50. package/build/esm/platform/node/http-exporter-transport.js +87 -0
  51. package/build/esm/platform/node/http-exporter-transport.js.map +1 -0
  52. package/build/esm/platform/node/http-transport-types.d.ts +12 -0
  53. package/build/esm/platform/node/http-transport-types.js +17 -0
  54. package/build/esm/platform/node/http-transport-types.js.map +1 -0
  55. package/build/esm/platform/node/http-transport-utils.d.ts +16 -0
  56. package/build/esm/platform/node/http-transport-utils.js +127 -0
  57. package/build/esm/platform/node/http-transport-utils.js.map +1 -0
  58. package/build/esm/platform/node/index.d.ts +0 -1
  59. package/build/esm/platform/node/index.js +0 -1
  60. package/build/esm/platform/node/index.js.map +1 -1
  61. package/build/esm/retrying-transport.d.ts +8 -0
  62. package/build/esm/retrying-transport.js +119 -0
  63. package/build/esm/retrying-transport.js.map +1 -0
  64. package/build/esm/types.d.ts +1 -2
  65. package/build/esm/types.js.map +1 -1
  66. package/build/esm/util.d.ts +1 -27
  67. package/build/esm/util.js +1 -89
  68. package/build/esm/util.js.map +1 -1
  69. package/build/esm/version.d.ts +1 -1
  70. package/build/esm/version.js +1 -1
  71. package/build/esm/version.js.map +1 -1
  72. package/build/esnext/OTLPExporterBase.d.ts +0 -5
  73. package/build/esnext/OTLPExporterBase.js +0 -8
  74. package/build/esnext/OTLPExporterBase.js.map +1 -1
  75. package/build/esnext/configuration/otlp-http-configuration.d.ts +13 -0
  76. package/build/esnext/configuration/otlp-http-configuration.js +56 -0
  77. package/build/esnext/configuration/otlp-http-configuration.js.map +1 -0
  78. package/build/esnext/configuration/otlp-http-env-configuration.d.ts +9 -0
  79. package/build/esnext/configuration/otlp-http-env-configuration.js +93 -0
  80. package/build/esnext/configuration/otlp-http-env-configuration.js.map +1 -0
  81. package/build/esnext/configuration/shared-configuration.d.ts +22 -0
  82. package/build/esnext/configuration/shared-configuration.js +44 -0
  83. package/build/esnext/configuration/shared-configuration.js.map +1 -0
  84. package/build/esnext/configuration/shared-env-configuration.d.ts +3 -0
  85. package/build/esnext/configuration/shared-env-configuration.js +44 -0
  86. package/build/esnext/configuration/shared-env-configuration.js.map +1 -0
  87. package/build/esnext/export-response.d.ts +14 -0
  88. package/build/esnext/export-response.js +17 -0
  89. package/build/esnext/export-response.js.map +1 -0
  90. package/build/esnext/exporter-transport.d.ts +6 -0
  91. package/build/esnext/exporter-transport.js +17 -0
  92. package/build/esnext/exporter-transport.js.map +1 -0
  93. package/build/esnext/index.d.ts +5 -1
  94. package/build/esnext/index.js +6 -1
  95. package/build/esnext/index.js.map +1 -1
  96. package/build/esnext/is-export-retryable.d.ts +3 -0
  97. package/build/esnext/is-export-retryable.js +35 -0
  98. package/build/esnext/is-export-retryable.js.map +1 -0
  99. package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +7 -9
  100. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +49 -21
  101. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  102. package/build/esnext/platform/browser/index.d.ts +0 -1
  103. package/build/esnext/platform/browser/index.js +0 -1
  104. package/build/esnext/platform/browser/index.js.map +1 -1
  105. package/build/esnext/platform/browser/send-beacon-transport.d.ts +10 -0
  106. package/build/esnext/platform/browser/send-beacon-transport.js +45 -0
  107. package/build/esnext/platform/browser/send-beacon-transport.js.map +1 -0
  108. package/build/esnext/platform/browser/xhr-transport.d.ts +11 -0
  109. package/build/esnext/platform/browser/xhr-transport.js +82 -0
  110. package/build/esnext/platform/browser/xhr-transport.js.map +1 -0
  111. package/build/esnext/platform/index.d.ts +2 -2
  112. package/build/esnext/platform/index.js +2 -2
  113. package/build/esnext/platform/index.js.map +1 -1
  114. package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +6 -13
  115. package/build/esnext/platform/node/OTLPExporterNodeBase.js +45 -14
  116. package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -1
  117. package/build/esnext/platform/node/convert-legacy-agent-options.d.ts +12 -0
  118. package/build/esnext/platform/node/convert-legacy-agent-options.js +27 -0
  119. package/build/esnext/platform/node/convert-legacy-agent-options.js.map +1 -0
  120. package/build/esnext/platform/node/http-exporter-transport.d.ts +4 -0
  121. package/build/esnext/platform/node/http-exporter-transport.js +47 -0
  122. package/build/esnext/platform/node/http-exporter-transport.js.map +1 -0
  123. package/build/esnext/platform/node/http-transport-types.d.ts +12 -0
  124. package/build/esnext/platform/node/http-transport-types.js +17 -0
  125. package/build/esnext/platform/node/http-transport-types.js.map +1 -0
  126. package/build/esnext/platform/node/http-transport-utils.d.ts +16 -0
  127. package/build/esnext/platform/node/http-transport-utils.js +116 -0
  128. package/build/esnext/platform/node/http-transport-utils.js.map +1 -0
  129. package/build/esnext/platform/node/index.d.ts +0 -1
  130. package/build/esnext/platform/node/index.js +0 -1
  131. package/build/esnext/platform/node/index.js.map +1 -1
  132. package/build/esnext/retrying-transport.d.ts +8 -0
  133. package/build/esnext/retrying-transport.js +69 -0
  134. package/build/esnext/retrying-transport.js.map +1 -0
  135. package/build/esnext/types.d.ts +1 -2
  136. package/build/esnext/types.js.map +1 -1
  137. package/build/esnext/util.d.ts +1 -27
  138. package/build/esnext/util.js +1 -89
  139. package/build/esnext/util.js.map +1 -1
  140. package/build/esnext/version.d.ts +1 -1
  141. package/build/esnext/version.js +1 -1
  142. package/build/esnext/version.js.map +1 -1
  143. package/build/src/OTLPExporterBase.d.ts +0 -5
  144. package/build/src/OTLPExporterBase.js +0 -8
  145. package/build/src/OTLPExporterBase.js.map +1 -1
  146. package/build/src/configuration/otlp-http-configuration.d.ts +13 -0
  147. package/build/src/configuration/otlp-http-configuration.js +61 -0
  148. package/build/src/configuration/otlp-http-configuration.js.map +1 -0
  149. package/build/src/configuration/otlp-http-env-configuration.d.ts +9 -0
  150. package/build/src/configuration/otlp-http-env-configuration.js +97 -0
  151. package/build/src/configuration/otlp-http-env-configuration.js.map +1 -0
  152. package/build/src/configuration/shared-configuration.d.ts +22 -0
  153. package/build/src/configuration/shared-configuration.js +50 -0
  154. package/build/src/configuration/shared-configuration.js.map +1 -0
  155. package/build/src/configuration/shared-env-configuration.d.ts +3 -0
  156. package/build/src/configuration/shared-env-configuration.js +48 -0
  157. package/build/src/configuration/shared-env-configuration.js.map +1 -0
  158. package/build/src/export-response.d.ts +14 -0
  159. package/build/src/export-response.js +18 -0
  160. package/build/src/export-response.js.map +1 -0
  161. package/build/src/exporter-transport.d.ts +6 -0
  162. package/build/src/exporter-transport.js +18 -0
  163. package/build/src/exporter-transport.js.map +1 -0
  164. package/build/src/index.d.ts +5 -1
  165. package/build/src/index.js +21 -17
  166. package/build/src/index.js.map +1 -1
  167. package/build/src/is-export-retryable.d.ts +3 -0
  168. package/build/src/is-export-retryable.js +40 -0
  169. package/build/src/is-export-retryable.js.map +1 -0
  170. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +7 -9
  171. package/build/src/platform/browser/OTLPExporterBrowserBase.js +49 -21
  172. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  173. package/build/src/platform/browser/index.d.ts +0 -1
  174. package/build/src/platform/browser/index.js +1 -3
  175. package/build/src/platform/browser/index.js.map +1 -1
  176. package/build/src/platform/browser/send-beacon-transport.d.ts +10 -0
  177. package/build/src/platform/browser/send-beacon-transport.js +49 -0
  178. package/build/src/platform/browser/send-beacon-transport.js.map +1 -0
  179. package/build/src/platform/browser/xhr-transport.d.ts +11 -0
  180. package/build/src/platform/browser/xhr-transport.js +86 -0
  181. package/build/src/platform/browser/xhr-transport.js.map +1 -0
  182. package/build/src/platform/index.d.ts +2 -2
  183. package/build/src/platform/index.js +1 -5
  184. package/build/src/platform/index.js.map +1 -1
  185. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +6 -13
  186. package/build/src/platform/node/OTLPExporterNodeBase.js +45 -14
  187. package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -1
  188. package/build/src/platform/node/convert-legacy-agent-options.d.ts +12 -0
  189. package/build/src/platform/node/convert-legacy-agent-options.js +31 -0
  190. package/build/src/platform/node/convert-legacy-agent-options.js.map +1 -0
  191. package/build/src/platform/node/http-exporter-transport.d.ts +4 -0
  192. package/build/src/platform/node/http-exporter-transport.js +51 -0
  193. package/build/src/platform/node/http-exporter-transport.js.map +1 -0
  194. package/build/src/platform/node/http-transport-types.d.ts +12 -0
  195. package/build/src/platform/node/http-transport-types.js +18 -0
  196. package/build/src/platform/node/http-transport-types.js.map +1 -0
  197. package/build/src/platform/node/http-transport-utils.d.ts +16 -0
  198. package/build/src/platform/node/http-transport-utils.js +121 -0
  199. package/build/src/platform/node/http-transport-utils.js.map +1 -0
  200. package/build/src/platform/node/index.d.ts +0 -1
  201. package/build/src/platform/node/index.js +1 -5
  202. package/build/src/platform/node/index.js.map +1 -1
  203. package/build/src/retrying-transport.d.ts +8 -0
  204. package/build/src/retrying-transport.js +73 -0
  205. package/build/src/retrying-transport.js.map +1 -0
  206. package/build/src/types.d.ts +1 -2
  207. package/build/src/types.js.map +1 -1
  208. package/build/src/util.d.ts +1 -27
  209. package/build/src/util.js +3 -97
  210. package/build/src/util.js.map +1 -1
  211. package/build/src/version.d.ts +1 -1
  212. package/build/src/version.js +1 -1
  213. package/build/src/version.js.map +1 -1
  214. package/package.json +13 -17
  215. package/build/esm/platform/browser/util.d.ts +0 -21
  216. package/build/esm/platform/browser/util.js +0 -152
  217. package/build/esm/platform/browser/util.js.map +0 -1
  218. package/build/esm/platform/node/util.d.ts +0 -19
  219. package/build/esm/platform/node/util.js +0 -194
  220. package/build/esm/platform/node/util.js.map +0 -1
  221. package/build/esnext/platform/browser/util.d.ts +0 -21
  222. package/build/esnext/platform/browser/util.js +0 -122
  223. package/build/esnext/platform/browser/util.js.map +0 -1
  224. package/build/esnext/platform/node/util.d.ts +0 -19
  225. package/build/esnext/platform/node/util.js +0 -181
  226. package/build/esnext/platform/node/util.js.map +0 -1
  227. package/build/src/platform/browser/util.d.ts +0 -21
  228. package/build/src/platform/browser/util.js +0 -127
  229. package/build/src/platform/browser/util.js.map +0 -1
  230. package/build/src/platform/node/util.d.ts +0 -19
  231. package/build/src/platform/node/util.js +0 -187
  232. package/build/src/platform/node/util.js.map +0 -1
@@ -17,37 +17,68 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.OTLPExporterNodeBase = void 0;
19
19
  const OTLPExporterBase_1 = require("../../OTLPExporterBase");
20
- const util_1 = require("../../util");
21
- const util_2 = require("./util");
22
20
  const api_1 = require("@opentelemetry/api");
23
- const core_1 = require("@opentelemetry/core");
21
+ const http_exporter_transport_1 = require("./http-exporter-transport");
22
+ const types_1 = require("../../types");
23
+ const retrying_transport_1 = require("../../retrying-transport");
24
+ const convert_legacy_agent_options_1 = require("./convert-legacy-agent-options");
25
+ const otlp_http_configuration_1 = require("../../configuration/otlp-http-configuration");
26
+ const otlp_http_env_configuration_1 = require("../../configuration/otlp-http-env-configuration");
24
27
  /**
25
28
  * Collector Metric Exporter abstract base class
26
29
  */
27
30
  class OTLPExporterNodeBase extends OTLPExporterBase_1.OTLPExporterBase {
28
- constructor(config = {}, serializer, contentType) {
31
+ constructor(config = {}, serializer, requiredHeaders, signalIdentifier, signalResourcePath) {
29
32
  super(config);
30
- this.DEFAULT_HEADERS = {};
31
- this._contentType = contentType;
33
+ const actualConfig = (0, otlp_http_configuration_1.mergeOtlpHttpConfigurationWithDefaults)({
34
+ url: config.url,
35
+ headers: config.headers,
36
+ concurrencyLimit: config.concurrencyLimit,
37
+ timeoutMillis: config.timeoutMillis,
38
+ compression: config.compression,
39
+ }, (0, otlp_http_env_configuration_1.getHttpConfigurationFromEnvironment)(signalIdentifier, signalResourcePath), (0, otlp_http_configuration_1.getHttpConfigurationDefaults)(requiredHeaders, signalResourcePath));
40
+ this._timeoutMillis = actualConfig.timeoutMillis;
41
+ this._concurrencyLimit = actualConfig.concurrencyLimit;
32
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
43
  if (config.metadata) {
34
44
  api_1.diag.warn('Metadata cannot be set when using http');
35
45
  }
36
- this.headers = Object.assign(this.DEFAULT_HEADERS, (0, util_1.parseHeaders)(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS));
37
- this.agent = (0, util_2.createHttpAgent)(config);
38
- this.compression = (0, util_2.configureCompression)(config.compression);
39
46
  this._serializer = serializer;
47
+ this._transport = (0, retrying_transport_1.createRetryingTransport)({
48
+ transport: (0, http_exporter_transport_1.createHttpExporterTransport)({
49
+ agentOptions: (0, convert_legacy_agent_options_1.convertLegacyAgentOptions)(config),
50
+ compression: actualConfig.compression,
51
+ headers: actualConfig.headers,
52
+ url: actualConfig.url,
53
+ }),
54
+ });
40
55
  }
41
- onInit(_config) { }
42
56
  send(objects, onSuccess, onError) {
43
57
  if (this._shutdownOnce.isCalled) {
44
58
  api_1.diag.debug('Shutdown already started. Cannot send objects');
45
59
  return;
46
60
  }
47
- const promise = new Promise((resolve, reject) => {
48
- var _a;
49
- (0, util_2.sendWithHttp)(this, (_a = this._serializer.serializeRequest(objects)) !== null && _a !== void 0 ? _a : new Uint8Array(), this._contentType, resolve, reject);
50
- }).then(onSuccess, onError);
61
+ const data = this._serializer.serializeRequest(objects);
62
+ if (data == null) {
63
+ onError(new Error('Could not serialize message'));
64
+ return;
65
+ }
66
+ const promise = this._transport
67
+ .send(data, this._timeoutMillis)
68
+ .then(response => {
69
+ if (response.status === 'success') {
70
+ onSuccess();
71
+ }
72
+ else if (response.status === 'failure' && response.error) {
73
+ onError(response.error);
74
+ }
75
+ else if (response.status === 'retryable') {
76
+ onError(new types_1.OTLPExporterError('Export failed with retryable status'));
77
+ }
78
+ else {
79
+ onError(new types_1.OTLPExporterError('Export failed with unknown error'));
80
+ }
81
+ }, onError);
51
82
  this._sendingPromises.push(promise);
52
83
  const popPromise = () => {
53
84
  const index = this._sendingPromises.indexOf(promise);
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKH,6DAA0D;AAG1D,qCAA0C;AAC1C,iCAA6E;AAC7E,4CAA0C;AAC1C,8CAA2D;AAG3D;;GAEG;AACH,MAAsB,oBAGpB,SAAQ,mCAAwD;IAQhE,YACE,SAAqC,EAAE,EACvC,UAAsD,EACtD,WAAmB;QAEnB,KAAK,CAAC,MAAM,CAAC,CAAC;QAZhB,oBAAe,GAA2B,EAAE,CAAC;QAa3C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,UAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,eAAe,EACpB,IAAA,mBAAY,EAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,mBAAY,CAAC,uBAAuB,CAAC,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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';\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { createHttpAgent, sendWithHttp, configureCompression } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {\n DEFAULT_HEADERS: Record<string, string> = {};\n headers: Record<string, string>;\n agent: http.Agent | https.Agent | undefined;\n compression: CompressionAlgorithm;\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _contentType: string;\n\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n contentType: string\n ) {\n super(config);\n this._contentType = contentType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((config as any).metadata) {\n diag.warn('Metadata cannot be set when using http');\n }\n this.headers = Object.assign(\n this.DEFAULT_HEADERS,\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)\n );\n this.agent = createHttpAgent(config);\n this.compression = configureCompression(config.compression);\n this._serializer = serializer;\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const promise = new Promise<void>((resolve, reject) => {\n sendWithHttp(\n this,\n this._serializer.serializeRequest(objects) ?? new Uint8Array(),\n this._contentType,\n resolve,\n reject\n );\n }).then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n onShutdown(): void {}\n}\n"]}
1
+ {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6DAA0D;AAE1D,4CAA0C;AAG1C,uEAAwE;AACxE,uCAAgD;AAChD,iEAAmE;AACnE,iFAA2E;AAC3E,yFAGqD;AACrD,iGAAsG;AAEtG;;GAEG;AACH,MAAsB,oBAGpB,SAAQ,mCAAwD;IAKhE,YACE,SAAqC,EAAE,EACvC,UAAsD,EACtD,eAAuC,EACvC,gBAAwB,EACxB,kBAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,MAAM,YAAY,GAAG,IAAA,gEAAsC,EACzD;YACE,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,EACD,IAAA,iEAAmC,EAAC,gBAAgB,EAAE,kBAAkB,CAAC,EACzE,IAAA,sDAA4B,EAAC,eAAe,EAAE,kBAAkB,CAAC,CAClE,CAAC;QAEF,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,aAAa,CAAC;QACjD,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,gBAAgB,CA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C,IAAI,yBAAiB,CAAC,qCAAqC,CAAC,CAAC,CAAC;aACvE;iBAAM;gBACL,OAAO,CAAC,IAAI,yBAAiB,CAAC,kCAAkC,CAAC,CAAC,CAAC;aACpE;QACH,CAAC,EAAE,OAAO,CAAC,CAAC;QAEd,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,KAAU,CAAC;CACtB;AAvFD,oDAuFC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterNodeConfigBase } from './types';\nimport { diag } from '@opentelemetry/api';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { IExporterTransport } from '../../exporter-transport';\nimport { createHttpExporterTransport } from './http-exporter-transport';\nimport { OTLPExporterError } from '../../types';\nimport { createRetryingTransport } from '../../retrying-transport';\nimport { convertLegacyAgentOptions } from './convert-legacy-agent-options';\nimport {\n getHttpConfigurationDefaults,\n mergeOtlpHttpConfigurationWithDefaults,\n} from '../../configuration/otlp-http-configuration';\nimport { getHttpConfigurationFromEnvironment } from '../../configuration/otlp-http-env-configuration';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _transport: IExporterTransport;\n private _timeoutMillis: number;\n\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n requiredHeaders: Record<string, string>,\n signalIdentifier: string,\n signalResourcePath: string\n ) {\n super(config);\n const actualConfig = mergeOtlpHttpConfigurationWithDefaults(\n {\n url: config.url,\n headers: config.headers,\n concurrencyLimit: config.concurrencyLimit,\n timeoutMillis: config.timeoutMillis,\n compression: config.compression,\n },\n getHttpConfigurationFromEnvironment(signalIdentifier, signalResourcePath),\n getHttpConfigurationDefaults(requiredHeaders, signalResourcePath)\n );\n\n this._timeoutMillis = actualConfig.timeoutMillis;\n this._concurrencyLimit = actualConfig.concurrencyLimit;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((config as any).metadata) {\n diag.warn('Metadata cannot be set when using http');\n }\n this._serializer = serializer;\n\n this._transport = createRetryingTransport({\n transport: createHttpExporterTransport({\n agentOptions: convertLegacyAgentOptions(config),\n compression: actualConfig.compression,\n headers: actualConfig.headers,\n url: actualConfig.url,\n }),\n });\n }\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const data = this._serializer.serializeRequest(objects);\n\n if (data == null) {\n onError(new Error('Could not serialize message'));\n return;\n }\n\n const promise = this._transport\n .send(data, this._timeoutMillis)\n .then(response => {\n if (response.status === 'success') {\n onSuccess();\n } else if (response.status === 'failure' && response.error) {\n onError(response.error);\n } else if (response.status === 'retryable') {\n onError(new OTLPExporterError('Export failed with retryable status'));\n } else {\n onError(new OTLPExporterError('Export failed with unknown error'));\n }\n }, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n onShutdown(): void {}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { OTLPExporterNodeConfigBase } from './types';
3
+ import type * as http from 'http';
4
+ import type * as https from 'https';
5
+ /**
6
+ * Replicates old config behavior where there's two ways to set keepAlive.
7
+ * This function sets keepAlive in AgentOptions if it is defined. In the future, we will remove
8
+ * this duplicate to only allow setting keepAlive in AgentOptions.
9
+ * @param config
10
+ */
11
+ export declare function convertLegacyAgentOptions(config: OTLPExporterNodeConfigBase): http.AgentOptions | https.AgentOptions;
12
+ //# sourceMappingURL=convert-legacy-agent-options.d.ts.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertLegacyAgentOptions = void 0;
4
+ /**
5
+ * Replicates old config behavior where there's two ways to set keepAlive.
6
+ * This function sets keepAlive in AgentOptions if it is defined. In the future, we will remove
7
+ * this duplicate to only allow setting keepAlive in AgentOptions.
8
+ * @param config
9
+ */
10
+ function convertLegacyAgentOptions(config) {
11
+ var _a;
12
+ // populate keepAlive for use with new settings
13
+ if ((config === null || config === void 0 ? void 0 : config.keepAlive) != null) {
14
+ if (config.httpAgentOptions != null) {
15
+ if (config.httpAgentOptions.keepAlive == null) {
16
+ // specific setting is not set, populate with non-specific setting.
17
+ config.httpAgentOptions.keepAlive = config.keepAlive;
18
+ }
19
+ // do nothing, use specific setting otherwise
20
+ }
21
+ else {
22
+ // populate specific option if AgentOptions does not exist.
23
+ config.httpAgentOptions = {
24
+ keepAlive: config.keepAlive,
25
+ };
26
+ }
27
+ }
28
+ return (_a = config.httpAgentOptions) !== null && _a !== void 0 ? _a : { keepAlive: true };
29
+ }
30
+ exports.convertLegacyAgentOptions = convertLegacyAgentOptions;
31
+ //# sourceMappingURL=convert-legacy-agent-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-legacy-agent-options.js","sourceRoot":"","sources":["../../../../src/platform/node/convert-legacy-agent-options.ts"],"names":[],"mappings":";;;AAmBA;;;;;GAKG;AACH,SAAgB,yBAAyB,CACvC,MAAkC;;IAElC,+CAA+C;IAC/C,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,KAAI,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,MAAA,MAAM,CAAC,gBAAgB,mCAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACxD,CAAC;AApBD,8DAoBC","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 './types';\nimport type * as http from 'http';\nimport type * as https from 'https';\n\n/**\n * Replicates old config behavior where there's two ways to set keepAlive.\n * This function sets keepAlive in AgentOptions if it is defined. In the future, we will remove\n * this duplicate to only allow setting keepAlive in AgentOptions.\n * @param config\n */\nexport function convertLegacyAgentOptions(\n config: OTLPExporterNodeConfigBase\n): http.AgentOptions | https.AgentOptions {\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 ?? { keepAlive: true };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { HttpRequestParameters } from './http-transport-types';
2
+ import { IExporterTransport } from '../../exporter-transport';
3
+ export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
4
+ //# sourceMappingURL=http-exporter-transport.d.ts.map
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createHttpExporterTransport = void 0;
19
+ class HttpExporterTransport {
20
+ constructor(_parameters) {
21
+ this._parameters = _parameters;
22
+ this._send = null;
23
+ this._agent = null;
24
+ }
25
+ async send(data, timeoutMillis) {
26
+ if (this._send == null) {
27
+ // Lazy require to ensure that http/https is not required before instrumentations can wrap it.
28
+ const { sendWithHttp, createHttpAgent,
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
30
+ } = require('./http-transport-utils');
31
+ this._agent = createHttpAgent(this._parameters.url, this._parameters.agentOptions);
32
+ this._send = sendWithHttp;
33
+ }
34
+ return new Promise(resolve => {
35
+ var _a;
36
+ // this will always be defined
37
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
38
+ (_a = this._send) === null || _a === void 0 ? void 0 : _a.call(this, this._parameters, this._agent, data, result => {
39
+ resolve(result);
40
+ }, timeoutMillis);
41
+ });
42
+ }
43
+ shutdown() {
44
+ // intentionally left empty, nothing to do.
45
+ }
46
+ }
47
+ function createHttpExporterTransport(parameters) {
48
+ return new HttpExporterTransport(parameters);
49
+ }
50
+ exports.createHttpExporterTransport = createHttpExporterTransport;
51
+ //# sourceMappingURL=http-exporter-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../../src/platform/node/http-exporter-transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAcH,MAAM,qBAAqB;IAIzB,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;QAH9C,UAAK,GAAwB,IAAI,CAAC;QAClC,WAAM,GAAoC,IAAI,CAAC;IAEE,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,8FAA8F;YAC9F,MAAM,EACJ,YAAY,EACZ,eAAe;YACf,8DAA8D;cAC/D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,GAAG,eAAe,CAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B,CAAC;YACF,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;SAC3B;QAED,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;;YAC3C,8BAA8B;YAC9B,oEAAoE;YACpE,MAAA,IAAI,CAAC,KAAK,+CAAV,IAAI,EACF,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAO,EACZ,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,SAAgB,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC;AAJD,kEAIC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../../export-response';\nimport { IExporterTransport } from '../../exporter-transport';\n\nclass HttpExporterTransport implements IExporterTransport {\n private _send: sendWithHttp | null = null;\n private _agent: http.Agent | https.Agent | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n if (this._send == null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n this._agent = createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n );\n this._send = sendWithHttp;\n }\n\n return new Promise<ExportResponse>(resolve => {\n // this will always be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._send?.(\n this._parameters,\n this._agent!,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import type * as http from 'http';
3
+ import type * as https from 'https';
4
+ import { ExportResponse } from '../../export-response';
5
+ export declare type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
6
+ export interface HttpRequestParameters {
7
+ url: string;
8
+ headers: Record<string, string>;
9
+ compression: 'gzip' | 'none';
10
+ agentOptions: http.AgentOptions | https.AgentOptions;
11
+ }
12
+ //# sourceMappingURL=http-transport-types.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ //# sourceMappingURL=http-transport-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import * as https from 'https';
4
+ import { HttpRequestParameters } from './http-transport-types';
5
+ import { ExportResponse } from '../../export-response';
6
+ /**
7
+ * Sends data using http
8
+ * @param params
9
+ * @param agent
10
+ * @param data
11
+ * @param onDone
12
+ * @param timeoutMillis
13
+ */
14
+ export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
15
+ export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
16
+ //# sourceMappingURL=http-transport-utils.d.ts.map
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHttpAgent = exports.sendWithHttp = void 0;
4
+ /*
5
+ * Copyright The OpenTelemetry Authors
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * https://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const http = require("http");
20
+ const https = require("https");
21
+ const zlib = require("zlib");
22
+ const stream_1 = require("stream");
23
+ const is_export_retryable_1 = require("../../is-export-retryable");
24
+ const types_1 = require("../../types");
25
+ /**
26
+ * Sends data using http
27
+ * @param params
28
+ * @param agent
29
+ * @param data
30
+ * @param onDone
31
+ * @param timeoutMillis
32
+ */
33
+ function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
34
+ const parsedUrl = new URL(params.url);
35
+ const nodeVersion = Number(process.versions.node.split('.')[0]);
36
+ const options = {
37
+ hostname: parsedUrl.hostname,
38
+ port: parsedUrl.port,
39
+ path: parsedUrl.pathname,
40
+ method: 'POST',
41
+ headers: Object.assign({}, params.headers),
42
+ agent: agent,
43
+ };
44
+ const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
45
+ const req = request(options, (res) => {
46
+ const responseData = [];
47
+ res.on('data', chunk => responseData.push(chunk));
48
+ res.on('end', () => {
49
+ if (res.statusCode && res.statusCode < 299) {
50
+ onDone({
51
+ status: 'success',
52
+ data: Buffer.concat(responseData),
53
+ });
54
+ }
55
+ else if (res.statusCode && (0, is_export_retryable_1.isExportRetryable)(res.statusCode)) {
56
+ onDone({
57
+ status: 'retryable',
58
+ retryInMillis: (0, is_export_retryable_1.parseRetryAfterToMills)(res.headers['retry-after']),
59
+ });
60
+ }
61
+ else {
62
+ const error = new types_1.OTLPExporterError(res.statusMessage, res.statusCode);
63
+ onDone({
64
+ status: 'failure',
65
+ error,
66
+ });
67
+ }
68
+ });
69
+ });
70
+ req.setTimeout(timeoutMillis, () => {
71
+ req.destroy();
72
+ onDone({
73
+ status: 'failure',
74
+ error: new Error('Request Timeout'),
75
+ });
76
+ });
77
+ req.on('error', (error) => {
78
+ onDone({
79
+ status: 'failure',
80
+ error: error,
81
+ });
82
+ });
83
+ const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
84
+ req.on(reportTimeoutErrorEvent, () => {
85
+ onDone({
86
+ status: 'failure',
87
+ error: new Error('Request timed out'),
88
+ });
89
+ });
90
+ compressAndSend(req, params.compression, data, (error) => {
91
+ onDone({
92
+ status: 'failure',
93
+ error,
94
+ });
95
+ });
96
+ }
97
+ exports.sendWithHttp = sendWithHttp;
98
+ function compressAndSend(req, compression, data, onError) {
99
+ let dataStream = readableFromUint8Array(data);
100
+ if (compression === 'gzip') {
101
+ req.setHeader('Content-Encoding', 'gzip');
102
+ dataStream = dataStream
103
+ .on('error', onError)
104
+ .pipe(zlib.createGzip())
105
+ .on('error', onError);
106
+ }
107
+ dataStream.pipe(req);
108
+ }
109
+ function readableFromUint8Array(buff) {
110
+ const readable = new stream_1.Readable();
111
+ readable.push(buff);
112
+ readable.push(null);
113
+ return readable;
114
+ }
115
+ function createHttpAgent(rawUrl, agentOptions) {
116
+ const parsedUrl = new URL(rawUrl);
117
+ const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
118
+ return new Agent(agentOptions);
119
+ }
120
+ exports.createHttpAgent = createHttpAgent;
121
+ //# sourceMappingURL=http-transport-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAAkC;AAGlC,mEAGmC;AACnC,uCAAgD;AAEhD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,MAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,MAA0C,EAC1C,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,C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C1B,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;AACvB,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,eAAe,CAC7B,MAAc,EACd,YAAoD;IAEpD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACxE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AAPD,0CAOC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../is-export-retryable';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Sends data using http\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n ...params.headers,\n },\n agent: agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n onDone({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (res.statusCode && isExportRetryable(res.statusCode)) {\n onDone({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(res.statusMessage, res.statusCode);\n onDone({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n onDone({\n status: 'failure',\n error: new Error('Request Timeout'),\n });\n });\n req.on('error', (error: Error | any) => {\n onDone({\n status: 'failure',\n error: error,\n });\n });\n\n const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';\n req.on(reportTimeoutErrorEvent, () => {\n onDone({\n status: 'failure',\n error: new Error('Request timed out'),\n });\n });\n\n compressAndSend(req, params.compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\nfunction compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n rawUrl: string,\n agentOptions: http.AgentOptions | https.AgentOptions\n) {\n const parsedUrl = new URL(rawUrl);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent(agentOptions);\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
2
- export { sendWithHttp, createHttpAgent, configureCompression } from './util';
3
2
  export { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -15,13 +15,9 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CompressionAlgorithm = exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp = exports.OTLPExporterNodeBase = void 0;
18
+ exports.CompressionAlgorithm = exports.OTLPExporterNodeBase = void 0;
19
19
  var OTLPExporterNodeBase_1 = require("./OTLPExporterNodeBase");
20
20
  Object.defineProperty(exports, "OTLPExporterNodeBase", { enumerable: true, get: function () { return OTLPExporterNodeBase_1.OTLPExporterNodeBase; } });
21
- var util_1 = require("./util");
22
- Object.defineProperty(exports, "sendWithHttp", { enumerable: true, get: function () { return util_1.sendWithHttp; } });
23
- Object.defineProperty(exports, "createHttpAgent", { enumerable: true, get: function () { return util_1.createHttpAgent; } });
24
- Object.defineProperty(exports, "configureCompression", { enumerable: true, get: function () { return util_1.configureCompression; } });
25
21
  var types_1 = require("./types");
26
22
  Object.defineProperty(exports, "CompressionAlgorithm", { enumerable: true, get: function () { return types_1.CompressionAlgorithm; } });
27
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,+BAA6E;AAApE,oGAAA,YAAY,OAAA;AAAE,uGAAA,eAAe,OAAA;AAAE,4GAAA,oBAAoB,OAAA;AAC5D,iCAA2E;AAAtC,6GAAA,oBAAoB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { sendWithHttp, createHttpAgent, configureCompression } from './util';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,iCAA2E;AAAtC,6GAAA,oBAAoB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
@@ -0,0 +1,8 @@
1
+ import { IExporterTransport } from './exporter-transport';
2
+ /**
3
+ * Creates an Exporter Transport that retries on 'retryable' response.
4
+ */
5
+ export declare function createRetryingTransport(options: {
6
+ transport: IExporterTransport;
7
+ }): IExporterTransport;
8
+ //# sourceMappingURL=retrying-transport.d.ts.map
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createRetryingTransport = void 0;
19
+ const MAX_ATTEMPTS = 5;
20
+ const INITIAL_BACKOFF = 1000;
21
+ const MAX_BACKOFF = 5000;
22
+ const BACKOFF_MULTIPLIER = 1.5;
23
+ const JITTER = 0.2;
24
+ /**
25
+ * Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]
26
+ */
27
+ function getJitter() {
28
+ return Math.random() * (2 * JITTER) - JITTER;
29
+ }
30
+ class RetryingTransport {
31
+ constructor(_transport) {
32
+ this._transport = _transport;
33
+ }
34
+ retry(data, timeoutMillis, inMillis) {
35
+ return new Promise((resolve, reject) => {
36
+ setTimeout(() => {
37
+ this._transport.send(data, timeoutMillis).then(resolve, reject);
38
+ }, inMillis);
39
+ });
40
+ }
41
+ async send(data, timeoutMillis) {
42
+ var _a;
43
+ const deadline = Date.now() + timeoutMillis;
44
+ let result = await this._transport.send(data, timeoutMillis);
45
+ let attempts = MAX_ATTEMPTS;
46
+ let nextBackoff = INITIAL_BACKOFF;
47
+ while (result.status === 'retryable' && attempts > 0) {
48
+ attempts--;
49
+ // use maximum of computed backoff and 0 to avoid negative timeouts
50
+ const backoff = Math.max(Math.min(nextBackoff, MAX_BACKOFF) + getJitter(), 0);
51
+ nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;
52
+ const retryInMillis = (_a = result.retryInMillis) !== null && _a !== void 0 ? _a : backoff;
53
+ // return when expected retry time is after the export deadline.
54
+ const remainingTimeoutMillis = deadline - Date.now();
55
+ if (retryInMillis > remainingTimeoutMillis) {
56
+ return result;
57
+ }
58
+ result = await this.retry(data, remainingTimeoutMillis, retryInMillis);
59
+ }
60
+ return result;
61
+ }
62
+ shutdown() {
63
+ return this._transport.shutdown();
64
+ }
65
+ }
66
+ /**
67
+ * Creates an Exporter Transport that retries on 'retryable' response.
68
+ */
69
+ function createRetryingTransport(options) {
70
+ return new RetryingTransport(options.transport);
71
+ }
72
+ exports.createRetryingTransport = createRetryingTransport;
73
+ //# sourceMappingURL=retrying-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrying-transport.js","sourceRoot":"","sources":["../../src/retrying-transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKH,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,MAAM,GAAG,GAAG,CAAC;AAEnB;;GAEG;AACH,SAAS,SAAS;IAChB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AAC/C,CAAC;AAED,MAAM,iBAAiB;IACrB,YAAoB,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IAAG,CAAC;IAE9C,KAAK,CACX,IAAg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M,CAAC;IAChB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,OAGvC;IACC,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AALD,0DAKC","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';\n\nconst MAX_ATTEMPTS = 5;\nconst INITIAL_BACKOFF = 1000;\nconst MAX_BACKOFF = 5000;\nconst BACKOFF_MULTIPLIER = 1.5;\nconst JITTER = 0.2;\n\n/**\n * Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]\n */\nfunction getJitter() {\n return Math.random() * (2 * JITTER) - JITTER;\n}\n\nclass RetryingTransport implements IExporterTransport {\n constructor(private _transport: IExporterTransport) {}\n\n private retry(\n data: Uint8Array,\n timeoutMillis: number,\n inMillis: number\n ): Promise<ExportResponse> {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n this._transport.send(data, timeoutMillis).then(resolve, reject);\n }, inMillis);\n });\n }\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const deadline = Date.now() + timeoutMillis;\n let result = await this._transport.send(data, timeoutMillis);\n let attempts = MAX_ATTEMPTS;\n let nextBackoff = INITIAL_BACKOFF;\n\n while (result.status === 'retryable' && attempts > 0) {\n attempts--;\n\n // use maximum of computed backoff and 0 to avoid negative timeouts\n const backoff = Math.max(\n Math.min(nextBackoff, MAX_BACKOFF) + getJitter(),\n 0\n );\n nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;\n const retryInMillis = result.retryInMillis ?? backoff;\n\n // return when expected retry time is after the export deadline.\n const remainingTimeoutMillis = deadline - Date.now();\n if (retryInMillis > remainingTimeoutMillis) {\n return result;\n }\n\n result = await this.retry(data, remainingTimeoutMillis, retryInMillis);\n }\n\n return result;\n }\n\n shutdown() {\n return this._transport.shutdown();\n }\n}\n\n/**\n * Creates an Exporter Transport that retries on 'retryable' response.\n */\nexport function createRetryingTransport(options: {\n // Underlying transport to wrap.\n transport: IExporterTransport;\n}): IExporterTransport {\n return new RetryingTransport(options.transport);\n}\n"]}
@@ -24,8 +24,7 @@ export interface ExportServiceError {
24
24
  * Collector Exporter base config
25
25
  */
26
26
  export interface OTLPExporterConfigBase {
27
- headers?: Partial<Record<string, unknown>>;
28
- hostname?: string;
27
+ headers?: Record<string, string>;
29
28
  url?: string;
30
29
  concurrencyLimit?: number;
31
30
  /** Maximum time the OTLP exporter will wait for each batch export.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAK1C,YAAY,OAAgB,EAAE,IAAa,EAAE,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAW,mBAAmB,CAAC;QAKnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,8CAUC","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/**\n * Interface for handling error\n */\nexport class OTLPExporterError extends Error {\n readonly code?: number;\n override readonly name: string = 'OTLPExporterError';\n readonly data?: string;\n\n constructor(message?: string, code?: number, data?: string) {\n super(message);\n this.data = data;\n this.code = code;\n }\n}\n\n/**\n * Interface for handling export service errors\n */\nexport interface ExportServiceError {\n name: string;\n code: number;\n details: string;\n metadata: { [key: string]: unknown };\n message: string;\n stack: string;\n}\n\n/**\n * Collector Exporter base config\n */\nexport interface OTLPExporterConfigBase {\n headers?: Partial<Record<string, unknown>>;\n hostname?: string;\n url?: string;\n concurrencyLimit?: number;\n /** Maximum time the OTLP exporter will wait for each batch export.\n * The default value is 10000ms. */\n timeoutMillis?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAK1C,YAAY,OAAgB,EAAE,IAAa,EAAE,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAW,mBAAmB,CAAC;QAKnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,8CAUC","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/**\n * Interface for handling error\n */\nexport class OTLPExporterError extends Error {\n readonly code?: number;\n override readonly name: string = 'OTLPExporterError';\n readonly data?: string;\n\n constructor(message?: string, code?: number, data?: string) {\n super(message);\n this.data = data;\n this.code = code;\n }\n}\n\n/**\n * Interface for handling export service errors\n */\nexport interface ExportServiceError {\n name: string;\n code: number;\n details: string;\n metadata: { [key: string]: unknown };\n message: string;\n stack: string;\n}\n\n/**\n * Collector Exporter base config\n */\nexport interface OTLPExporterConfigBase {\n headers?: Record<string, string>;\n url?: string;\n concurrencyLimit?: number;\n /** Maximum time the OTLP exporter will wait for each batch export.\n * The default value is 10000ms. */\n timeoutMillis?: number;\n}\n"]}
@@ -1,32 +1,6 @@
1
- export declare const DEFAULT_EXPORT_MAX_ATTEMPTS = 5;
2
- export declare const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
3
- export declare const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
4
- export declare const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
5
1
  /**
6
2
  * Parses headers from config leaving only those that have defined values
7
3
  * @param partialHeaders
8
4
  */
9
- export declare function parseHeaders(partialHeaders?: Partial<Record<string, unknown>>): Record<string, string>;
10
- /**
11
- * Adds path (version + signal) to a no per-signal endpoint
12
- * @param url
13
- * @param path
14
- * @returns url + path
15
- */
16
- export declare function appendResourcePathToUrl(url: string, path: string): string;
17
- /**
18
- * Adds root path to signal specific endpoint when endpoint contains no path part and no root path
19
- * @param url
20
- * @returns url
21
- */
22
- export declare function appendRootPathToUrlIfNeeded(url: string): string;
23
- /**
24
- * Configure exporter trace timeout value from passed in value or environment variables
25
- * @param timeoutMillis
26
- * @returns timeout value in milliseconds
27
- */
28
- export declare function configureExporterTimeout(timeoutMillis: number | undefined): number;
29
- export declare function invalidTimeout(timeout: number, defaultTimeout: number): number;
30
- export declare function isExportRetryable(statusCode: number): boolean;
31
- export declare function parseRetryAfterToMills(retryAfter?: string | null): number;
5
+ export declare function validateAndNormalizeHeaders(partialHeaders?: Partial<Record<string, unknown>>): Record<string, string>;
32
6
  //# sourceMappingURL=util.d.ts.map