@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
@@ -0,0 +1,116 @@
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 * as http from 'http';
17
+ import * as https from 'https';
18
+ import * as zlib from 'zlib';
19
+ import { Readable } from 'stream';
20
+ import { isExportRetryable, parseRetryAfterToMills, } from '../../is-export-retryable';
21
+ import { OTLPExporterError } from '../../types';
22
+ /**
23
+ * Sends data using http
24
+ * @param params
25
+ * @param agent
26
+ * @param data
27
+ * @param onDone
28
+ * @param timeoutMillis
29
+ */
30
+ export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
31
+ const parsedUrl = new URL(params.url);
32
+ const nodeVersion = Number(process.versions.node.split('.')[0]);
33
+ const options = {
34
+ hostname: parsedUrl.hostname,
35
+ port: parsedUrl.port,
36
+ path: parsedUrl.pathname,
37
+ method: 'POST',
38
+ headers: Object.assign({}, params.headers),
39
+ agent: agent,
40
+ };
41
+ const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
42
+ const req = request(options, (res) => {
43
+ const responseData = [];
44
+ res.on('data', chunk => responseData.push(chunk));
45
+ res.on('end', () => {
46
+ if (res.statusCode && res.statusCode < 299) {
47
+ onDone({
48
+ status: 'success',
49
+ data: Buffer.concat(responseData),
50
+ });
51
+ }
52
+ else if (res.statusCode && isExportRetryable(res.statusCode)) {
53
+ onDone({
54
+ status: 'retryable',
55
+ retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
56
+ });
57
+ }
58
+ else {
59
+ const error = new OTLPExporterError(res.statusMessage, res.statusCode);
60
+ onDone({
61
+ status: 'failure',
62
+ error,
63
+ });
64
+ }
65
+ });
66
+ });
67
+ req.setTimeout(timeoutMillis, () => {
68
+ req.destroy();
69
+ onDone({
70
+ status: 'failure',
71
+ error: new Error('Request Timeout'),
72
+ });
73
+ });
74
+ req.on('error', (error) => {
75
+ onDone({
76
+ status: 'failure',
77
+ error: error,
78
+ });
79
+ });
80
+ const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
81
+ req.on(reportTimeoutErrorEvent, () => {
82
+ onDone({
83
+ status: 'failure',
84
+ error: new Error('Request timed out'),
85
+ });
86
+ });
87
+ compressAndSend(req, params.compression, data, (error) => {
88
+ onDone({
89
+ status: 'failure',
90
+ error,
91
+ });
92
+ });
93
+ }
94
+ function compressAndSend(req, compression, data, onError) {
95
+ let dataStream = readableFromUint8Array(data);
96
+ if (compression === 'gzip') {
97
+ req.setHeader('Content-Encoding', 'gzip');
98
+ dataStream = dataStream
99
+ .on('error', onError)
100
+ .pipe(zlib.createGzip())
101
+ .on('error', onError);
102
+ }
103
+ dataStream.pipe(req);
104
+ }
105
+ function readableFromUint8Array(buff) {
106
+ const readable = new Readable();
107
+ readable.push(buff);
108
+ readable.push(null);
109
+ return readable;
110
+ }
111
+ export function createHttpAgent(rawUrl, agentOptions) {
112
+ const parsedUrl = new URL(rawUrl);
113
+ const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
114
+ return new Agent(agentOptions);
115
+ }
116
+ //# sourceMappingURL=http-transport-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,MAA0C,EAC1C,aAAqB;IAErB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC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AAM,EAAE;QAC1B,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QAC1C,UAAU,GAAG,UAAU;aACpB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;aACpB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;aACvB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACzB;IAED,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAyB;IACvD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,YAAoD;IAEpD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACxE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../is-export-retryable';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Sends data using http\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n ...params.headers,\n },\n agent: agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n onDone({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (res.statusCode && isExportRetryable(res.statusCode)) {\n onDone({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(res.statusMessage, res.statusCode);\n onDone({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n onDone({\n status: 'failure',\n error: new Error('Request Timeout'),\n });\n });\n req.on('error', (error: Error | any) => {\n onDone({\n status: 'failure',\n error: error,\n });\n });\n\n const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';\n req.on(reportTimeoutErrorEvent, () => {\n onDone({\n status: 'failure',\n error: new Error('Request timed out'),\n });\n });\n\n compressAndSend(req, params.compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\nfunction compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n rawUrl: string,\n agentOptions: http.AgentOptions | https.AgentOptions\n) {\n const parsedUrl = new URL(rawUrl);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent(agentOptions);\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
2
- export { sendWithHttp, createHttpAgent, configureCompression } from './util';
3
2
  export { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -14,6 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
17
- export { sendWithHttp, createHttpAgent, configureCompression } from './util';
18
17
  export { CompressionAlgorithm } from './types';
19
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAA8B,oBAAoB,EAAE,MAAM,SAAS,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 { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { sendWithHttp, createHttpAgent, configureCompression } from './util';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAA8B,oBAAoB,EAAE,MAAM,SAAS,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 { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
@@ -1,19 +1,3 @@
1
- /// <reference types="node" />
2
- import * as http from 'http';
3
- import * as https from 'https';
4
- import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
5
- import { OTLPExporterNodeConfigBase } from '.';
6
1
  import { CompressionAlgorithm } from './types';
7
- import { OTLPExporterError } from '../../types';
8
- /**
9
- * Sends data using http
10
- * @param collector
11
- * @param data
12
- * @param contentType
13
- * @param onSuccess
14
- * @param onError
15
- */
16
- export declare function sendWithHttp<ExportItem, ServiceResponse>(collector: OTLPExporterNodeBase<ExportItem, ServiceResponse>, data: string | Uint8Array, contentType: string, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
17
- export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
18
2
  export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
19
3
  //# sourceMappingURL=util.d.ts.map
@@ -13,159 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import * as url from 'url';
17
- import * as http from 'http';
18
- import * as https from 'https';
19
- import * as zlib from 'zlib';
20
- import { Readable } from 'stream';
21
- import { diag } from '@opentelemetry/api';
22
16
  import { CompressionAlgorithm } from './types';
23
17
  import { getEnv } from '@opentelemetry/core';
24
- import { OTLPExporterError } from '../../types';
25
- import { DEFAULT_EXPORT_MAX_ATTEMPTS, DEFAULT_EXPORT_INITIAL_BACKOFF, DEFAULT_EXPORT_BACKOFF_MULTIPLIER, DEFAULT_EXPORT_MAX_BACKOFF, isExportRetryable, parseRetryAfterToMills, } from '../../util';
26
- /**
27
- * Sends data using http
28
- * @param collector
29
- * @param data
30
- * @param contentType
31
- * @param onSuccess
32
- * @param onError
33
- */
34
- export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
35
- const exporterTimeout = collector.timeoutMillis;
36
- const parsedUrl = new url.URL(collector.url);
37
- const nodeVersion = Number(process.versions.node.split('.')[0]);
38
- let retryTimer;
39
- let req;
40
- let reqIsDestroyed = false;
41
- const exporterTimer = setTimeout(() => {
42
- clearTimeout(retryTimer);
43
- reqIsDestroyed = true;
44
- if (req.destroyed) {
45
- const err = new OTLPExporterError('Request Timeout');
46
- onError(err);
47
- }
48
- else {
49
- // req.abort() was deprecated since v14
50
- nodeVersion >= 14 ? req.destroy() : req.abort();
51
- }
52
- }, exporterTimeout);
53
- const options = {
54
- hostname: parsedUrl.hostname,
55
- port: parsedUrl.port,
56
- path: parsedUrl.pathname,
57
- method: 'POST',
58
- headers: Object.assign({ 'Content-Type': contentType }, collector.headers),
59
- agent: collector.agent,
60
- };
61
- const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
62
- const sendWithRetry = (retries = DEFAULT_EXPORT_MAX_ATTEMPTS, minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF) => {
63
- req = request(options, (res) => {
64
- let responseData = '';
65
- res.on('data', chunk => (responseData += chunk));
66
- res.on('aborted', () => {
67
- if (reqIsDestroyed) {
68
- const err = new OTLPExporterError('Request Timeout');
69
- onError(err);
70
- }
71
- });
72
- res.on('end', () => {
73
- if (reqIsDestroyed === false) {
74
- if (res.statusCode && res.statusCode < 299) {
75
- diag.debug(`statusCode: ${res.statusCode}`, responseData);
76
- onSuccess();
77
- // clear all timers since request was completed and promise was resolved
78
- clearTimeout(exporterTimer);
79
- clearTimeout(retryTimer);
80
- }
81
- else if (res.statusCode &&
82
- isExportRetryable(res.statusCode) &&
83
- retries > 0) {
84
- let retryTime;
85
- minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
86
- // retry after interval specified in Retry-After header
87
- if (res.headers['retry-after']) {
88
- retryTime = parseRetryAfterToMills(res.headers['retry-after']);
89
- }
90
- else {
91
- // exponential backoff with jitter
92
- retryTime = Math.round(Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +
93
- minDelay);
94
- }
95
- retryTimer = setTimeout(() => {
96
- sendWithRetry(retries - 1, minDelay);
97
- }, retryTime);
98
- }
99
- else {
100
- const error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
101
- onError(error);
102
- // clear all timers since request was completed and promise was resolved
103
- clearTimeout(exporterTimer);
104
- clearTimeout(retryTimer);
105
- }
106
- }
107
- });
108
- });
109
- req.on('error', (error) => {
110
- if (reqIsDestroyed) {
111
- const err = new OTLPExporterError('Request Timeout', error.code);
112
- onError(err);
113
- }
114
- else {
115
- onError(error);
116
- }
117
- clearTimeout(exporterTimer);
118
- clearTimeout(retryTimer);
119
- });
120
- req.on('abort', () => {
121
- if (reqIsDestroyed) {
122
- const err = new OTLPExporterError('Request Timeout');
123
- onError(err);
124
- }
125
- clearTimeout(exporterTimer);
126
- clearTimeout(retryTimer);
127
- });
128
- switch (collector.compression) {
129
- case CompressionAlgorithm.GZIP: {
130
- req.setHeader('Content-Encoding', 'gzip');
131
- const dataStream = readableFromUnit8Array(data);
132
- dataStream
133
- .on('error', onError)
134
- .pipe(zlib.createGzip())
135
- .on('error', onError)
136
- .pipe(req);
137
- break;
138
- }
139
- default:
140
- req.end(Buffer.from(data));
141
- break;
142
- }
143
- };
144
- sendWithRetry();
145
- }
146
- function readableFromUnit8Array(buff) {
147
- const readable = new Readable();
148
- readable.push(buff);
149
- readable.push(null);
150
- return readable;
151
- }
152
- export function createHttpAgent(config) {
153
- if (config.httpAgentOptions && config.keepAlive === false) {
154
- diag.warn('httpAgentOptions is used only when keepAlive is true');
155
- return undefined;
156
- }
157
- if (config.keepAlive === false || !config.url)
158
- return undefined;
159
- try {
160
- const parsedUrl = new url.URL(config.url);
161
- const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
162
- return new Agent(Object.assign({ keepAlive: true }, config.httpAgentOptions));
163
- }
164
- catch (err) {
165
- diag.error(`collector exporter failed to create http agent. err: ${err.message}`);
166
- return undefined;
167
- }
168
- }
169
18
  export function configureCompression(compression) {
170
19
  if (compression) {
171
20
  return compression;
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,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,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;QAClE,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAEhE,IAAI;QACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAa,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;QACxE,OAAO,IAAI,KAAK,iBAAG,SAAS,EAAE,IAAI,IAAK,MAAM,CAAC,gBAAgB,EAAG,CAAC;KACnE;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,CAAC,KAAK,CACR,wDAAwD,GAAG,CAAC,OAAO,EAAE,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,MAAM,EAAE,CAAC,qCAAqC;YAC9C,MAAM,EAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,oBAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,oBAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,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 */\nimport * as url from 'url';\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nimport { OTLPExporterNodeConfigBase } from '.';\nimport { diag } from '@opentelemetry/api';\nimport { CompressionAlgorithm } from './types';\nimport { getEnv } from '@opentelemetry/core';\nimport { OTLPExporterError } from '../../types';\nimport {\n DEFAULT_EXPORT_MAX_ATTEMPTS,\n DEFAULT_EXPORT_INITIAL_BACKOFF,\n DEFAULT_EXPORT_BACKOFF_MULTIPLIER,\n DEFAULT_EXPORT_MAX_BACKOFF,\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../util';\n\n/**\n * Sends data using http\n * @param collector\n * @param data\n * @param contentType\n * @param onSuccess\n * @param onError\n */\nexport function sendWithHttp<ExportItem, ServiceResponse>(\n collector: OTLPExporterNodeBase<ExportItem, ServiceResponse>,\n data: string | Uint8Array,\n contentType: string,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n const exporterTimeout = collector.timeoutMillis;\n const parsedUrl = new url.URL(collector.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n let retryTimer: ReturnType<typeof setTimeout>;\n let req: http.ClientRequest;\n let reqIsDestroyed = false;\n\n const exporterTimer = setTimeout(() => {\n clearTimeout(retryTimer);\n reqIsDestroyed = true;\n\n if (req.destroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n } else {\n // req.abort() was deprecated since v14\n nodeVersion >= 14 ? req.destroy() : req.abort();\n }\n }, exporterTimeout);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n 'Content-Type': contentType,\n ...collector.headers,\n },\n agent: collector.agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const sendWithRetry = (\n retries = DEFAULT_EXPORT_MAX_ATTEMPTS,\n minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF\n ) => {\n req = request(options, (res: http.IncomingMessage) => {\n let responseData = '';\n res.on('data', chunk => (responseData += chunk));\n\n res.on('aborted', () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n });\n\n res.on('end', () => {\n if (reqIsDestroyed === false) {\n if (res.statusCode && res.statusCode < 299) {\n diag.debug(`statusCode: ${res.statusCode}`, responseData);\n onSuccess();\n // clear all timers since request was completed and promise was resolved\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n } else if (\n res.statusCode &&\n isExportRetryable(res.statusCode) &&\n retries > 0\n ) {\n let retryTime: number;\n minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;\n\n // retry after interval specified in Retry-After header\n if (res.headers['retry-after']) {\n retryTime = parseRetryAfterToMills(res.headers['retry-after']!);\n } else {\n // exponential backoff with jitter\n retryTime = Math.round(\n Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +\n minDelay\n );\n }\n\n retryTimer = setTimeout(() => {\n sendWithRetry(retries - 1, minDelay);\n }, retryTime);\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n responseData\n );\n onError(error);\n // clear all timers since request was completed and promise was resolved\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n }\n }\n });\n });\n\n req.on('error', (error: Error | any) => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout', error.code);\n onError(err);\n } else {\n onError(error);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n });\n\n req.on('abort', () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n });\n\n switch (collector.compression) {\n case CompressionAlgorithm.GZIP: {\n req.setHeader('Content-Encoding', 'gzip');\n const dataStream = readableFromUnit8Array(data);\n dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError)\n .pipe(req);\n\n break;\n }\n default:\n req.end(Buffer.from(data));\n break;\n }\n };\n sendWithRetry();\n}\n\nfunction readableFromUnit8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n config: OTLPExporterNodeConfigBase\n): http.Agent | https.Agent | undefined {\n if (config.httpAgentOptions && config.keepAlive === false) {\n diag.warn('httpAgentOptions is used only when keepAlive is true');\n return undefined;\n }\n\n if (config.keepAlive === false || !config.url) return undefined;\n\n try {\n const parsedUrl = new url.URL(config.url as string);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent({ keepAlive: true, ...config.httpAgentOptions });\n } catch (err) {\n diag.error(\n `collector exporter failed to create http agent. err: ${err.message}`\n );\n return undefined;\n }\n}\n\nexport function configureCompression(\n compression: CompressionAlgorithm | undefined\n): CompressionAlgorithm {\n if (compression) {\n return compression;\n } else {\n const definedCompression =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||\n getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n return definedCompression === CompressionAlgorithm.GZIP\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE;\n }\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,UAAU,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,MAAM,EAAE,CAAC,qCAAqC;YAC9C,MAAM,EAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,oBAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,oBAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,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 { CompressionAlgorithm } from './types';\nimport { getEnv } from '@opentelemetry/core';\n\nexport function configureCompression(\n compression: CompressionAlgorithm | undefined\n): CompressionAlgorithm {\n if (compression) {\n return compression;\n } else {\n const definedCompression =\n getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION ||\n getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n return definedCompression === CompressionAlgorithm.GZIP\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE;\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { IExporterTransport } from './exporter-transport';
2
+ /**
3
+ * Creates an Exporter Transport that retries on 'retryable' response.
4
+ */
5
+ export declare function createRetryingTransport(options: {
6
+ transport: IExporterTransport;
7
+ }): IExporterTransport;
8
+ //# sourceMappingURL=retrying-transport.d.ts.map
@@ -0,0 +1,69 @@
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
+ const MAX_ATTEMPTS = 5;
17
+ const INITIAL_BACKOFF = 1000;
18
+ const MAX_BACKOFF = 5000;
19
+ const BACKOFF_MULTIPLIER = 1.5;
20
+ const JITTER = 0.2;
21
+ /**
22
+ * Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]
23
+ */
24
+ function getJitter() {
25
+ return Math.random() * (2 * JITTER) - JITTER;
26
+ }
27
+ class RetryingTransport {
28
+ constructor(_transport) {
29
+ this._transport = _transport;
30
+ }
31
+ retry(data, timeoutMillis, inMillis) {
32
+ return new Promise((resolve, reject) => {
33
+ setTimeout(() => {
34
+ this._transport.send(data, timeoutMillis).then(resolve, reject);
35
+ }, inMillis);
36
+ });
37
+ }
38
+ async send(data, timeoutMillis) {
39
+ var _a;
40
+ const deadline = Date.now() + timeoutMillis;
41
+ let result = await this._transport.send(data, timeoutMillis);
42
+ let attempts = MAX_ATTEMPTS;
43
+ let nextBackoff = INITIAL_BACKOFF;
44
+ while (result.status === 'retryable' && attempts > 0) {
45
+ attempts--;
46
+ // use maximum of computed backoff and 0 to avoid negative timeouts
47
+ const backoff = Math.max(Math.min(nextBackoff, MAX_BACKOFF) + getJitter(), 0);
48
+ nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;
49
+ const retryInMillis = (_a = result.retryInMillis) !== null && _a !== void 0 ? _a : backoff;
50
+ // return when expected retry time is after the export deadline.
51
+ const remainingTimeoutMillis = deadline - Date.now();
52
+ if (retryInMillis > remainingTimeoutMillis) {
53
+ return result;
54
+ }
55
+ result = await this.retry(data, remainingTimeoutMillis, retryInMillis);
56
+ }
57
+ return result;
58
+ }
59
+ shutdown() {
60
+ return this._transport.shutdown();
61
+ }
62
+ }
63
+ /**
64
+ * Creates an Exporter Transport that retries on 'retryable' response.
65
+ */
66
+ export function createRetryingTransport(options) {
67
+ return new RetryingTransport(options.transport);
68
+ }
69
+ //# sourceMappingURL=retrying-trans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pD,QAAQ,EAAE,CAAC;YAEX,mEAAmE;YACnE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACtB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG,SAAS,EAAE,EAChD,CAAC,CACF,CAAC;YACF,WAAW,GAAG,WAAW,GAAG,kBAAkB,CAAC;YAC/C,MAAM,aAAa,GAAG,MAAA,MAAM,CAAC,aAAa,mCAAI,OAAO,CAAC;YAEtD,gEAAgE;YAChE,MAAM,sBAAsB,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACrD,IAAI,aAAa,GAAG,sBAAsB,EAAE;gBAC1C,OAAO,MAAM,CAAC;aACf;YAED,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,sBAAsB,EAAE,aAAa,CAAC,CAAC;SACxE;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAGvC;IACC,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClD,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';\n\nconst MAX_ATTEMPTS = 5;\nconst INITIAL_BACKOFF = 1000;\nconst MAX_BACKOFF = 5000;\nconst BACKOFF_MULTIPLIER = 1.5;\nconst JITTER = 0.2;\n\n/**\n * Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]\n */\nfunction getJitter() {\n return Math.random() * (2 * JITTER) - JITTER;\n}\n\nclass RetryingTransport implements IExporterTransport {\n constructor(private _transport: IExporterTransport) {}\n\n private retry(\n data: Uint8Array,\n timeoutMillis: number,\n inMillis: number\n ): Promise<ExportResponse> {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n this._transport.send(data, timeoutMillis).then(resolve, reject);\n }, inMillis);\n });\n }\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const deadline = Date.now() + timeoutMillis;\n let result = await this._transport.send(data, timeoutMillis);\n let attempts = MAX_ATTEMPTS;\n let nextBackoff = INITIAL_BACKOFF;\n\n while (result.status === 'retryable' && attempts > 0) {\n attempts--;\n\n // use maximum of computed backoff and 0 to avoid negative timeouts\n const backoff = Math.max(\n Math.min(nextBackoff, MAX_BACKOFF) + getJitter(),\n 0\n );\n nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;\n const retryInMillis = result.retryInMillis ?? backoff;\n\n // return when expected retry time is after the export deadline.\n const remainingTimeoutMillis = deadline - Date.now();\n if (retryInMillis > remainingTimeoutMillis) {\n return result;\n }\n\n result = await this.retry(data, remainingTimeoutMillis, retryInMillis);\n }\n\n return result;\n }\n\n shutdown() {\n return this._transport.shutdown();\n }\n}\n\n/**\n * Creates an Exporter Transport that retries on 'retryable' response.\n */\nexport function createRetryingTransport(options: {\n // Underlying transport to wrap.\n transport: IExporterTransport;\n}): IExporterTransport {\n return new RetryingTransport(options.transport);\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.52.0";
1
+ export declare const VERSION = "0.53.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export const VERSION = '0.52.0';
17
+ export const VERSION = '0.53.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,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// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.52.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,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// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.53.0';\n"]}
@@ -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/OTLPExporterBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8CAI6B;AAM7B,iCAAkD;AAElD;;GAEG;AACH,MAAsB,gBAAgB;IAWpC;;OAEG;IACH,YAAY,SAAY,EAAO;QANrB,qBAAgB,GAAuB,EAAE,CAAC;QAOlD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SACjC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,aAAa,GAAG,IAAI,qBAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAE9D,IAAI,CAAC,iBAAiB;YACpB,OAAO,MAAM,CAAC,gBAAgB,KAAK,QAAQ;gBACzC,CAAC,CAAC,MAAM,CAAC,gBAAgB;gBACzB,CAAC,CAAC,EAAE,CAAC;QAET,IAAI,CAAC,aAAa,GAAG,IAAA,+BAAwB,EAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAEpE,qBAAqB;QACrB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,MAAM,CACJ,KAAmB,EACnB,cAA8C;QAE9C,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,cAAc,CAAC;gBACb,IAAI,EAAE,uBAAgB,CAAC,MAAM;gBAC7B,KAAK,EAAE,IAAI,KAAK,CAAC,4BAA4B,CAAC;aAC/C,CAAC,CAAC;YACH,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C/B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;CAUF;AAhHD,4CAgHC","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,4CAA0C;AAC1C,8CAI6B;AAM7B,iCAAkD;AAElD;;GAEG;AACH,MAAsB,gBAAgB;IAcpC;;OAEG;IACH,YAAY,SAAY,EAAO;QANrB,qBAAgB,GAAuB,EAAE,CAAC;QAOlD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ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AAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,OAAO,CAAC,KAAmB;QACjC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI;gBACF,UAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;gBACtC,IAAI,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,QAAQ;QACN,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAClD,6BAA6B;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,SAAS;QACf,UAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC/B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;CAUF;AAnHD,4CAmHC","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,18 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ //# sourceMappingURL=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,18 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ //# sourceMappingURL=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