@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
@@ -14,10 +14,13 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { OTLPExporterBase } from '../../OTLPExporterBase';
17
+ import { OTLPExporterError } from '../../types';
17
18
  import { parseHeaders } from '../../util';
18
- import { sendWithBeacon, sendWithXhr } from './util';
19
19
  import { diag } from '@opentelemetry/api';
20
20
  import { getEnv, baggageUtils } from '@opentelemetry/core';
21
+ import { createXhrTransport } from './xhr-transport';
22
+ import { createSendBeaconTransport } from './send-beacon-transport';
23
+ import { createRetryingTransport } from '../../retrying-transport';
21
24
  /**
22
25
  * Collector Metric Exporter abstract base class
23
26
  */
@@ -29,35 +32,52 @@ export class OTLPExporterBrowserBase extends OTLPExporterBase {
29
32
  */
30
33
  constructor(config = {}, serializer, contentType) {
31
34
  super(config);
32
- this._useXHR = false;
33
35
  this._serializer = serializer;
34
- this._contentType = contentType;
35
- this._useXHR =
36
- !!config.headers || typeof navigator.sendBeacon !== 'function';
37
- if (this._useXHR) {
38
- this._headers = Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
36
+ const useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';
37
+ if (useXhr) {
38
+ this._transport = createRetryingTransport({
39
+ transport: createXhrTransport({
40
+ headers: Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS), { 'Content-Type': contentType }),
41
+ url: this.url,
42
+ }),
43
+ });
39
44
  }
40
45
  else {
41
- this._headers = {};
46
+ // sendBeacon has no way to signal retry, so we do not wrap it in a RetryingTransport
47
+ this._transport = createSendBeaconTransport({
48
+ url: this.url,
49
+ blobType: contentType,
50
+ });
42
51
  }
43
52
  }
44
53
  onInit() { }
45
54
  onShutdown() { }
46
- send(items, onSuccess, onError) {
47
- var _a;
55
+ send(objects, onSuccess, onError) {
48
56
  if (this._shutdownOnce.isCalled) {
49
57
  diag.debug('Shutdown already started. Cannot send objects');
50
58
  return;
51
59
  }
52
- const body = (_a = this._serializer.serializeRequest(items)) !== null && _a !== void 0 ? _a : new Uint8Array();
53
- const promise = new Promise((resolve, reject) => {
54
- if (this._useXHR) {
55
- sendWithXhr(body, this.url, Object.assign(Object.assign({}, this._headers), { 'Content-Type': this._contentType }), this.timeoutMillis, resolve, reject);
60
+ const data = this._serializer.serializeRequest(objects);
61
+ if (data == null) {
62
+ onError(new Error('Could not serialize message'));
63
+ return;
64
+ }
65
+ const promise = this._transport
66
+ .send(data, this.timeoutMillis)
67
+ .then(response => {
68
+ if (response.status === 'success') {
69
+ onSuccess();
70
+ }
71
+ else if (response.status === 'failure' && response.error) {
72
+ onError(response.error);
73
+ }
74
+ else if (response.status === 'retryable') {
75
+ onError(new OTLPExporterError('Export failed with retryable status'));
56
76
  }
57
77
  else {
58
- sendWithBeacon(body, this.url, { type: this._contentType }, resolve, reject);
78
+ onError(new OTLPExporterError('Export failed with unknown error'));
59
79
  }
60
- }).then(onSuccess, onError);
80
+ }, onError);
61
81
  this._sendingPromises.push(promise);
62
82
  const popPromise = () => {
63
83
  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,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,MAAM,OAAgB,uBAGpB,SAAQ,gBAAoD;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;Y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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","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,aAAa,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAgB,uBAGpB,SAAQ,gBAAoD;IAI5D;;;;OAIG;IACH,YACE,SAAiC,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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,iBAAiB,CAAC,qCAAqC,CAAC,CAAC,CAAC;aACvE;iBAAM;gBACL,OAAO,CAAC,IAAI,iBAAiB,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","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
@@ -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,45 @@
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
+ class SendBeaconTransport {
18
+ constructor(_params) {
19
+ this._params = _params;
20
+ }
21
+ send(data) {
22
+ return new Promise(resolve => {
23
+ if (navigator.sendBeacon(this._params.url, new Blob([data], { type: this._params.blobType }))) {
24
+ // no way to signal retry, treat everything as success
25
+ diag.debug('SendBeacon success');
26
+ resolve({
27
+ status: 'success',
28
+ });
29
+ }
30
+ else {
31
+ resolve({
32
+ status: 'failure',
33
+ error: new Error('SendBeacon failed'),
34
+ });
35
+ }
36
+ });
37
+ }
38
+ shutdown() {
39
+ // Intentionally left empty, nothing to do.
40
+ }
41
+ }
42
+ export function createSendBeaconTransport(parameters) {
43
+ return new SendBeaconTransport(parameters);
44
+ }
45
+ //# 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,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,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../../exporter-transport';\nimport { ExportResponse } from '../../export-response';\nimport { diag } from '@opentelemetry/api';\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,82 @@
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 { isExportRetryable, parseRetryAfterToMills } from '../../util';
17
+ import { diag } from '@opentelemetry/api';
18
+ class XhrTransport {
19
+ constructor(_parameters) {
20
+ this._parameters = _parameters;
21
+ }
22
+ send(data, timeoutMillis) {
23
+ return new Promise(resolve => {
24
+ const xhr = new XMLHttpRequest();
25
+ xhr.timeout = timeoutMillis;
26
+ xhr.open('POST', this._parameters.url);
27
+ Object.entries(this._parameters.headers).forEach(([k, v]) => {
28
+ xhr.setRequestHeader(k, v);
29
+ });
30
+ xhr.ontimeout = _ => {
31
+ resolve({
32
+ status: 'failure',
33
+ error: new Error('XHR request timed out'),
34
+ });
35
+ };
36
+ xhr.onreadystatechange = () => {
37
+ if (xhr.status >= 200 && xhr.status <= 299) {
38
+ diag.debug('XHR success');
39
+ resolve({
40
+ status: 'success',
41
+ });
42
+ }
43
+ else if (xhr.status && isExportRetryable(xhr.status)) {
44
+ resolve({
45
+ status: 'retryable',
46
+ retryInMillis: parseRetryAfterToMills(xhr.getResponseHeader('Retry-After')),
47
+ });
48
+ }
49
+ else if (xhr.status !== 0) {
50
+ resolve({
51
+ status: 'failure',
52
+ error: new Error('XHR request failed with non-retryable status'),
53
+ });
54
+ }
55
+ };
56
+ xhr.onabort = () => {
57
+ resolve({
58
+ status: 'failure',
59
+ error: new Error('XHR request aborted'),
60
+ });
61
+ };
62
+ xhr.onerror = () => {
63
+ resolve({
64
+ status: 'failure',
65
+ error: new Error('XHR request errored'),
66
+ });
67
+ };
68
+ xhr.send(new Blob([data], { type: this._parameters.headers['Content-Type'] }));
69
+ });
70
+ }
71
+ shutdown() {
72
+ // Intentionally left empty, nothing to do.
73
+ }
74
+ }
75
+ /**
76
+ * Creates an exporter transport that uses XHR to send the data
77
+ * @param parameters applied to each request made by transport
78
+ */
79
+ export function createXhrTransport(parameters) {
80
+ return new XhrTransport(parameters);
81
+ }
82
+ //# 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,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;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;oBA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","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
@@ -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);
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
@@ -14,26 +14,49 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { OTLPExporterBase } from '../../OTLPExporterBase';
17
- import { parseHeaders } from '../../util';
18
- import { createHttpAgent, sendWithHttp, configureCompression } from './util';
17
+ import { configureCompression } from './util';
19
18
  import { diag } from '@opentelemetry/api';
20
19
  import { getEnv, baggageUtils } from '@opentelemetry/core';
20
+ import { createHttpExporterTransport } from './http-exporter-transport';
21
+ import { OTLPExporterError } from '../../types';
22
+ import { createRetryingTransport } from '../../retrying-transport';
21
23
  /**
22
24
  * Collector Metric Exporter abstract base class
23
25
  */
24
26
  export class OTLPExporterNodeBase extends OTLPExporterBase {
25
- constructor(config = {}, serializer, contentType) {
27
+ constructor(config = {}, serializer, signalSpecificHeaders) {
28
+ var _a;
26
29
  super(config);
27
- this.DEFAULT_HEADERS = {};
28
- this._contentType = contentType;
29
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
31
  if (config.metadata) {
31
32
  diag.warn('Metadata cannot be set when using http');
32
33
  }
33
- this.headers = Object.assign(this.DEFAULT_HEADERS, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
34
- this.agent = createHttpAgent(config);
35
- this.compression = configureCompression(config.compression);
36
34
  this._serializer = serializer;
35
+ // populate keepAlive for use with new settings
36
+ if ((config === null || config === void 0 ? void 0 : config.keepAlive) != null) {
37
+ if (config.httpAgentOptions != null) {
38
+ if (config.httpAgentOptions.keepAlive == null) {
39
+ // specific setting is not set, populate with non-specific setting.
40
+ config.httpAgentOptions.keepAlive = config.keepAlive;
41
+ }
42
+ // do nothing, use specific setting otherwise
43
+ }
44
+ else {
45
+ // populate specific option if AgentOptions does not exist.
46
+ config.httpAgentOptions = {
47
+ keepAlive: config.keepAlive,
48
+ };
49
+ }
50
+ }
51
+ const nonSignalSpecificHeaders = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS);
52
+ this._transport = createRetryingTransport({
53
+ transport: createHttpExporterTransport({
54
+ agentOptions: (_a = config.httpAgentOptions) !== null && _a !== void 0 ? _a : { keepAlive: true },
55
+ compression: configureCompression(config.compression),
56
+ headers: Object.assign({}, nonSignalSpecificHeaders, signalSpecificHeaders),
57
+ url: this.url,
58
+ }),
59
+ });
37
60
  }
38
61
  onInit(_config) { }
39
62
  send(objects, onSuccess, onError) {
@@ -41,10 +64,27 @@ export class OTLPExporterNodeBase extends OTLPExporterBase {
41
64
  diag.debug('Shutdown already started. Cannot send objects');
42
65
  return;
43
66
  }
44
- const promise = new Promise((resolve, reject) => {
45
- var _a;
46
- sendWithHttp(this, (_a = this._serializer.serializeRequest(objects)) !== null && _a !== void 0 ? _a : new Uint8Array(), this._contentType, resolve, reject);
47
- }).then(onSuccess, onError);
67
+ const data = this._serializer.serializeRequest(objects);
68
+ if (data == null) {
69
+ onError(new Error('Could not serialize message'));
70
+ return;
71
+ }
72
+ const promise = this._transport
73
+ .send(data, this.timeoutMillis)
74
+ .then(response => {
75
+ if (response.status === 'success') {
76
+ onSuccess();
77
+ }
78
+ else if (response.status === 'failure' && response.error) {
79
+ onError(response.error);
80
+ }
81
+ else if (response.status === 'retryable') {
82
+ onError(new OTLPExporterError('Export failed with retryable status'));
83
+ }
84
+ else {
85
+ onError(new OTLPExporterError('Export failed with unknown error'));
86
+ }
87
+ }, onError);
48
88
  this._sendingPromises.push(promise);
49
89
  const popPromise = () => {
50
90
  const index = this._sendingPromises.indexOf(promise);
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,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,MAAM,OAAgB,oBAGpB,SAAQ,gBAAwD;IAQhE,YACE,SAAqC,EAAE,EACvC,UAAsD,EACtD,WAAmB;QAEnB,KAAK,CAAC,MAAM,CAAC,CAAC;QAZhB,oBAAe,GAA2B,EAAE,CAAC;QAa3C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,eAAe,EACpB,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,0BAA0B,CAAC,CAC1E,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,OAAmC,IAAS,CAAC;IAEpD,IAAI,CACF,OAAqB,EACrB,SAAqB,EACrB,OAAqD;QAErD,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QAED,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YACpD,YAAY,CACV,IAAI,EACJ,MAAA,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,mCAAI,IAAI,UAAU,EAAE,EAC9D,IAAI,CAAC,YAAY,EACjB,OAAO,EACP,MAAM,CACP,CAAC;QACJ,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;IAED,UAAU,KAAU,CAAC;CACtB","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,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAgB,oBAGpB,SAAQ,gBAAwD;IAIhE,YACE,SAAqC,EAAE,EACvC,UAAsD,EACtD,qBAA6C;;QAE7C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,+CAA+C;QAC/C,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,KAAI,IAAI,EAAE;YAC7B,IAAI,MAAM,CAAC,gBAAgB,IAAI,IAAI,EAAE;gBACnC,IAAI,MAAM,CAAC,gBAAgB,CAAC,SAAS,IAAI,I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AQ,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,iBAAiB,CAAC,qCAAqC,CAAC,CAAC,CAAC;aACvE;iBAAM;gBACL,OAAO,CAAC,IAAI,iBAAiB,CAAC,kCAAkC,CAAC,CAAC,CAAC;aACpE;QACH,CAAC,EAAE,OAAO,CAAC,CAAC;QAEd,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,KAAU,CAAC;CACtB","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 { configureCompression } 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 { createHttpExporterTransport } from './http-exporter-transport';\nimport { OTLPExporterError } from '../../types';\nimport { createRetryingTransport } from '../../retrying-transport';\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\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n signalSpecificHeaders: Record<string, string>\n ) {\n super(config);\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 // populate keepAlive for use with new settings\n if (config?.keepAlive != null) {\n if (config.httpAgentOptions != null) {\n if (config.httpAgentOptions.keepAlive == null) {\n // specific setting is not set, populate with non-specific setting.\n config.httpAgentOptions.keepAlive = config.keepAlive;\n }\n // do nothing, use specific setting otherwise\n } else {\n // populate specific option if AgentOptions does not exist.\n config.httpAgentOptions = {\n keepAlive: config.keepAlive,\n };\n }\n }\n const nonSignalSpecificHeaders = baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n );\n\n this._transport = createRetryingTransport({\n transport: createHttpExporterTransport({\n agentOptions: config.httpAgentOptions ?? { keepAlive: true },\n compression: configureCompression(config.compression),\n headers: Object.assign(\n {},\n nonSignalSpecificHeaders,\n signalSpecificHeaders\n ),\n url: this.url,\n }),\n });\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): 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 onShutdown(): void {}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { HttpRequestParameters } from './http-transport-types';
2
+ import { IExporterTransport } from '../../exporter-transport';
3
+ export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
4
+ //# sourceMappingURL=http-exporter-transport.d.ts.map
@@ -0,0 +1,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
+ class HttpExporterTransport {
17
+ constructor(_parameters) {
18
+ this._parameters = _parameters;
19
+ this._send = null;
20
+ this._agent = null;
21
+ }
22
+ async send(data, timeoutMillis) {
23
+ if (this._send == null) {
24
+ // Lazy require to ensure that http/https is not required before instrumentations can wrap it.
25
+ const { sendWithHttp, createHttpAgent,
26
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27
+ } = require('./http-transport-utils');
28
+ this._agent = createHttpAgent(this._parameters.url, this._parameters.agentOptions);
29
+ this._send = sendWithHttp;
30
+ }
31
+ return new Promise(resolve => {
32
+ var _a;
33
+ // this will always be defined
34
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
35
+ (_a = this._send) === null || _a === void 0 ? void 0 : _a.call(this, this._parameters, this._agent, data, result => {
36
+ resolve(result);
37
+ }, timeoutMillis);
38
+ });
39
+ }
40
+ shutdown() {
41
+ // intentionally left empty, nothing to do.
42
+ }
43
+ }
44
+ export function createHttpExporterTransport(parameters) {
45
+ return new HttpExporterTransport(parameters);
46
+ }
47
+ //# sourceMappingURL=http-exporter-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../../src/platform/node/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH,MAAM,qBAAqB;IAIzB,YAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;QAH9C,UAAK,GAAwB,IAAI,CAAC;QAClC,WAAM,GAAoC,IAAI,CAAC;IAEE,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,IAAgB,EAAE,aAAqB;QAChD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YACtB,8FAA8F;YAC9F,MAAM,EACJ,YAAY,EACZ,eAAe;YACf,8DAA8D;cAC/D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,GAAG,eAAe,CAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B,CAAC;YACF,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;SAC3B;QAED,OAAO,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;;YAC3C,8BAA8B;YAC9B,oEAAoE;YACpE,MAAA,IAAI,CAAC,KAAK,+CAAV,IAAI,EACF,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAO,EACZ,IAAI,EACJ,MAAM,CAAC,EAAE;gBACP,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC,EACD,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../../export-response';\nimport { IExporterTransport } from '../../exporter-transport';\n\nclass HttpExporterTransport implements IExporterTransport {\n private _send: sendWithHttp | null = null;\n private _agent: http.Agent | https.Agent | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n if (this._send == null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n this._agent = createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n );\n this._send = sendWithHttp;\n }\n\n return new Promise<ExportResponse>(resolve => {\n // this will always be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._send?.(\n this._parameters,\n this._agent!,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import type * as http from 'http';
3
+ import type * as https from 'https';
4
+ import { ExportResponse } from '../../export-response';
5
+ export declare type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
6
+ export interface HttpRequestParameters {
7
+ url: string;
8
+ headers: Record<string, string>;
9
+ compression: 'gzip' | 'none';
10
+ agentOptions: http.AgentOptions | https.AgentOptions;
11
+ }
12
+ //# sourceMappingURL=http-transport-types.d.ts.map
@@ -0,0 +1,17 @@
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
+ export {};
17
+ //# sourceMappingURL=http-transport-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\nimport { ExportResponse } from '../../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import * as https from 'https';
4
+ import { HttpRequestParameters } from './http-transport-types';
5
+ import { ExportResponse } from '../../export-response';
6
+ /**
7
+ * Sends data using http
8
+ * @param params
9
+ * @param agent
10
+ * @param data
11
+ * @param onDone
12
+ * @param timeoutMillis
13
+ */
14
+ export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
15
+ export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
16
+ //# sourceMappingURL=http-transport-utils.d.ts.map