@opentelemetry/otlp-exporter-base 0.52.1 → 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
@@ -5,6 +5,9 @@ import { OTLPExporterError, OTLPExporterConfigBase } from './types';
5
5
  */
6
6
  export declare abstract class OTLPExporterBase<T extends OTLPExporterConfigBase, ExportItem> {
7
7
  readonly url: string;
8
+ /**
9
+ * @deprecated scheduled for removal. This is only used in tests.
10
+ */
8
11
  readonly hostname: string | undefined;
9
12
  readonly timeoutMillis: number;
10
13
  protected _concurrencyLimit: number;
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/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AkB,CAAC,CAAC;QAC/B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAUH,uBAAC;AAAD,CAAC,AAhHD,IAgHC","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 { diag } from '@opentelemetry/api';\nimport {\n ExportResult,\n ExportResultCode,\n BindOnceFuture,\n} from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nimport { configureExporterTimeout } from './util';\n\n/**\n * Collector Exporter abstract base class\n */\nexport abstract class OTLPExporterBase<\n T extends OTLPExporterConfigBase,\n ExportItem,\n> {\n public readonly url: string;\n public readonly hostname: string | undefined;\n public readonly timeoutMillis: number;\n protected _concurrencyLimit: number;\n protected _sendingPromises: Promise<unknown>[] = [];\n protected _shutdownOnce: BindOnceFuture<void>;\n\n /**\n * @param config\n */\n constructor(config: T = {} as T) {\n this.url = this.getDefaultUrl(config);\n if (typeof config.hostname === 'string') {\n this.hostname = config.hostname;\n }\n\n this.shutdown = this.shutdown.bind(this);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : 30;\n\n this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);\n\n // platform dependent\n this.onInit(config);\n }\n\n /**\n * Export items.\n * @param items\n * @param resultCallback\n */\n export(\n items: ExportItem[],\n resultCallback: (result: ExportResult) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been shutdown'),\n });\n return;\n }\n\n if (this._sendingPromises.length >= this._concurrencyLimit) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Concurrent export limit reached'),\n });\n return;\n }\n\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error: ExportServiceError) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: ExportItem[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n diag.debug('items to be sent', items);\n this.send(items, resolve, reject);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Shutdown the exporter.\n */\n shutdown(): Promise<void> {\n return this._shutdownOnce.call();\n }\n\n /**\n * Exports any pending spans in the exporter\n */\n forceFlush(): Promise<void> {\n return Promise.all(this._sendingPromises).then(() => {\n /** ignore resolved values */\n });\n }\n\n /**\n * Called by _shutdownOnce with BindOnceFuture\n */\n private _shutdown(): Promise<void> {\n diag.debug('shutdown started');\n this.onShutdown();\n return this.forceFlush();\n }\n\n abstract onShutdown(): void;\n abstract onInit(config: T): void;\n abstract send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void;\n abstract getDefaultUrl(config: T): string;\n}\n"]}
1
+ {"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/OTLPExporterBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAEL,gBAAgB,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD;;GAEG;AACH;IAcE;;OAEG;IACH,0BAAY,MAAmB;QAAnB,uBAAA,EAAA,SAAY,EAAO;QANrB,qBAAgB,GAAuB,EAAE,CAAC;QAOlD,IA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AC,OAAO,EAAE,CAAC,CAAC;QACrD,CAAC,CAAC;aACD,KAAK,CAAC,UAAC,KAAyB;YAC/B,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,kCAAO,GAAf,UAAgB,KAAmB;QAAnC,iBASC;QARC,OAAO,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;YACvC,IAAI;gBACF,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;gBACtC,KAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aACnC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,mCAAQ,GAAR;QACE,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,qCAAU,GAAV;QACE,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;YAC7C,6BAA6B;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,oCAAS,GAAjB;QACE,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC/B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAUH,uBAAC;AAAD,CAAC,AAnHD,IAmHC","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 { diag } from '@opentelemetry/api';\nimport {\n ExportResult,\n ExportResultCode,\n BindOnceFuture,\n} from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nimport { configureExporterTimeout } from './util';\n\n/**\n * Collector Exporter abstract base class\n */\nexport abstract class OTLPExporterBase<\n T extends OTLPExporterConfigBase,\n ExportItem,\n> {\n public readonly url: string;\n /**\n * @deprecated scheduled for removal. This is only used in tests.\n */\n public readonly hostname: string | undefined;\n public readonly timeoutMillis: number;\n protected _concurrencyLimit: number;\n protected _sendingPromises: Promise<unknown>[] = [];\n protected _shutdownOnce: BindOnceFuture<void>;\n\n /**\n * @param config\n */\n constructor(config: T = {} as T) {\n this.url = this.getDefaultUrl(config);\n if (typeof config.hostname === 'string') {\n this.hostname = config.hostname;\n }\n\n this.shutdown = this.shutdown.bind(this);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : 30;\n\n this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);\n\n // platform dependent\n this.onInit(config);\n }\n\n /**\n * Export items.\n * @param items\n * @param resultCallback\n */\n export(\n items: ExportItem[],\n resultCallback: (result: ExportResult) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been shutdown'),\n });\n return;\n }\n\n if (this._sendingPromises.length >= this._concurrencyLimit) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Concurrent export limit reached'),\n });\n return;\n }\n\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error: ExportServiceError) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: ExportItem[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n diag.debug('items to be sent', items);\n this.send(items, resolve, reject);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Shutdown the exporter.\n */\n shutdown(): Promise<void> {\n return this._shutdownOnce.call();\n }\n\n /**\n * Exports any pending spans in the exporter\n */\n forceFlush(): Promise<void> {\n return Promise.all(this._sendingPromises).then(() => {\n /** ignore resolved values */\n });\n }\n\n /**\n * Called by _shutdownOnce with BindOnceFuture\n */\n private _shutdown(): Promise<void> {\n diag.debug('shutdown started');\n this.onShutdown();\n return this.forceFlush();\n }\n\n abstract onShutdown(): void;\n abstract onInit(config: T): void;\n abstract send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void;\n abstract getDefaultUrl(config: T): string;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ export interface ExportResponseSuccess {
2
+ status: 'success';
3
+ data?: Uint8Array;
4
+ }
5
+ export interface ExportResponseFailure {
6
+ status: 'failure';
7
+ error: Error;
8
+ }
9
+ export interface ExportResponseRetryable {
10
+ status: 'retryable';
11
+ retryInMillis?: number;
12
+ }
13
+ export declare type ExportResponse = ExportResponseSuccess | ExportResponseFailure | ExportResponseRetryable;
14
+ //# sourceMappingURL=export-response.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=export-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-response.js","sourceRoot":"","sources":["../../src/export-response.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\nexport interface ExportResponseSuccess {\n status: 'success';\n data?: Uint8Array;\n}\n\nexport interface ExportResponseFailure {\n status: 'failure';\n error: Error;\n}\n\nexport interface ExportResponseRetryable {\n status: 'retryable';\n retryInMillis?: number;\n}\n\nexport type ExportResponse =\n | ExportResponseSuccess\n | ExportResponseFailure\n | ExportResponseRetryable;\n"]}
@@ -0,0 +1,6 @@
1
+ import { ExportResponse } from './export-response';
2
+ export interface IExporterTransport {
3
+ send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse>;
4
+ shutdown(): void;
5
+ }
6
+ //# sourceMappingURL=exporter-transport.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=exporter-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter-transport.js","sourceRoot":"","sources":["../../src/exporter-transport.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 { ExportResponse } from './export-response';\n\nexport interface IExporterTransport {\n send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse>;\n shutdown(): void;\n}\n"]}
@@ -2,4 +2,6 @@ export * from './platform';
2
2
  export { OTLPExporterBase } from './OTLPExporterBase';
3
3
  export { OTLPExporterError, OTLPExporterConfigBase, ExportServiceError, } from './types';
4
4
  export { parseHeaders, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, configureExporterTimeout, invalidTimeout, } from './util';
5
+ export { ExportResponse, ExportResponseFailure, ExportResponseSuccess, ExportResponseRetryable, } from './export-response';
6
+ export { IExporterTransport } from './exporter-transport';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -13,6 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ /* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
17
+ * TODO: Replace export * with named exports before next major version
18
+ */
16
19
  export * from './platform';
17
20
  export { OTLPExporterBase } from './OTLPExporterBase';
18
21
  export { OTLPExporterError, } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,iBAAiB,GAGlB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,cAAc,GACf,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 */\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,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,iBAAiB,GAGlB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,cAAc,GACf,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\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,35 @@
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 function isExportRetryable(statusCode) {
17
+ var retryCodes = [429, 502, 503, 504];
18
+ return retryCodes.includes(statusCode);
19
+ }
20
+ export function parseRetryAfterToMills(retryAfter) {
21
+ if (retryAfter == null) {
22
+ return undefined;
23
+ }
24
+ var seconds = Number.parseInt(retryAfter, 10);
25
+ if (Number.isInteger(seconds)) {
26
+ return seconds > 0 ? seconds * 1000 : -1;
27
+ }
28
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
29
+ var delay = new Date(retryAfter).getTime() - Date.now();
30
+ if (delay >= 0) {
31
+ return delay;
32
+ }
33
+ return 0;
34
+ }
35
+ //# 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,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,UAAsC;IAEtC,IAAI,UAAU,IAAI,IAAI,EAAE;QACtB,OAAO,SAAS,CAAC;KAClB;IAED,IAAM,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,IAAM,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","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
@@ -28,22 +28,14 @@ var __extends = (this && this.__extends) || (function () {
28
28
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
29
  };
30
30
  })();
31
- var __assign = (this && this.__assign) || function () {
32
- __assign = Object.assign || function(t) {
33
- for (var s, i = 1, n = arguments.length; i < n; i++) {
34
- s = arguments[i];
35
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
36
- t[p] = s[p];
37
- }
38
- return t;
39
- };
40
- return __assign.apply(this, arguments);
41
- };
42
31
  import { OTLPExporterBase } from '../../OTLPExporterBase';
32
+ import { OTLPExporterError } from '../../types';
43
33
  import { parseHeaders } from '../../util';
44
- import { sendWithBeacon, sendWithXhr } from './util';
45
34
  import { diag } from '@opentelemetry/api';
46
35
  import { getEnv, baggageUtils } from '@opentelemetry/core';
36
+ import { createXhrTransport } from './xhr-transport';
37
+ import { createSendBeaconTransport } from './send-beacon-transport';
38
+ import { createRetryingTransport } from '../../retrying-transport';
47
39
  /**
48
40
  * Collector Metric Exporter abstract base class
49
41
  */
@@ -57,37 +49,54 @@ var OTLPExporterBrowserBase = /** @class */ (function (_super) {
57
49
  function OTLPExporterBrowserBase(config, serializer, contentType) {
58
50
  if (config === void 0) { config = {}; }
59
51
  var _this = _super.call(this, config) || this;
60
- _this._useXHR = false;
61
52
  _this._serializer = serializer;
62
- _this._contentType = contentType;
63
- _this._useXHR =
64
- !!config.headers || typeof navigator.sendBeacon !== 'function';
65
- if (_this._useXHR) {
66
- _this._headers = Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
53
+ var useXhr = !!config.headers || typeof navigator.sendBeacon !== 'function';
54
+ if (useXhr) {
55
+ _this._transport = createRetryingTransport({
56
+ transport: createXhrTransport({
57
+ headers: Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS), { 'Content-Type': contentType }),
58
+ url: _this.url,
59
+ }),
60
+ });
67
61
  }
68
62
  else {
69
- _this._headers = {};
63
+ // sendBeacon has no way to signal retry, so we do not wrap it in a RetryingTransport
64
+ _this._transport = createSendBeaconTransport({
65
+ url: _this.url,
66
+ blobType: contentType,
67
+ });
70
68
  }
71
69
  return _this;
72
70
  }
73
71
  OTLPExporterBrowserBase.prototype.onInit = function () { };
74
72
  OTLPExporterBrowserBase.prototype.onShutdown = function () { };
75
- OTLPExporterBrowserBase.prototype.send = function (items, onSuccess, onError) {
73
+ OTLPExporterBrowserBase.prototype.send = function (objects, onSuccess, onError) {
76
74
  var _this = this;
77
- var _a;
78
75
  if (this._shutdownOnce.isCalled) {
79
76
  diag.debug('Shutdown already started. Cannot send objects');
80
77
  return;
81
78
  }
82
- var body = (_a = this._serializer.serializeRequest(items)) !== null && _a !== void 0 ? _a : new Uint8Array();
83
- var promise = new Promise(function (resolve, reject) {
84
- if (_this._useXHR) {
85
- sendWithXhr(body, _this.url, __assign(__assign({}, _this._headers), { 'Content-Type': _this._contentType }), _this.timeoutMillis, resolve, reject);
79
+ var data = this._serializer.serializeRequest(objects);
80
+ if (data == null) {
81
+ onError(new Error('Could not serialize message'));
82
+ return;
83
+ }
84
+ var promise = this._transport
85
+ .send(data, this.timeoutMillis)
86
+ .then(function (response) {
87
+ if (response.status === 'success') {
88
+ onSuccess();
89
+ }
90
+ else if (response.status === 'failure' && response.error) {
91
+ onError(response.error);
92
+ }
93
+ else if (response.status === 'retryable') {
94
+ onError(new OTLPExporterError('Export failed with retryable status'));
86
95
  }
87
96
  else {
88
- sendWithBeacon(body, _this.url, { type: _this._contentType }, resolve, reject);
97
+ onError(new OTLPExporterError('Export failed with unknown error'));
89
98
  }
90
- }).then(onSuccess, onError);
99
+ }, onError);
91
100
  this._sendingPromises.push(promise);
92
101
  var popPromise = function () {
93
102
  var index = _this._sendingPromises.indexOf(promise);
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;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QACD,IAAM,IAAI,GAAG,MAAA,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,mCAAI,IAAI,UAAU,EAAE,CAAC;QAE1E,IAAM,OAAO,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;YAChD,IAAI,KAAI,CAAC,OAAO,EAAE;gBAChB,WAAW,CACT,IAAI,EACJ,KAAI,CAAC,GAAG,wBAEH,KAAI,CAAC,QAAQ,KAChB,cAAc,EAAE,KAAI,CAAC,YAAY,KAEnC,KAAI,CAAC,aAAa,EAClB,OAAO,EACP,MAAM,CACP,CAAC;aACH;iBAAM;gBACL,cAAc,CACZ,IAAI,EACJ,KAAI,CAAC,GAAG,EACR,EAAE,IAAI,EAAE,KAAI,CAAC,YAAY,EAAE,EAC3B,OAAO,EACP,MAAM,CACP,CAAC;aACH;QACH,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACH,8BAAC;AAAD,CAAC,AAnFD,CAGU,gBAAgB,GAgFzB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterConfigBase } from '../../types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { sendWithBeacon, sendWithXhr } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterBrowserBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem> {\n protected _headers: Record<string, string>;\n private _useXHR: boolean = false;\n private _contentType: string;\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n\n /**\n * @param config\n * @param serializer\n * @param contentType\n */\n constructor(\n config: OTLPExporterConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n contentType: string\n ) {\n super(config);\n this._serializer = serializer;\n this._contentType = contentType;\n this._useXHR =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n if (this._useXHR) {\n this._headers = Object.assign(\n {},\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n )\n );\n } else {\n this._headers = {};\n }\n }\n\n onInit(): void {}\n\n onShutdown(): void {}\n\n send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n const body = this._serializer.serializeRequest(items) ?? new Uint8Array();\n\n const promise = new Promise<void>((resolve, reject) => {\n if (this._useXHR) {\n sendWithXhr(\n body,\n this.url,\n {\n ...this._headers,\n 'Content-Type': this._contentType,\n },\n this.timeoutMillis,\n resolve,\n reject\n );\n } else {\n sendWithBeacon(\n body,\n this.url,\n { type: this._contentType },\n resolve,\n reject\n );\n }\n }).then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n}\n"]}
1
+ {"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAA0B,iBAAiB,EAAE,MAAM,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;IAGU,2CAAoD;IAI5D;;;;OAIG;IACH,iCACE,MAAmC,EACnC,UAAsD,EACtD,WAAmB;QAFnB,uBAAA,EAAA,WAAmC;QADrC,YAKE,kBAAM,MAAM,CAAC,SAyBd;QAxBC,KAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAM,MAAM,GACV,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;QACjE,IAAI,MAAM,EAAE;YACV,KAAI,CAAC,UAAU,GAAG,uBAAuB,CAAC;gBACxC,SAAS,EAAE,kBAAkB,CAAC;oBAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,CACpB,EAAE,EACF,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,YAAY,CA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C,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,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACH,8BAAC;AAAD,CAAC,AAtFD,CAGU,gBAAgB,GAmFzB","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,47 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { diag } from '@opentelemetry/api';
17
+ var SendBeaconTransport = /** @class */ (function () {
18
+ function SendBeaconTransport(_params) {
19
+ this._params = _params;
20
+ }
21
+ SendBeaconTransport.prototype.send = function (data) {
22
+ var _this = this;
23
+ return new Promise(function (resolve) {
24
+ if (navigator.sendBeacon(_this._params.url, new Blob([data], { type: _this._params.blobType }))) {
25
+ // no way to signal retry, treat everything as success
26
+ diag.debug('SendBeacon success');
27
+ resolve({
28
+ status: 'success',
29
+ });
30
+ }
31
+ else {
32
+ resolve({
33
+ status: 'failure',
34
+ error: new Error('SendBeacon failed'),
35
+ });
36
+ }
37
+ });
38
+ };
39
+ SendBeaconTransport.prototype.shutdown = function () {
40
+ // Intentionally left empty, nothing to do.
41
+ };
42
+ return SendBeaconTransport;
43
+ }());
44
+ export function createSendBeaconTransport(parameters) {
45
+ return new SendBeaconTransport(parameters);
46
+ }
47
+ //# sourceMappingURL=send-beacon-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-beacon-transport.js","sourceRoot":"","sources":["../../../../src/platform/browser/send-beacon-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU1C;IACE,6BAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IACrD,kCAAI,GAAJ,UAAK,IAAgB;QAArB,iBAoBC;QAnBC,OAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;YACxC,IACE,SAAS,CAAC,UAAU,CAClB,KAAI,CAAC,OAAO,CAAC,GAAG,EAChB,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,KAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAClD,EACD;gBACA,sDAAsD;gBACtD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBACjC,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;iBAClB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC;oBACN,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,IAAI,KAAK,CAAC,mBAAmB,CAAC;iBACtC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sCAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,0BAAC;AAAD,CAAC,AA3BD,IA2BC;AAED,MAAM,UAAU,yBAAyB,CACvC,UAAgC;IAEhC,OAAO,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../../exporter-transport';\nimport { ExportResponse } from '../../export-response';\nimport { diag } from '@opentelemetry/api';\n\nexport interface SendBeaconParameters {\n url: string;\n /**\n * for instance 'application/x-protobuf'\n */\n blobType: string;\n}\n\nclass SendBeaconTransport implements IExporterTransport {\n constructor(private _params: SendBeaconParameters) {}\n send(data: Uint8Array): Promise<ExportResponse> {\n return new Promise<ExportResponse>(resolve => {\n if (\n navigator.sendBeacon(\n this._params.url,\n new Blob([data], { type: this._params.blobType })\n )\n ) {\n // no way to signal retry, treat everything as success\n diag.debug('SendBeacon success');\n resolve({\n status: 'success',\n });\n } else {\n resolve({\n status: 'failure',\n error: new Error('SendBeacon failed'),\n });\n }\n });\n }\n\n shutdown(): void {\n // Intentionally left empty, nothing to do.\n }\n}\n\nexport function createSendBeaconTransport(\n parameters: SendBeaconParameters\n): IExporterTransport {\n return new SendBeaconTransport(parameters);\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { IExporterTransport } from '../../exporter-transport';
2
+ export interface XhrRequestParameters {
3
+ url: string;
4
+ headers: Record<string, string>;
5
+ }
6
+ /**
7
+ * Creates an exporter transport that uses XHR to send the data
8
+ * @param parameters applied to each request made by transport
9
+ */
10
+ export declare function createXhrTransport(parameters: XhrRequestParameters): IExporterTransport;
11
+ //# sourceMappingURL=xhr-transport.d.ts.map
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
18
+ if (!m) return o;
19
+ var i = m.call(o), r, ar = [], e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
29
+ }
30
+ return ar;
31
+ };
32
+ import { isExportRetryable, parseRetryAfterToMills } from '../../util';
33
+ import { diag } from '@opentelemetry/api';
34
+ var XhrTransport = /** @class */ (function () {
35
+ function XhrTransport(_parameters) {
36
+ this._parameters = _parameters;
37
+ }
38
+ XhrTransport.prototype.send = function (data, timeoutMillis) {
39
+ var _this = this;
40
+ return new Promise(function (resolve) {
41
+ var xhr = new XMLHttpRequest();
42
+ xhr.timeout = timeoutMillis;
43
+ xhr.open('POST', _this._parameters.url);
44
+ Object.entries(_this._parameters.headers).forEach(function (_a) {
45
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
46
+ xhr.setRequestHeader(k, v);
47
+ });
48
+ xhr.ontimeout = function (_) {
49
+ resolve({
50
+ status: 'failure',
51
+ error: new Error('XHR request timed out'),
52
+ });
53
+ };
54
+ xhr.onreadystatechange = function () {
55
+ if (xhr.status >= 200 && xhr.status <= 299) {
56
+ diag.debug('XHR success');
57
+ resolve({
58
+ status: 'success',
59
+ });
60
+ }
61
+ else if (xhr.status && isExportRetryable(xhr.status)) {
62
+ resolve({
63
+ status: 'retryable',
64
+ retryInMillis: parseRetryAfterToMills(xhr.getResponseHeader('Retry-After')),
65
+ });
66
+ }
67
+ else if (xhr.status !== 0) {
68
+ resolve({
69
+ status: 'failure',
70
+ error: new Error('XHR request failed with non-retryable status'),
71
+ });
72
+ }
73
+ };
74
+ xhr.onabort = function () {
75
+ resolve({
76
+ status: 'failure',
77
+ error: new Error('XHR request aborted'),
78
+ });
79
+ };
80
+ xhr.onerror = function () {
81
+ resolve({
82
+ status: 'failure',
83
+ error: new Error('XHR request errored'),
84
+ });
85
+ };
86
+ xhr.send(new Blob([data], { type: _this._parameters.headers['Content-Type'] }));
87
+ });
88
+ };
89
+ XhrTransport.prototype.shutdown = function () {
90
+ // Intentionally left empty, nothing to do.
91
+ };
92
+ return XhrTransport;
93
+ }());
94
+ /**
95
+ * Creates an exporter transport that uses XHR to send the data
96
+ * @param parameters applied to each request made by transport
97
+ */
98
+ export function createXhrTransport(parameters) {
99
+ return new XhrTransport(parameters);
100
+ }
101
+ //# sourceMappingURL=xhr-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhr-transport.js","sourceRoot":"","sources":["../../../../src/platform/browser/xhr-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAIH,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAO1C;IACE,sBAAoB,WAAiC;QAAjC,gBAAW,GAAX,WAAW,CAAsB;IAAG,CAAC;IAEzD,2BAAI,GAAJ,UAAK,IAAgB,EAAE,aAAqB;QAA5C,iBAsDC;QArDC,OAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;YACxC,IAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;YACjC,GAAG,CAAC,OAAO,GAAG,aAAa,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,CAAC,KAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,EAAM;oBAAN,KAAA,aAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;gBACrD,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,SAAS,GAAG,UAAA,CAAC;gBACf,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c,CAAC,EAAE,CAAC,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,+BAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,mBAAC;AAAD,CAAC,AA9DD,IA8DC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAgC;IAEhC,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from '../../exporter-transport';\nimport { ExportResponse } from '../../export-response';\nimport { 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"]}