@opentelemetry/otlp-exporter-base 0.52.0 → 0.53.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 (169) hide show
  1. package/build/esm/OTLPExporterBase.d.ts +3 -0
  2. package/build/esm/OTLPExporterBase.js.map +1 -1
  3. package/build/esm/export-response.d.ts +14 -0
  4. package/build/esm/export-response.js +17 -0
  5. package/build/esm/export-response.js.map +1 -0
  6. package/build/esm/exporter-transport.d.ts +6 -0
  7. package/build/esm/exporter-transport.js +17 -0
  8. package/build/esm/exporter-transport.js.map +1 -0
  9. package/build/esm/index.d.ts +2 -0
  10. package/build/esm/index.js +3 -0
  11. package/build/esm/index.js.map +1 -1
  12. package/build/esm/is-export-retryable.d.ts +3 -0
  13. package/build/esm/is-export-retryable.js +35 -0
  14. package/build/esm/is-export-retryable.js.map +1 -0
  15. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  16. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +36 -27
  17. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  18. package/build/esm/platform/browser/index.d.ts +0 -1
  19. package/build/esm/platform/browser/index.js +0 -1
  20. package/build/esm/platform/browser/index.js.map +1 -1
  21. package/build/esm/platform/browser/send-beacon-transport.d.ts +10 -0
  22. package/build/esm/platform/browser/send-beacon-transport.js +47 -0
  23. package/build/esm/platform/browser/send-beacon-transport.js.map +1 -0
  24. package/build/esm/platform/browser/xhr-transport.d.ts +11 -0
  25. package/build/esm/platform/browser/xhr-transport.js +101 -0
  26. package/build/esm/platform/browser/xhr-transport.js.map +1 -0
  27. package/build/esm/platform/index.d.ts +2 -2
  28. package/build/esm/platform/index.js +2 -2
  29. package/build/esm/platform/index.js.map +1 -1
  30. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  31. package/build/esm/platform/node/OTLPExporterNodeBase.js +52 -12
  32. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -1
  33. package/build/esm/platform/node/http-exporter-transport.d.ts +4 -0
  34. package/build/esm/platform/node/http-exporter-transport.js +87 -0
  35. package/build/esm/platform/node/http-exporter-transport.js.map +1 -0
  36. package/build/esm/platform/node/http-transport-types.d.ts +12 -0
  37. package/build/esm/platform/node/http-transport-types.js +17 -0
  38. package/build/esm/platform/node/http-transport-types.js.map +1 -0
  39. package/build/esm/platform/node/http-transport-utils.d.ts +16 -0
  40. package/build/esm/platform/node/http-transport-utils.js +127 -0
  41. package/build/esm/platform/node/http-transport-utils.js.map +1 -0
  42. package/build/esm/platform/node/index.d.ts +0 -1
  43. package/build/esm/platform/node/index.js +0 -1
  44. package/build/esm/platform/node/index.js.map +1 -1
  45. package/build/esm/platform/node/util.d.ts +0 -16
  46. package/build/esm/platform/node/util.js +0 -164
  47. package/build/esm/platform/node/util.js.map +1 -1
  48. package/build/esm/retrying-transport.d.ts +8 -0
  49. package/build/esm/retrying-transport.js +119 -0
  50. package/build/esm/retrying-transport.js.map +1 -0
  51. package/build/esm/version.d.ts +1 -1
  52. package/build/esm/version.js +1 -1
  53. package/build/esm/version.js.map +1 -1
  54. package/build/esnext/OTLPExporterBase.d.ts +3 -0
  55. package/build/esnext/OTLPExporterBase.js.map +1 -1
  56. package/build/esnext/export-response.d.ts +14 -0
  57. package/build/esnext/export-response.js +17 -0
  58. package/build/esnext/export-response.js.map +1 -0
  59. package/build/esnext/exporter-transport.d.ts +6 -0
  60. package/build/esnext/exporter-transport.js +17 -0
  61. package/build/esnext/exporter-transport.js.map +1 -0
  62. package/build/esnext/index.d.ts +2 -0
  63. package/build/esnext/index.js +3 -0
  64. package/build/esnext/index.js.map +1 -1
  65. package/build/esnext/is-export-retryable.d.ts +3 -0
  66. package/build/esnext/is-export-retryable.js +35 -0
  67. package/build/esnext/is-export-retryable.js.map +1 -0
  68. package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  69. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +36 -16
  70. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  71. package/build/esnext/platform/browser/index.d.ts +0 -1
  72. package/build/esnext/platform/browser/index.js +0 -1
  73. package/build/esnext/platform/browser/index.js.map +1 -1
  74. package/build/esnext/platform/browser/send-beacon-transport.d.ts +10 -0
  75. package/build/esnext/platform/browser/send-beacon-transport.js +45 -0
  76. package/build/esnext/platform/browser/send-beacon-transport.js.map +1 -0
  77. package/build/esnext/platform/browser/xhr-transport.d.ts +11 -0
  78. package/build/esnext/platform/browser/xhr-transport.js +82 -0
  79. package/build/esnext/platform/browser/xhr-transport.js.map +1 -0
  80. package/build/esnext/platform/index.d.ts +2 -2
  81. package/build/esnext/platform/index.js +2 -2
  82. package/build/esnext/platform/index.js.map +1 -1
  83. package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  84. package/build/esnext/platform/node/OTLPExporterNodeBase.js +52 -12
  85. package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -1
  86. package/build/esnext/platform/node/http-exporter-transport.d.ts +4 -0
  87. package/build/esnext/platform/node/http-exporter-transport.js +47 -0
  88. package/build/esnext/platform/node/http-exporter-transport.js.map +1 -0
  89. package/build/esnext/platform/node/http-transport-types.d.ts +12 -0
  90. package/build/esnext/platform/node/http-transport-types.js +17 -0
  91. package/build/esnext/platform/node/http-transport-types.js.map +1 -0
  92. package/build/esnext/platform/node/http-transport-utils.d.ts +16 -0
  93. package/build/esnext/platform/node/http-transport-utils.js +116 -0
  94. package/build/esnext/platform/node/http-transport-utils.js.map +1 -0
  95. package/build/esnext/platform/node/index.d.ts +0 -1
  96. package/build/esnext/platform/node/index.js +0 -1
  97. package/build/esnext/platform/node/index.js.map +1 -1
  98. package/build/esnext/platform/node/util.d.ts +0 -16
  99. package/build/esnext/platform/node/util.js +0 -151
  100. package/build/esnext/platform/node/util.js.map +1 -1
  101. package/build/esnext/retrying-transport.d.ts +8 -0
  102. package/build/esnext/retrying-transport.js +69 -0
  103. package/build/esnext/retrying-transport.js.map +1 -0
  104. package/build/esnext/version.d.ts +1 -1
  105. package/build/esnext/version.js +1 -1
  106. package/build/esnext/version.js.map +1 -1
  107. package/build/src/OTLPExporterBase.d.ts +3 -0
  108. package/build/src/OTLPExporterBase.js.map +1 -1
  109. package/build/src/export-response.d.ts +14 -0
  110. package/build/src/export-response.js +18 -0
  111. package/build/src/export-response.js.map +1 -0
  112. package/build/src/exporter-transport.d.ts +6 -0
  113. package/build/src/exporter-transport.js +18 -0
  114. package/build/src/exporter-transport.js.map +1 -0
  115. package/build/src/index.d.ts +2 -0
  116. package/build/src/index.js +15 -12
  117. package/build/src/index.js.map +1 -1
  118. package/build/src/is-export-retryable.d.ts +3 -0
  119. package/build/src/is-export-retryable.js +40 -0
  120. package/build/src/is-export-retryable.js.map +1 -0
  121. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  122. package/build/src/platform/browser/OTLPExporterBrowserBase.js +36 -16
  123. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  124. package/build/src/platform/browser/index.d.ts +0 -1
  125. package/build/src/platform/browser/index.js +1 -3
  126. package/build/src/platform/browser/index.js.map +1 -1
  127. package/build/src/platform/browser/send-beacon-transport.d.ts +10 -0
  128. package/build/src/platform/browser/send-beacon-transport.js +49 -0
  129. package/build/src/platform/browser/send-beacon-transport.js.map +1 -0
  130. package/build/src/platform/browser/xhr-transport.d.ts +11 -0
  131. package/build/src/platform/browser/xhr-transport.js +86 -0
  132. package/build/src/platform/browser/xhr-transport.js.map +1 -0
  133. package/build/src/platform/index.d.ts +2 -2
  134. package/build/src/platform/index.js +1 -5
  135. package/build/src/platform/index.js.map +1 -1
  136. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  137. package/build/src/platform/node/OTLPExporterNodeBase.js +52 -12
  138. package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -1
  139. package/build/src/platform/node/http-exporter-transport.d.ts +4 -0
  140. package/build/src/platform/node/http-exporter-transport.js +51 -0
  141. package/build/src/platform/node/http-exporter-transport.js.map +1 -0
  142. package/build/src/platform/node/http-transport-types.d.ts +12 -0
  143. package/build/src/platform/node/http-transport-types.js +18 -0
  144. package/build/src/platform/node/http-transport-types.js.map +1 -0
  145. package/build/src/platform/node/http-transport-utils.d.ts +16 -0
  146. package/build/src/platform/node/http-transport-utils.js +121 -0
  147. package/build/src/platform/node/http-transport-utils.js.map +1 -0
  148. package/build/src/platform/node/index.d.ts +0 -1
  149. package/build/src/platform/node/index.js +1 -5
  150. package/build/src/platform/node/index.js.map +1 -1
  151. package/build/src/platform/node/util.d.ts +0 -16
  152. package/build/src/platform/node/util.js +2 -155
  153. package/build/src/platform/node/util.js.map +1 -1
  154. package/build/src/retrying-transport.d.ts +8 -0
  155. package/build/src/retrying-transport.js +73 -0
  156. package/build/src/retrying-transport.js.map +1 -0
  157. package/build/src/version.d.ts +1 -1
  158. package/build/src/version.js +1 -1
  159. package/build/src/version.js.map +1 -1
  160. package/package.json +11 -12
  161. package/build/esm/platform/browser/util.d.ts +0 -21
  162. package/build/esm/platform/browser/util.js +0 -152
  163. package/build/esm/platform/browser/util.js.map +0 -1
  164. package/build/esnext/platform/browser/util.d.ts +0 -21
  165. package/build/esnext/platform/browser/util.js +0 -122
  166. package/build/esnext/platform/browser/util.js.map +0 -1
  167. package/build/src/platform/browser/util.d.ts +0 -21
  168. package/build/src/platform/browser/util.js +0 -127
  169. package/build/src/platform/browser/util.js.map +0 -1
@@ -1,16 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = exports.OTLPExporterError = exports.OTLPExporterBase = void 0;
14
2
  /*
15
3
  * Copyright The OpenTelemetry Authors
16
4
  *
@@ -26,6 +14,21 @@ exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPa
26
14
  * See the License for the specific language governing permissions and
27
15
  * limitations under the License.
28
16
  */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = exports.OTLPExporterError = exports.OTLPExporterBase = void 0;
29
+ /* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
30
+ * TODO: Replace export * with named exports before next major version
31
+ */
29
32
  __exportStar(require("./platform"), exports);
30
33
  var OTLPExporterBase_1 = require("./OTLPExporterBase");
31
34
  Object.defineProperty(exports, "OTLPExporterBase", { enumerable: true, get: function () { return OTLPExporterBase_1.OTLPExporterBase; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAA2B;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,iCAIiB;AAHf,0GAAA,iBAAiB,OAAA;AAInB,+BAMgB;AALd,oGAAA,YAAY,OAAA;AACZ,+GAAA,uBAAuB,OAAA;AACvB,mHAAA,2BAA2B,OAAA;AAC3B,gHAAA,wBAAwB,OAAA;AACxB,sGAAA,cAAc,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 */\nexport * from './platform';\nexport { OTLPExporterBase } from './OTLPExporterBase';\nexport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nexport {\n parseHeaders,\n appendResourcePathToUrl,\n appendRootPathToUrlIfNeeded,\n configureExporterTimeout,\n invalidTimeout,\n} from './util';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;AAEH;;GAEG;AACH,6CAA2B;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,iCAIiB;AAHf,0GAAA,iBAAiB,OAAA;AAInB,+BAMgB;AALd,oGAAA,YAAY,OAAA;AACZ,+GAAA,uBAAuB,OAAA;AACvB,mHAAA,2BAA2B,OAAA;AAC3B,gHAAA,wBAAwB,OAAA;AACxB,sGAAA,cAAc,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\n/* eslint no-restricted-syntax: [\"warn\", \"ExportAllDeclaration\"] --\n * TODO: Replace export * with named exports before next major version\n */\nexport * from './platform';\nexport { OTLPExporterBase } from './OTLPExporterBase';\nexport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nexport {\n parseHeaders,\n appendResourcePathToUrl,\n appendRootPathToUrlIfNeeded,\n configureExporterTimeout,\n invalidTimeout,\n} from './util';\n\nexport {\n ExportResponse,\n ExportResponseFailure,\n ExportResponseSuccess,\n ExportResponseRetryable,\n} from './export-response';\n\nexport { IExporterTransport } from './exporter-transport';\n"]}
@@ -0,0 +1,3 @@
1
+ export declare function isExportRetryable(statusCode: number): boolean;
2
+ export declare function parseRetryAfterToMills(retryAfter?: string | undefined | null): number | undefined;
3
+ //# sourceMappingURL=is-export-retryable.d.ts.map
@@ -0,0 +1,40 @@
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.parseRetryAfterToMills = exports.isExportRetryable = void 0;
19
+ function isExportRetryable(statusCode) {
20
+ const retryCodes = [429, 502, 503, 504];
21
+ return retryCodes.includes(statusCode);
22
+ }
23
+ exports.isExportRetryable = isExportRetryable;
24
+ function parseRetryAfterToMills(retryAfter) {
25
+ if (retryAfter == null) {
26
+ return undefined;
27
+ }
28
+ const seconds = Number.parseInt(retryAfter, 10);
29
+ if (Number.isInteger(seconds)) {
30
+ return seconds > 0 ? seconds * 1000 : -1;
31
+ }
32
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
33
+ const delay = new Date(retryAfter).getTime() - Date.now();
34
+ if (delay >= 0) {
35
+ return delay;
36
+ }
37
+ return 0;
38
+ }
39
+ exports.parseRetryAfterToMills = parseRetryAfterToMills;
40
+ //# sourceMappingURL=is-export-retryable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-export-retryable.js","sourceRoot":"","sources":["../../src/is-export-retryable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAHD,8CAGC;AAED,SAAgB,sBAAsB,CACpC,UAAsC;IAEtC,IAAI,UAAU,IAAI,IAAI,EAAE;QACtB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC7B,OAAO,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1C;IACD,mFAAmF;IACnF,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE1D,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAlBD,wDAkBC","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 function isExportRetryable(statusCode: number): boolean {\n const retryCodes = [429, 502, 503, 504];\n return retryCodes.includes(statusCode);\n}\n\nexport function parseRetryAfterToMills(\n retryAfter?: string | undefined | null\n): number | undefined {\n if (retryAfter == null) {\n return undefined;\n }\n\n const seconds = Number.parseInt(retryAfter, 10);\n if (Number.isInteger(seconds)) {\n return seconds > 0 ? seconds * 1000 : -1;\n }\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives\n const delay = new Date(retryAfter).getTime() - Date.now();\n\n if (delay >= 0) {\n return delay;\n }\n return 0;\n}\n"]}
@@ -1,15 +1,12 @@
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;
13
10
  /**
14
11
  * @param config
15
12
  * @param serializer
@@ -18,6 +15,6 @@ export declare abstract class OTLPExporterBrowserBase<ExportItem, ServiceRespons
18
15
  constructor(config: OTLPExporterConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, contentType: string);
19
16
  onInit(): void;
20
17
  onShutdown(): void;
21
- send(items: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
18
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
22
19
  }
23
20
  //# sourceMappingURL=OTLPExporterBrowserBase.d.ts.map
@@ -17,10 +17,13 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.OTLPExporterBrowserBase = void 0;
19
19
  const OTLPExporterBase_1 = require("../../OTLPExporterBase");
20
+ const types_1 = require("../../types");
20
21
  const util_1 = require("../../util");
21
- const util_2 = require("./util");
22
22
  const api_1 = require("@opentelemetry/api");
23
23
  const core_1 = require("@opentelemetry/core");
24
+ const xhr_transport_1 = require("./xhr-transport");
25
+ const send_beacon_transport_1 = require("./send-beacon-transport");
26
+ const retrying_transport_1 = require("../../retrying-transport");
24
27
  /**
25
28
  * Collector Metric Exporter abstract base class
26
29
  */
@@ -32,35 +35,52 @@ class OTLPExporterBrowserBase extends OTLPExporterBase_1.OTLPExporterBase {
32
35
  */
33
36
  constructor(config = {}, serializer, contentType) {
34
37
  super(config);
35
- this._useXHR = false;
36
38
  this._serializer = serializer;
37
- this._contentType = contentType;
38
- this._useXHR =
39
- !!config.headers || typeof navigator.sendBeacon !== 'function';
40
- if (this._useXHR) {
41
- this._headers = Object.assign({}, (0, util_1.parseHeaders)(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS));
39
+ const useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';
40
+ if (useXhr) {
41
+ this._transport = (0, retrying_transport_1.createRetryingTransport)({
42
+ transport: (0, xhr_transport_1.createXhrTransport)({
43
+ headers: Object.assign({}, (0, util_1.parseHeaders)(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS), { 'Content-Type': contentType }),
44
+ url: this.url,
45
+ }),
46
+ });
42
47
  }
43
48
  else {
44
- this._headers = {};
49
+ // sendBeacon has no way to signal retry, so we do not wrap it in a RetryingTransport
50
+ this._transport = (0, send_beacon_transport_1.createSendBeaconTransport)({
51
+ url: this.url,
52
+ blobType: contentType,
53
+ });
45
54
  }
46
55
  }
47
56
  onInit() { }
48
57
  onShutdown() { }
49
- send(items, onSuccess, onError) {
50
- var _a;
58
+ send(objects, onSuccess, onError) {
51
59
  if (this._shutdownOnce.isCalled) {
52
60
  api_1.diag.debug('Shutdown already started. Cannot send objects');
53
61
  return;
54
62
  }
55
- const body = (_a = this._serializer.serializeRequest(items)) !== null && _a !== void 0 ? _a : new Uint8Array();
56
- const promise = new Promise((resolve, reject) => {
57
- if (this._useXHR) {
58
- (0, util_2.sendWithXhr)(body, this.url, Object.assign(Object.assign({}, this._headers), { 'Content-Type': this._contentType }), this.timeoutMillis, resolve, reject);
63
+ const data = this._serializer.serializeRequest(objects);
64
+ if (data == null) {
65
+ onError(new Error('Could not serialize message'));
66
+ return;
67
+ }
68
+ const promise = this._transport
69
+ .send(data, this.timeoutMillis)
70
+ .then(response => {
71
+ if (response.status === 'success') {
72
+ onSuccess();
73
+ }
74
+ else if (response.status === 'failure' && response.error) {
75
+ onError(response.error);
76
+ }
77
+ else if (response.status === 'retryable') {
78
+ onError(new types_1.OTLPExporterError('Export failed with retryable status'));
59
79
  }
60
80
  else {
61
- (0, util_2.sendWithBeacon)(body, this.url, { type: this._contentType }, resolve, reject);
81
+ onError(new types_1.OTLPExporterError('Export failed with unknown error'));
62
82
  }
63
- }).then(onSuccess, onError);
83
+ }, onError);
64
84
  this._sendingPromises.push(promise);
65
85
  const popPromise = () => {
66
86
  const 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,6DAA0D;AAG1D,qCAA0C;AAC1C,iCAAqD;AACrD,4CAA0C;AAC1C,8CAA2D;AAG3D;;GAEG;AACH,MAAsB,uBAGpB,SAAQ,mCAAoD;IAM5D;;;;OAIG;IACH,YACE,SAAiC,EAAE,EACnC,UAAsD,EACtD,WAAmB;QAEnB,KAAK,CAAC,MAAM,CAAC,CAAC;QAdR,YAAO,GAAY,KAAK,CAAC;QAe/B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,OAAO;YACV,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;QACjE,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAC3B,EAAE,EACF,IAAA,mBAAY,EAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,mBAAY,CAAC,uBAAuB,CAClC,IAAA,aAAM,GAAE,CAAC,0BAA0B,CACpC,CACF,CAAC;SACH;aAAM;YACL,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;SACpB;IACH,CAAC;IAED,MAAM,KAAU,CAAC;IAEjB,UAAU,KAAU,CAAC;IAErB,IAAI,CACF,KAAmB,EACnB,SAAqB,EACrB,OAAqD;;QAErD,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,UAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QACD,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,mCAAI,IAAI,UAAU,EAAE,CAAC;QAE1E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpD,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAA,kBAAW,EACT,IAAI,EACJ,IAAI,CAAC,GAAG,kCAEH,IAAI,CAAC,QAAQ,KAChB,cAAc,EAAE,IAAI,CAAC,YAAY,KAEnC,IAAI,CAAC,aAAa,EAClB,OAAO,EACP,MAAM,CACP,CAAC;aACH;iBAAM;gBACL,IAAA,qBAAc,EACZ,IAAI,EACJ,IAAI,CAAC,GAAG,EACR,EAAE,IAAI,EAAE,IAAI,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,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;CACF;AAnFD,0DAmFC","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,6DAA0D;AAC1D,uCAAwE;AACxE,qCAA0C;AAC1C,4CAA0C;AAC1C,8CAA2D;AAG3D,mDAAqD;AACrD,mEAAoE;AACpE,iEAAmE;AAEnE;;GAEG;AACH,MAAsB,uBAGpB,SAAQ,mCAAoD;IAI5D;;;;OAIG;IACH,YACE,SAAiC,EAAE,EACnC,UAAsD,EACtD,WAAmB;QAEnB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,MAAM,MAAM,GACV,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;QACjE,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,UAAU,GAAG,IAAA,4CAAuB,EAAC;gBACxC,SAAS,EAAE,IAAA,kCAAkB,EAAC;oBAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,CACpB,EAAE,EACF,IAAA,mBAAY,EAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,mBAAY,CAAC,uBAAuB,CAClC,IAAA,aAAM,GAAE,CAAC,0BAA0B,CACpC,EACD,EAAE,cAAc,EAAE,WAAW,EAAE,CAChC;oBACD,GAAG,EAAE,IAAI,CAAC,GAAG;iBACd,CAAC;aACH,CAAC,CAAC;SACJ;aAAM;YACL,qFAAqF;YACrF,IAAI,CAAC,UAAU,GAAG,IAAA,iDAAyB,EAAC;gBAC1C,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,QAAQ,EAAE,WAAW;aACtB,CAAC,CAAC;SACJ;IACH,CAAC;IAED,MAAM,KAAU,CAAC;IAEjB,UAAU,KAAU,CAAC;IAErB,IAAI,CACF,OAAqB,EACrB,SAAqB,EACrB,OAA2C;QAE3C,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,UAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAExD,IAAI,IAAI,IAAI,IAAI,EAAE;YAChB,OAAO,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;YAClD,OAAO;SACR;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU;aAC5B,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC;aAC9B,IAAI,CAAC,QAAQ,CAAC,EAAE;YACf,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE;gBACjC,SAAS,EAAE,CAAC;aACb;iBAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE;gBAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW,EAAE;gBAC1C,OAAO,CAAC,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;CACF;AAtFD,0DAsFC","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 { parseHeaders } from '../../util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\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';\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\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 const useXhr =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n if (useXhr) {\n this._transport = createRetryingTransport({\n transport: createXhrTransport({\n headers: Object.assign(\n {},\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n ),\n { 'Content-Type': contentType }\n ),\n url: this.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: this.url,\n blobType: contentType,\n });\n }\n }\n\n onInit(): void {}\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
@@ -15,9 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.sendWithXhr = exports.OTLPExporterBrowserBase = void 0;
18
+ exports.OTLPExporterBrowserBase = void 0;
19
19
  var OTLPExporterBrowserBase_1 = require("./OTLPExporterBrowserBase");
20
20
  Object.defineProperty(exports, "OTLPExporterBrowserBase", { enumerable: true, get: function () { return OTLPExporterBrowserBase_1.OTLPExporterBrowserBase; } });
21
- var util_1 = require("./util");
22
- Object.defineProperty(exports, "sendWithXhr", { enumerable: true, get: function () { return util_1.sendWithXhr; } });
23
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,+BAAqC;AAA5B,mGAAA,WAAW,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 { 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,qEAAoE;AAA3D,kIAAA,uBAAuB,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 { 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,49 @@
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.createSendBeaconTransport = void 0;
19
+ const api_1 = require("@opentelemetry/api");
20
+ class SendBeaconTransport {
21
+ constructor(_params) {
22
+ this._params = _params;
23
+ }
24
+ send(data) {
25
+ return new Promise(resolve => {
26
+ if (navigator.sendBeacon(this._params.url, new Blob([data], { type: this._params.blobType }))) {
27
+ // no way to signal retry, treat everything as success
28
+ api_1.diag.debug('SendBeacon success');
29
+ resolve({
30
+ status: 'success',
31
+ });
32
+ }
33
+ else {
34
+ resolve({
35
+ status: 'failure',
36
+ error: new Error('SendBeacon failed'),
37
+ });
38
+ }
39
+ });
40
+ }
41
+ shutdown() {
42
+ // Intentionally left empty, nothing to do.
43
+ }
44
+ }
45
+ function createSendBeaconTransport(parameters) {
46
+ return new SendBeaconTransport(parameters);
47
+ }
48
+ exports.createSendBeaconTransport = createSendBeaconTransport;
49
+ //# 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,4CAA0C;AAU1C,MAAM,mBAAmB;IACvB,YAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,IAAI,CAAC,IAAgB;QACnB,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,IACE,SAAS,CAAC,UAAU,CAClB,IAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAClD,EACD;gBACA,sDAAsD;gBACtD,UAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,SAAgB,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAJD,8DAIC","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,86 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createXhrTransport = void 0;
19
+ const util_1 = require("../../util");
20
+ const api_1 = require("@opentelemetry/api");
21
+ class XhrTransport {
22
+ constructor(_parameters) {
23
+ this._parameters = _parameters;
24
+ }
25
+ send(data, timeoutMillis) {
26
+ return new Promise(resolve => {
27
+ const xhr = new XMLHttpRequest();
28
+ xhr.timeout = timeoutMillis;
29
+ xhr.open('POST', this._parameters.url);
30
+ Object.entries(this._parameters.headers).forEach(([k, v]) => {
31
+ xhr.setRequestHeader(k, v);
32
+ });
33
+ xhr.ontimeout = _ => {
34
+ resolve({
35
+ status: 'failure',
36
+ error: new Error('XHR request timed out'),
37
+ });
38
+ };
39
+ xhr.onreadystatechange = () => {
40
+ if (xhr.status >= 200 && xhr.status <= 299) {
41
+ api_1.diag.debug('XHR success');
42
+ resolve({
43
+ status: 'success',
44
+ });
45
+ }
46
+ else if (xhr.status && (0, util_1.isExportRetryable)(xhr.status)) {
47
+ resolve({
48
+ status: 'retryable',
49
+ retryInMillis: (0, util_1.parseRetryAfterToMills)(xhr.getResponseHeader('Retry-After')),
50
+ });
51
+ }
52
+ else if (xhr.status !== 0) {
53
+ resolve({
54
+ status: 'failure',
55
+ error: new Error('XHR request failed with non-retryable status'),
56
+ });
57
+ }
58
+ };
59
+ xhr.onabort = () => {
60
+ resolve({
61
+ status: 'failure',
62
+ error: new Error('XHR request aborted'),
63
+ });
64
+ };
65
+ xhr.onerror = () => {
66
+ resolve({
67
+ status: 'failure',
68
+ error: new Error('XHR request errored'),
69
+ });
70
+ };
71
+ xhr.send(new Blob([data], { type: this._parameters.headers['Content-Type'] }));
72
+ });
73
+ }
74
+ shutdown() {
75
+ // Intentionally left empty, nothing to do.
76
+ }
77
+ }
78
+ /**
79
+ * Creates an exporter transport that uses XHR to send the data
80
+ * @param parameters applied to each request made by transport
81
+ */
82
+ function createXhrTransport(parameters) {
83
+ return new XhrTransport(parameters);
84
+ }
85
+ exports.createXhrTransport = createXhrTransport;
86
+ //# 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,qCAAuE;AACvE,4CAA0C;AAO1C,MAAM,YAAY;IAChB,YAAoB,WAAiC;QAAjC,gBAAW,GAAX,WAAW,CAAsB;IAAG,CAAC;IAEzD,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAC1C,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;YAC3C,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;gBAC1D,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE;gBAClB,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,uBAAuB,CAAC;iBAC1C,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,GAAG,CAAC,kBAAkB,GAAG,GAAG,EAAE;gBAC5B,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;oBAC1C,UAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAC1B,OAAO,CAAC;wBACN,MAAM,EAAE,SAAS;qBAClB,CAAC,CAAC;iBACJ;qBAAM,IAAI,GAAG,CAAC,MAAM,IAAI,IAAA,wBAAiB,EAAC,GAAG,CAAC,MAAM,CAAC,EAAE;oBACtD,OAAO,CAAC;wBACN,MAAM,EAAE,WAAW;wBACnB,aAAa,EAAE,IAAA,6BAAsB,EACnC,GAAG,CAAC,iBAAiB,CAAC,aAAa,CAAC,CACrC;qBACF,CAAC,CAAC;iBACJ;qBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC3B,OAAO,CAAC;wBACN,MAAM,EAAE,SAAS;wBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,8CAA8C,CAAC;qBACjE,CAAC,CAAC;iBACJ;YACH,CAAC,CAAC;YAEF,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE;gBACjB,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,qBAAqB,CAAC;iBACxC,CAAC,CAAC;YACL,CAAC,CAAC;YACF,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE;gBACjB,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,qBAAqB,CAAC;iBACxC,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,GAAG,CAAC,IAAI,CACN,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAChC,UAAgC;IAEhC,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC;AAJD,gDAIC","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 { isExportRetryable, parseRetryAfterToMills } from '../../util';\nimport { diag } from '@opentelemetry/api';\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
@@ -15,14 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.sendWithXhr = exports.OTLPExporterBrowserBase = exports.CompressionAlgorithm = exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp = exports.OTLPExporterNodeBase = void 0;
18
+ exports.OTLPExporterBrowserBase = exports.CompressionAlgorithm = exports.OTLPExporterNodeBase = void 0;
19
19
  var node_1 = require("./node");
20
20
  Object.defineProperty(exports, "OTLPExporterNodeBase", { enumerable: true, get: function () { return node_1.OTLPExporterNodeBase; } });
21
- Object.defineProperty(exports, "sendWithHttp", { enumerable: true, get: function () { return node_1.sendWithHttp; } });
22
- Object.defineProperty(exports, "createHttpAgent", { enumerable: true, get: function () { return node_1.createHttpAgent; } });
23
- Object.defineProperty(exports, "configureCompression", { enumerable: true, get: function () { return node_1.configureCompression; } });
24
21
  Object.defineProperty(exports, "CompressionAlgorithm", { enumerable: true, get: function () { return node_1.CompressionAlgorithm; } });
25
22
  var browser_1 = require("./browser");
26
23
  Object.defineProperty(exports, "OTLPExporterBrowserBase", { enumerable: true, get: function () { return browser_1.OTLPExporterBrowserBase; } });
27
- Object.defineProperty(exports, "sendWithXhr", { enumerable: true, get: function () { return browser_1.sendWithXhr; } });
28
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAOgB;AANd,4GAAA,oBAAoB,OAAA;AACpB,oGAAA,YAAY,OAAA;AACZ,uGAAA,eAAe,OAAA;AACf,4GAAA,oBAAoB,OAAA;AAEpB,4GAAA,oBAAoB,OAAA;AAEtB,qCAAiE;AAAxD,kHAAA,uBAAuB,OAAA;AAAE,sGAAA,WAAW,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 {\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,+BAIgB;AAHd,4GAAA,oBAAoB,OAAA;AAEpB,4GAAA,oBAAoB,OAAA;AAEtB,qCAAoD;AAA3C,kHAAA,uBAAuB,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 {\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);
10
+ private _transport;
11
+ constructor(config: OTLPExporterNodeConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, signalSpecificHeaders: Record<string, string>);
19
12
  onInit(_config: OTLPExporterNodeConfigBase): void;
20
- send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
13
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
21
14
  onShutdown(): void;
22
15
  }
23
16
  //# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
@@ -17,26 +17,49 @@
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");
20
+ const util_1 = require("./util");
22
21
  const api_1 = require("@opentelemetry/api");
23
22
  const core_1 = require("@opentelemetry/core");
23
+ const http_exporter_transport_1 = require("./http-exporter-transport");
24
+ const types_1 = require("../../types");
25
+ const retrying_transport_1 = require("../../retrying-transport");
24
26
  /**
25
27
  * Collector Metric Exporter abstract base class
26
28
  */
27
29
  class OTLPExporterNodeBase extends OTLPExporterBase_1.OTLPExporterBase {
28
- constructor(config = {}, serializer, contentType) {
30
+ constructor(config = {}, serializer, signalSpecificHeaders) {
31
+ var _a;
29
32
  super(config);
30
- this.DEFAULT_HEADERS = {};
31
- this._contentType = contentType;
32
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
34
  if (config.metadata) {
34
35
  api_1.diag.warn('Metadata cannot be set when using http');
35
36
  }
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
37
  this._serializer = serializer;
38
+ // populate keepAlive for use with new settings
39
+ if ((config === null || config === void 0 ? void 0 : config.keepAlive) != null) {
40
+ if (config.httpAgentOptions != null) {
41
+ if (config.httpAgentOptions.keepAlive == null) {
42
+ // specific setting is not set, populate with non-specific setting.
43
+ config.httpAgentOptions.keepAlive = config.keepAlive;
44
+ }
45
+ // do nothing, use specific setting otherwise
46
+ }
47
+ else {
48
+ // populate specific option if AgentOptions does not exist.
49
+ config.httpAgentOptions = {
50
+ keepAlive: config.keepAlive,
51
+ };
52
+ }
53
+ }
54
+ const nonSignalSpecificHeaders = core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS);
55
+ this._transport = (0, retrying_transport_1.createRetryingTransport)({
56
+ transport: (0, http_exporter_transport_1.createHttpExporterTransport)({
57
+ agentOptions: (_a = config.httpAgentOptions) !== null && _a !== void 0 ? _a : { keepAlive: true },
58
+ compression: (0, util_1.configureCompression)(config.compression),
59
+ headers: Object.assign({}, nonSignalSpecificHeaders, signalSpecificHeaders),
60
+ url: this.url,
61
+ }),
62
+ });
40
63
  }
41
64
  onInit(_config) { }
42
65
  send(objects, onSuccess, onError) {
@@ -44,10 +67,27 @@ class OTLPExporterNodeBase extends OTLPExporterBase_1.OTLPExporterBase {
44
67
  api_1.diag.debug('Shutdown already started. Cannot send objects');
45
68
  return;
46
69
  }
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);
70
+ const data = this._serializer.serializeRequest(objects);
71
+ if (data == null) {
72
+ onError(new Error('Could not serialize message'));
73
+ return;
74
+ }
75
+ const promise = this._transport
76
+ .send(data, this.timeoutMillis)
77
+ .then(response => {
78
+ if (response.status === 'success') {
79
+ onSuccess();
80
+ }
81
+ else if (response.status === 'failure' && response.error) {
82
+ onError(response.error);
83
+ }
84
+ else if (response.status === 'retryable') {
85
+ onError(new types_1.OTLPExporterError('Export failed with retryable status'));
86
+ }
87
+ else {
88
+ onError(new types_1.OTLPExporterError('Export failed with unknown error'));
89
+ }
90
+ }, onError);
51
91
  this._sendingPromises.push(promise);
52
92
  const popPromise = () => {
53
93
  const index = this._sendingPromises.indexOf(promise);