@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
@@ -1,23 +1,21 @@
1
1
  import { OTLPExporterBase } from '../../OTLPExporterBase';
2
- import { OTLPExporterConfigBase } from '../../types';
3
- import * as otlpTypes from '../../types';
2
+ import { OTLPExporterConfigBase, OTLPExporterError } from '../../types';
4
3
  import { ISerializer } from '@opentelemetry/otlp-transformer';
5
4
  /**
6
5
  * Collector Metric Exporter abstract base class
7
6
  */
8
7
  export declare abstract class OTLPExporterBrowserBase<ExportItem, ServiceResponse> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem> {
9
- protected _headers: Record<string, string>;
10
- private _useXHR;
11
- private _contentType;
12
8
  private _serializer;
9
+ private _transport;
10
+ private _timeoutMillis;
13
11
  /**
14
12
  * @param config
15
13
  * @param serializer
16
- * @param contentType
14
+ * @param requiredHeaders
15
+ * @param signalResourcePath
17
16
  */
18
- constructor(config: OTLPExporterConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, contentType: string);
19
- onInit(): void;
17
+ constructor(config: OTLPExporterConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, requiredHeaders: Record<string, string>, signalResourcePath: string);
20
18
  onShutdown(): void;
21
- send(items: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
19
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
22
20
  }
23
21
  //# sourceMappingURL=OTLPExporterBrowserBase.d.ts.map
@@ -28,22 +28,13 @@ var __extends = (this && this.__extends) || (function () {
28
28
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
29
  };
30
30
  })();
31
- var __assign = (this && this.__assign) || function () {
32
- __assign = Object.assign || function(t) {
33
- for (var s, i = 1, n = arguments.length; i < n; i++) {
34
- s = arguments[i];
35
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
36
- t[p] = s[p];
37
- }
38
- return t;
39
- };
40
- return __assign.apply(this, arguments);
41
- };
42
31
  import { OTLPExporterBase } from '../../OTLPExporterBase';
43
- import { parseHeaders } from '../../util';
44
- import { sendWithBeacon, sendWithXhr } from './util';
32
+ import { OTLPExporterError } from '../../types';
45
33
  import { diag } from '@opentelemetry/api';
46
- import { getEnv, baggageUtils } from '@opentelemetry/core';
34
+ import { createXhrTransport } from './xhr-transport';
35
+ import { createSendBeaconTransport } from './send-beacon-transport';
36
+ import { createRetryingTransport } from '../../retrying-transport';
37
+ import { getHttpConfigurationDefaults, mergeOtlpHttpConfigurationWithDefaults, } from '../../configuration/otlp-http-configuration';
47
38
  /**
48
39
  * Collector Metric Exporter abstract base class
49
40
  */
@@ -52,42 +43,68 @@ var OTLPExporterBrowserBase = /** @class */ (function (_super) {
52
43
  /**
53
44
  * @param config
54
45
  * @param serializer
55
- * @param contentType
46
+ * @param requiredHeaders
47
+ * @param signalResourcePath
56
48
  */
57
- function OTLPExporterBrowserBase(config, serializer, contentType) {
49
+ function OTLPExporterBrowserBase(config, serializer, requiredHeaders, signalResourcePath) {
58
50
  if (config === void 0) { config = {}; }
59
51
  var _this = _super.call(this, config) || this;
60
- _this._useXHR = false;
61
52
  _this._serializer = serializer;
62
- _this._contentType = contentType;
63
- _this._useXHR =
64
- !!config.headers || typeof navigator.sendBeacon !== 'function';
65
- if (_this._useXHR) {
66
- _this._headers = Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
53
+ var useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';
54
+ var actualConfig = mergeOtlpHttpConfigurationWithDefaults({
55
+ url: config.url,
56
+ timeoutMillis: config.timeoutMillis,
57
+ headers: config.headers,
58
+ concurrencyLimit: config.concurrencyLimit,
59
+ }, {}, // no fallback for browser case
60
+ getHttpConfigurationDefaults(requiredHeaders, signalResourcePath));
61
+ _this._timeoutMillis = actualConfig.timeoutMillis;
62
+ _this._concurrencyLimit = actualConfig.concurrencyLimit;
63
+ if (useXhr) {
64
+ _this._transport = createRetryingTransport({
65
+ transport: createXhrTransport({
66
+ headers: actualConfig.headers,
67
+ url: actualConfig.url,
68
+ }),
69
+ });
67
70
  }
68
71
  else {
69
- _this._headers = {};
72
+ // sendBeacon has no way to signal retry, so we do not wrap it in a RetryingTransport
73
+ _this._transport = createSendBeaconTransport({
74
+ url: actualConfig.url,
75
+ blobType: actualConfig.headers['Content-Type'],
76
+ });
70
77
  }
71
78
  return _this;
72
79
  }
73
- OTLPExporterBrowserBase.prototype.onInit = function () { };
74
80
  OTLPExporterBrowserBase.prototype.onShutdown = function () { };
75
- OTLPExporterBrowserBase.prototype.send = function (items, onSuccess, onError) {
81
+ OTLPExporterBrowserBase.prototype.send = function (objects, onSuccess, onError) {
76
82
  var _this = this;
77
- var _a;
78
83
  if (this._shutdownOnce.isCalled) {
79
84
  diag.debug('Shutdown already started. Cannot send objects');
80
85
  return;
81
86
  }
82
- var body = (_a = this._serializer.serializeRequest(items)) !== null && _a !== void 0 ? _a : new Uint8Array();
83
- var promise = new Promise(function (resolve, reject) {
84
- if (_this._useXHR) {
85
- sendWithXhr(body, _this.url, __assign(__assign({}, _this._headers), { 'Content-Type': _this._contentType }), _this.timeoutMillis, resolve, reject);
87
+ var data = this._serializer.serializeRequest(objects);
88
+ if (data == null) {
89
+ onError(new Error('Could not serialize message'));
90
+ return;
91
+ }
92
+ var promise = this._transport
93
+ .send(data, this._timeoutMillis)
94
+ .then(function (response) {
95
+ if (response.status === 'success') {
96
+ onSuccess();
97
+ }
98
+ else if (response.status === 'failure' && response.error) {
99
+ onError(response.error);
100
+ }
101
+ else if (response.status === 'retryable') {
102
+ onError(new OTLPExporterError('Export failed with retryable status'));
86
103
  }
87
104
  else {
88
- sendWithBeacon(body, _this.url, { type: _this._contentType }, resolve, reject);
105
+ onError(new OTLPExporterError('Export failed with unknown error'));
89
106
  }
90
- }).then(onSuccess, onError);
107
+ }, onError);
91
108
  this._sendingPromises.push(promise);
92
109
  var popPromise = function () {
93
110
  var index = _this._sendingPromises.indexOf(promise);
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH;IAGU,2CAAoD;IAM5D;;;;OAIG;IACH,iCACE,MAAmC,EACnC,UAAsD,EACt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aACH;iBAAM;gBACL,cAAc,CACZ,IAAI,EACJ,KAAI,CAAC,GAAG,EACR,EAAE,IAAI,EAAE,KAAI,CAAC,YAAY,EAAE,EAC3B,OAAO,EACP,MAAM,CACP,CAAC;aACH;QACH,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,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;IACH,8BAAC;AAAD,CAAC,AAnFD,CAGU,gBAAgB,GAgFzB","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 { OTLPExporterConfigBase } from '../../types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { sendWithBeacon, sendWithXhr } 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 OTLPExporterBrowserBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem> {\n protected _headers: Record<string, string>;\n private _useXHR: boolean = false;\n private _contentType: string;\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n\n /**\n * @param config\n * @param serializer\n * @param contentType\n */\n constructor(\n config: OTLPExporterConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n contentType: string\n ) {\n super(config);\n this._serializer = serializer;\n this._contentType = contentType;\n this._useXHR =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n if (this._useXHR) {\n this._headers = Object.assign(\n {},\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n )\n );\n } else {\n this._headers = {};\n }\n }\n\n onInit(): void {}\n\n onShutdown(): void {}\n\n send(\n items: 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 const body = this._serializer.serializeRequest(items) ?? new Uint8Array();\n\n const promise = new Promise<void>((resolve, reject) => {\n if (this._useXHR) {\n sendWithXhr(\n body,\n this.url,\n {\n ...this._headers,\n 'Content-Type': this._contentType,\n },\n this.timeoutMillis,\n resolve,\n reject\n );\n } else {\n sendWithBeacon(\n body,\n this.url,\n { type: this._contentType },\n resolve,\n reject\n );\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"]}
1
+ {"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAA0B,iBAAiB,EAAE,MAAM,aA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C,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,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;IACH,8BAAC;AAAD,CAAC,AA/FD,CAGU,gBAAgB,GA4FzB","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 { OTLPExporterConfigBase, OTLPExporterError } from '../../types';\nimport { diag } from '@opentelemetry/api';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { IExporterTransport } from '../../exporter-transport';\nimport { createXhrTransport } from './xhr-transport';\nimport { createSendBeaconTransport } from './send-beacon-transport';\nimport { createRetryingTransport } from '../../retrying-transport';\nimport {\n getHttpConfigurationDefaults,\n mergeOtlpHttpConfigurationWithDefaults,\n} from '../../configuration/otlp-http-configuration';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterBrowserBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem> {\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _transport: IExporterTransport;\n private _timeoutMillis: number;\n\n /**\n * @param config\n * @param serializer\n * @param requiredHeaders\n * @param signalResourcePath\n */\n constructor(\n config: OTLPExporterConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n requiredHeaders: Record<string, string>,\n signalResourcePath: string\n ) {\n super(config);\n this._serializer = serializer;\n const useXhr =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n\n const actualConfig = mergeOtlpHttpConfigurationWithDefaults(\n {\n url: config.url,\n timeoutMillis: config.timeoutMillis,\n headers: config.headers,\n concurrencyLimit: config.concurrencyLimit,\n },\n {}, // no fallback for browser case\n getHttpConfigurationDefaults(requiredHeaders, signalResourcePath)\n );\n\n this._timeoutMillis = actualConfig.timeoutMillis;\n this._concurrencyLimit = actualConfig.concurrencyLimit;\n\n if (useXhr) {\n this._transport = createRetryingTransport({\n transport: createXhrTransport({\n headers: actualConfig.headers,\n url: actualConfig.url,\n }),\n });\n } else {\n // sendBeacon has no way to signal retry, so we do not wrap it in a RetryingTransport\n this._transport = createSendBeaconTransport({\n url: actualConfig.url,\n blobType: actualConfig.headers['Content-Type'],\n });\n }\n }\n\n onShutdown(): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const data = this._serializer.serializeRequest(objects);\n\n if (data == null) {\n onError(new Error('Could not serialize message'));\n return;\n }\n\n const promise = this._transport\n .send(data, this._timeoutMillis)\n .then(response => {\n if (response.status === 'success') {\n onSuccess();\n } else if (response.status === 'failure' && response.error) {\n onError(response.error);\n } else if (response.status === 'retryable') {\n onError(new OTLPExporterError('Export failed with retryable status'));\n } else {\n onError(new OTLPExporterError('Export failed with unknown error'));\n }\n }, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n}\n"]}
@@ -1,3 +1,2 @@
1
1
  export { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
2
- export { sendWithXhr } from './util';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -14,5 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
17
- export { sendWithXhr } from './util';
18
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,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 { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';\nexport { sendWithXhr } from './util';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,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 { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';\n"]}
@@ -0,0 +1,10 @@
1
+ import { IExporterTransport } from '../../exporter-transport';
2
+ export interface SendBeaconParameters {
3
+ url: string;
4
+ /**
5
+ * for instance 'application/x-protobuf'
6
+ */
7
+ blobType: string;
8
+ }
9
+ export declare function createSendBeaconTransport(parameters: SendBeaconParameters): IExporterTransport;
10
+ //# sourceMappingURL=send-beacon-transport.d.ts.map
@@ -0,0 +1,47 @@
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 { diag } from '@opentelemetry/api';
17
+ var SendBeaconTransport = /** @class */ (function () {
18
+ function SendBeaconTransport(_params) {
19
+ this._params = _params;
20
+ }
21
+ SendBeaconTransport.prototype.send = function (data) {
22
+ var _this = this;
23
+ return new Promise(function (resolve) {
24
+ if (navigator.sendBeacon(_this._params.url, new Blob([data], { type: _this._params.blobType }))) {
25
+ // no way to signal retry, treat everything as success
26
+ diag.debug('SendBeacon success');
27
+ resolve({
28
+ status: 'success',
29
+ });
30
+ }
31
+ else {
32
+ resolve({
33
+ status: 'failure',
34
+ error: new Error('SendBeacon failed'),
35
+ });
36
+ }
37
+ });
38
+ };
39
+ SendBeaconTransport.prototype.shutdown = function () {
40
+ // Intentionally left empty, nothing to do.
41
+ };
42
+ return SendBeaconTransport;
43
+ }());
44
+ export function createSendBeaconTransport(parameters) {
45
+ return new SendBeaconTransport(parameters);
46
+ }
47
+ //# sourceMappingURL=send-beacon-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../../src/platform/browser/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU1C;IACE,6BAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,kCAAI,GAAJ,UAAK,IAAgB;QAArB,iBAoBC;QAnBC,OAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;YACxC,IACE,SAAS,CAAC,UAAU,CAClB,KAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAClD,EACD;gBACA,sDAAsD;gBACtD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sCAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,0BAAC;AAAD,CAAC,AA3BD,IA2BC;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../../exporter-transport';\nimport { ExportResponse } from '../../export-response';\nimport { diag } from '@opentelemetry/api';\n\nexport interface SendBeaconParameters {\n url: string;\n /**\n * for instance 'application/x-protobuf'\n */\n blobType: string;\n}\n\nclass SendBeaconTransport implements IExporterTransport {\n constructor(private _params: SendBeaconParameters) {}\n send(data: Uint8Array): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n if (\n navigator.sendBeacon(\n this._params.url,\n new Blob([data], { type: this._params.blobType })\n )\n ) {\n // no way to signal retry, treat everything as success\n diag.debug('SendBeacon success');\n resolve({\n status: 'success',\n });\n } else {\n resolve({\n status: 'failure',\n error: new Error('SendBeacon failed'),\n });\n }\n });\n }\n\n shutdown(): void {\n // Intentionally left empty, nothing to do.\n }\n}\n\nexport function createSendBeaconTransport(\n parameters: SendBeaconParameters\n): IExporterTransport {\n return new SendBeaconTransport(parameters);\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { IExporterTransport } from '../../exporter-transport';
2
+ export interface XhrRequestParameters {
3
+ url: string;
4
+ headers: Record<string, string>;
5
+ }
6
+ /**
7
+ * Creates an exporter transport that uses XHR to send the data
8
+ * @param parameters applied to each request made by transport
9
+ */
10
+ export declare function createXhrTransport(parameters: XhrRequestParameters): IExporterTransport;
11
+ //# sourceMappingURL=xhr-transport.d.ts.map
@@ -0,0 +1,101 @@
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
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
18
+ if (!m) return o;
19
+ var i = m.call(o), r, ar = [], e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
29
+ }
30
+ return ar;
31
+ };
32
+ import { diag } from '@opentelemetry/api';
33
+ import { isExportRetryable, parseRetryAfterToMills, } from '../../is-export-retryable';
34
+ var XhrTransport = /** @class */ (function () {
35
+ function XhrTransport(_parameters) {
36
+ this._parameters = _parameters;
37
+ }
38
+ XhrTransport.prototype.send = function (data, timeoutMillis) {
39
+ var _this = this;
40
+ return new Promise(function (resolve) {
41
+ var xhr = new XMLHttpRequest();
42
+ xhr.timeout = timeoutMillis;
43
+ xhr.open('POST', _this._parameters.url);
44
+ Object.entries(_this._parameters.headers).forEach(function (_a) {
45
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
46
+ xhr.setRequestHeader(k, v);
47
+ });
48
+ xhr.ontimeout = function (_) {
49
+ resolve({
50
+ status: 'failure',
51
+ error: new Error('XHR request timed out'),
52
+ });
53
+ };
54
+ xhr.onreadystatechange = function () {
55
+ if (xhr.status >= 200 && xhr.status <= 299) {
56
+ diag.debug('XHR success');
57
+ resolve({
58
+ status: 'success',
59
+ });
60
+ }
61
+ else if (xhr.status && isExportRetryable(xhr.status)) {
62
+ resolve({
63
+ status: 'retryable',
64
+ retryInMillis: parseRetryAfterToMills(xhr.getResponseHeader('Retry-After')),
65
+ });
66
+ }
67
+ else if (xhr.status !== 0) {
68
+ resolve({
69
+ status: 'failure',
70
+ error: new Error('XHR request failed with non-retryable status'),
71
+ });
72
+ }
73
+ };
74
+ xhr.onabort = function () {
75
+ resolve({
76
+ status: 'failure',
77
+ error: new Error('XHR request aborted'),
78
+ });
79
+ };
80
+ xhr.onerror = function () {
81
+ resolve({
82
+ status: 'failure',
83
+ error: new Error('XHR request errored'),
84
+ });
85
+ };
86
+ xhr.send(new Blob([data], { type: _this._parameters.headers['Content-Type'] }));
87
+ });
88
+ };
89
+ XhrTransport.prototype.shutdown = function () {
90
+ // Intentionally left empty, nothing to do.
91
+ };
92
+ return XhrTransport;
93
+ }());
94
+ /**
95
+ * Creates an exporter transport that uses XHR to send the data
96
+ * @param parameters applied to each request made by transport
97
+ */
98
+ export function createXhrTransport(parameters) {
99
+ return new XhrTransport(parameters);
100
+ }
101
+ //# sourceMappingURL=xhr-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhr-transport.js","sourceRoot":"","sources":["../../../../src/platform/browser/xhr-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AAOnC;IACE,sBAAoB,WAAiC;QAAjC,gBAAW,GAAX,WAAW,CAAsB;IAAG,CAAC;IAEzD,2BAAI,GAAJ,UAAK,IAAgB,EAAE,aAAqB;QAA5C,iBAsDC;QArDC,OAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;YACxC,IAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,CAAC,KAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,EAAM;oBAAN,KAAA,aAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;gBACrD,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7B,CAA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AAE,EAAE,IAAI,EAAE,KAAI,CAAC,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,+BAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,mBAAC;AAAD,CAAC,AA9DD,IA8DC;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 Object.entries(this._parameters.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(\n new Blob([data], { type: this._parameters.headers['Content-Type'] })\n );\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,3 +1,3 @@
1
- export { OTLPExporterNodeBase, sendWithHttp, createHttpAgent, configureCompression, OTLPExporterNodeConfigBase, CompressionAlgorithm, } from './node';
2
- export { OTLPExporterBrowserBase, sendWithXhr } from './browser';
1
+ export { OTLPExporterNodeBase, OTLPExporterNodeConfigBase, CompressionAlgorithm, } from './node';
2
+ export { OTLPExporterBrowserBase } from './browser';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -13,6 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { OTLPExporterNodeBase, sendWithHttp, createHttpAgent, configureCompression, CompressionAlgorithm, } from './node';
17
- export { OTLPExporterBrowserBase, sendWithXhr } from './browser';
16
+ export { OTLPExporterNodeBase, CompressionAlgorithm, } from './node';
17
+ export { OTLPExporterBrowserBase } from './browser';
18
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,oBAAoB,EAEpB,oBAAoB,GACrB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,WAAW,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 {\n OTLPExporterNodeBase,\n sendWithHttp,\n createHttpAgent,\n configureCompression,\n OTLPExporterNodeConfigBase,\n CompressionAlgorithm,\n} from './node';\nexport { OTLPExporterBrowserBase, sendWithXhr } from './browser';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,oBAAoB,EAEpB,oBAAoB,GACrB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,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 {\n OTLPExporterNodeBase,\n OTLPExporterNodeConfigBase,\n CompressionAlgorithm,\n} from './node';\nexport { OTLPExporterBrowserBase } from './browser';\n"]}
@@ -1,23 +1,16 @@
1
- /// <reference types="node" />
2
- import type * as http from 'http';
3
- import type * as https from 'https';
4
1
  import { OTLPExporterBase } from '../../OTLPExporterBase';
5
- import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
6
- import * as otlpTypes from '../../types';
2
+ import { OTLPExporterNodeConfigBase } from './types';
7
3
  import { ISerializer } from '@opentelemetry/otlp-transformer';
4
+ import { OTLPExporterError } from '../../types';
8
5
  /**
9
6
  * Collector Metric Exporter abstract base class
10
7
  */
11
8
  export declare abstract class OTLPExporterNodeBase<ExportItem, ServiceResponse> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {
12
- DEFAULT_HEADERS: Record<string, string>;
13
- headers: Record<string, string>;
14
- agent: http.Agent | https.Agent | undefined;
15
- compression: CompressionAlgorithm;
16
9
  private _serializer;
17
- private _contentType;
18
- constructor(config: OTLPExporterNodeConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, contentType: string);
19
- onInit(_config: OTLPExporterNodeConfigBase): void;
20
- send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
10
+ private _transport;
11
+ private _timeoutMillis;
12
+ constructor(config: OTLPExporterNodeConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, requiredHeaders: Record<string, string>, signalIdentifier: string, signalResourcePath: string);
13
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
21
14
  onShutdown(): void;
22
15
  }
23
16
  //# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
@@ -29,41 +29,72 @@ var __extends = (this && this.__extends) || (function () {
29
29
  };
30
30
  })();
31
31
  import { OTLPExporterBase } from '../../OTLPExporterBase';
32
- import { parseHeaders } from '../../util';
33
- import { createHttpAgent, sendWithHttp, configureCompression } from './util';
34
32
  import { diag } from '@opentelemetry/api';
35
- import { getEnv, baggageUtils } from '@opentelemetry/core';
33
+ import { createHttpExporterTransport } from './http-exporter-transport';
34
+ import { OTLPExporterError } from '../../types';
35
+ import { createRetryingTransport } from '../../retrying-transport';
36
+ import { convertLegacyAgentOptions } from './convert-legacy-agent-options';
37
+ import { getHttpConfigurationDefaults, mergeOtlpHttpConfigurationWithDefaults, } from '../../configuration/otlp-http-configuration';
38
+ import { getHttpConfigurationFromEnvironment } from '../../configuration/otlp-http-env-configuration';
36
39
  /**
37
40
  * Collector Metric Exporter abstract base class
38
41
  */
39
42
  var OTLPExporterNodeBase = /** @class */ (function (_super) {
40
43
  __extends(OTLPExporterNodeBase, _super);
41
- function OTLPExporterNodeBase(config, serializer, contentType) {
44
+ function OTLPExporterNodeBase(config, serializer, requiredHeaders, signalIdentifier, signalResourcePath) {
42
45
  if (config === void 0) { config = {}; }
43
46
  var _this = _super.call(this, config) || this;
44
- _this.DEFAULT_HEADERS = {};
45
- _this._contentType = contentType;
47
+ var actualConfig = mergeOtlpHttpConfigurationWithDefaults({
48
+ url: config.url,
49
+ headers: config.headers,
50
+ concurrencyLimit: config.concurrencyLimit,
51
+ timeoutMillis: config.timeoutMillis,
52
+ compression: config.compression,
53
+ }, getHttpConfigurationFromEnvironment(signalIdentifier, signalResourcePath), getHttpConfigurationDefaults(requiredHeaders, signalResourcePath));
54
+ _this._timeoutMillis = actualConfig.timeoutMillis;
55
+ _this._concurrencyLimit = actualConfig.concurrencyLimit;
46
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
57
  if (config.metadata) {
48
58
  diag.warn('Metadata cannot be set when using http');
49
59
  }
50
- _this.headers = Object.assign(_this.DEFAULT_HEADERS, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
51
- _this.agent = createHttpAgent(config);
52
- _this.compression = configureCompression(config.compression);
53
60
  _this._serializer = serializer;
61
+ _this._transport = createRetryingTransport({
62
+ transport: createHttpExporterTransport({
63
+ agentOptions: convertLegacyAgentOptions(config),
64
+ compression: actualConfig.compression,
65
+ headers: actualConfig.headers,
66
+ url: actualConfig.url,
67
+ }),
68
+ });
54
69
  return _this;
55
70
  }
56
- OTLPExporterNodeBase.prototype.onInit = function (_config) { };
57
71
  OTLPExporterNodeBase.prototype.send = function (objects, onSuccess, onError) {
58
72
  var _this = this;
59
73
  if (this._shutdownOnce.isCalled) {
60
74
  diag.debug('Shutdown already started. Cannot send objects');
61
75
  return;
62
76
  }
63
- var promise = new Promise(function (resolve, reject) {
64
- var _a;
65
- sendWithHttp(_this, (_a = _this._serializer.serializeRequest(objects)) !== null && _a !== void 0 ? _a : new Uint8Array(), _this._contentType, resolve, reject);
66
- }).then(onSuccess, onError);
77
+ var data = this._serializer.serializeRequest(objects);
78
+ if (data == null) {
79
+ onError(new Error('Could not serialize message'));
80
+ return;
81
+ }
82
+ var promise = this._transport
83
+ .send(data, this._timeoutMillis)
84
+ .then(function (response) {
85
+ if (response.status === 'success') {
86
+ onSuccess();
87
+ }
88
+ else if (response.status === 'failure' && response.error) {
89
+ onError(response.error);
90
+ }
91
+ else if (response.status === 'retryable') {
92
+ onError(new OTLPExporterError('Export failed with retryable status'));
93
+ }
94
+ else {
95
+ onError(new OTLPExporterError('Export failed with unknown error'));
96
+ }
97
+ }, onError);
67
98
  this._sendingPromises.push(promise);
68
99
  var popPromise = function () {
69
100
  var 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,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH;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CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,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,yCAAU,GAAV,cAAoB,CAAC;IACvB,2BAAC;AAAD,CAAC,AA/DD,CAGU,gBAAgB,GA4DzB","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';\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,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM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CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,yCAAU,GAAV,cAAoB,CAAC;IACvB,2BAAC;AAAD,CAAC,AAvFD,CAGU,gBAAgB,GAoFzB","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