@opentelemetry/otlp-exporter-base 0.35.0 → 0.36.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 (70) hide show
  1. package/build/esm/index.d.ts +3 -3
  2. package/build/esm/index.js +3 -3
  3. package/build/esm/index.js.map +1 -1
  4. package/build/esm/platform/browser/index.d.ts +2 -1
  5. package/build/esm/platform/browser/index.js +2 -1
  6. package/build/esm/platform/browser/index.js.map +1 -1
  7. package/build/esm/platform/browser/util.d.ts +1 -1
  8. package/build/esm/platform/browser/util.js +71 -27
  9. package/build/esm/platform/browser/util.js.map +1 -1
  10. package/build/esm/platform/index.d.ts +2 -2
  11. package/build/esm/platform/index.js +2 -2
  12. package/build/esm/platform/index.js.map +1 -1
  13. package/build/esm/platform/node/index.d.ts +3 -3
  14. package/build/esm/platform/node/index.js +3 -3
  15. package/build/esm/platform/node/index.js.map +1 -1
  16. package/build/esm/platform/node/util.js +88 -46
  17. package/build/esm/platform/node/util.js.map +1 -1
  18. package/build/esm/util.d.ts +6 -0
  19. package/build/esm/util.js +23 -0
  20. package/build/esm/util.js.map +1 -1
  21. package/build/esm/version.d.ts +1 -1
  22. package/build/esm/version.js +1 -1
  23. package/build/esm/version.js.map +1 -1
  24. package/build/esnext/index.d.ts +3 -3
  25. package/build/esnext/index.js +3 -3
  26. package/build/esnext/index.js.map +1 -1
  27. package/build/esnext/platform/browser/index.d.ts +2 -1
  28. package/build/esnext/platform/browser/index.js +2 -1
  29. package/build/esnext/platform/browser/index.js.map +1 -1
  30. package/build/esnext/platform/browser/util.d.ts +1 -1
  31. package/build/esnext/platform/browser/util.js +68 -26
  32. package/build/esnext/platform/browser/util.js.map +1 -1
  33. package/build/esnext/platform/index.d.ts +2 -2
  34. package/build/esnext/platform/index.js +2 -2
  35. package/build/esnext/platform/index.js.map +1 -1
  36. package/build/esnext/platform/node/index.d.ts +3 -3
  37. package/build/esnext/platform/node/index.js +3 -3
  38. package/build/esnext/platform/node/index.js.map +1 -1
  39. package/build/esnext/platform/node/util.js +86 -46
  40. package/build/esnext/platform/node/util.js.map +1 -1
  41. package/build/esnext/util.d.ts +6 -0
  42. package/build/esnext/util.js +23 -0
  43. package/build/esnext/util.js.map +1 -1
  44. package/build/esnext/version.d.ts +1 -1
  45. package/build/esnext/version.js +1 -1
  46. package/build/esnext/version.js.map +1 -1
  47. package/build/src/index.d.ts +3 -3
  48. package/build/src/index.js +11 -3
  49. package/build/src/index.js.map +1 -1
  50. package/build/src/platform/browser/index.d.ts +2 -1
  51. package/build/src/platform/browser/index.js +5 -11
  52. package/build/src/platform/browser/index.js.map +1 -1
  53. package/build/src/platform/browser/util.d.ts +1 -1
  54. package/build/src/platform/browser/util.js +68 -26
  55. package/build/src/platform/browser/util.js.map +1 -1
  56. package/build/src/platform/index.d.ts +2 -2
  57. package/build/src/platform/index.js +9 -13
  58. package/build/src/platform/index.js.map +1 -1
  59. package/build/src/platform/node/index.d.ts +3 -3
  60. package/build/src/platform/node/index.js +9 -13
  61. package/build/src/platform/node/index.js.map +1 -1
  62. package/build/src/platform/node/util.js +86 -46
  63. package/build/src/platform/node/util.js.map +1 -1
  64. package/build/src/util.d.ts +6 -0
  65. package/build/src/util.js +26 -1
  66. package/build/src/util.js.map +1 -1
  67. package/build/src/version.d.ts +1 -1
  68. package/build/src/version.js +1 -1
  69. package/build/src/version.js.map +1 -1
  70. package/package.json +4 -4
@@ -1,5 +1,5 @@
1
- export * from './OTLPExporterBase';
2
1
  export * from './platform';
3
- export * from './types';
4
- export * from './util';
2
+ export { OTLPExporterBase } from './OTLPExporterBase';
3
+ export { OTLPExporterError, OTLPExporterConfigBase, ExportServiceError, } from './types';
4
+ export { parseHeaders, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, configureExporterTimeout, invalidTimeout, } from './util';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './OTLPExporterBase';
17
16
  export * from './platform';
18
- export * from './types';
19
- export * from './util';
17
+ export { OTLPExporterBase } from './OTLPExporterBase';
18
+ export { OTLPExporterError, } from './types';
19
+ export { parseHeaders, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, configureExporterTimeout, invalidTimeout, } from './util';
20
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,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 './OTLPExporterBase';\nexport * from './platform';\nexport * from './types';\nexport * from './util';\n"]}
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,2 +1,3 @@
1
- export * from './OTLPExporterBrowserBase';
1
+ export { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
2
+ export { sendWithXhr } from './util';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -13,5 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './OTLPExporterBrowserBase';
16
+ export { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
17
+ export { sendWithXhr } from './util';
17
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,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 * from './OTLPExporterBrowserBase';\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;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"]}
@@ -17,5 +17,5 @@ export declare function sendWithBeacon(body: string, url: string, blobPropertyBa
17
17
  * @param onSuccess
18
18
  * @param onError
19
19
  */
20
- export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
20
+ export declare function sendWithXhr(body: string | Blob, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
21
21
  //# sourceMappingURL=util.d.ts.map
@@ -42,6 +42,7 @@ var __read = (this && this.__read) || function (o, n) {
42
42
  */
43
43
  import { diag } from '@opentelemetry/api';
44
44
  import { OTLPExporterError } from '../../types';
45
+ import { DEFAULT_EXPORT_MAX_ATTEMPTS, DEFAULT_EXPORT_INITIAL_BACKOFF, DEFAULT_EXPORT_BACKOFF_MULTIPLIER, DEFAULT_EXPORT_MAX_BACKOFF, isExportRetryable, parseRetryAfterToMills, } from '../../util';
45
46
  /**
46
47
  * Send metrics/spans using browser navigator.sendBeacon
47
48
  * @param body
@@ -70,39 +71,82 @@ export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
70
71
  * @param onError
71
72
  */
72
73
  export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
73
- var reqIsDestroyed;
74
+ var retryTimer;
75
+ var xhr;
76
+ var reqIsDestroyed = false;
74
77
  var exporterTimer = setTimeout(function () {
78
+ clearTimeout(retryTimer);
75
79
  reqIsDestroyed = true;
76
- xhr.abort();
77
- }, exporterTimeout);
78
- var xhr = new XMLHttpRequest();
79
- xhr.open('POST', url);
80
- var defaultHeaders = {
81
- Accept: 'application/json',
82
- 'Content-Type': 'application/json',
83
- };
84
- Object.entries(__assign(__assign({}, defaultHeaders), headers)).forEach(function (_a) {
85
- var _b = __read(_a, 2), k = _b[0], v = _b[1];
86
- xhr.setRequestHeader(k, v);
87
- });
88
- xhr.send(body);
89
- xhr.onreadystatechange = function () {
90
80
  if (xhr.readyState === XMLHttpRequest.DONE) {
91
- if (xhr.status >= 200 && xhr.status <= 299) {
92
- clearTimeout(exporterTimer);
93
- diag.debug('xhr success', body);
94
- onSuccess();
81
+ var err = new OTLPExporterError('Request Timeout');
82
+ onError(err);
83
+ }
84
+ else {
85
+ xhr.abort();
86
+ }
87
+ }, exporterTimeout);
88
+ var sendWithRetry = function (retries, minDelay) {
89
+ if (retries === void 0) { retries = DEFAULT_EXPORT_MAX_ATTEMPTS; }
90
+ if (minDelay === void 0) { minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF; }
91
+ xhr = new XMLHttpRequest();
92
+ xhr.open('POST', url);
93
+ var defaultHeaders = {
94
+ Accept: 'application/json',
95
+ 'Content-Type': 'application/json',
96
+ };
97
+ Object.entries(__assign(__assign({}, defaultHeaders), headers)).forEach(function (_a) {
98
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
99
+ xhr.setRequestHeader(k, v);
100
+ });
101
+ xhr.send(body);
102
+ xhr.onreadystatechange = function () {
103
+ if (xhr.readyState === XMLHttpRequest.DONE && reqIsDestroyed === false) {
104
+ if (xhr.status >= 200 && xhr.status <= 299) {
105
+ diag.debug('xhr success', body);
106
+ onSuccess();
107
+ clearTimeout(exporterTimer);
108
+ clearTimeout(retryTimer);
109
+ }
110
+ else if (xhr.status && isExportRetryable(xhr.status) && retries > 0) {
111
+ var retryTime = void 0;
112
+ minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
113
+ // retry after interval specified in Retry-After header
114
+ if (xhr.getResponseHeader('Retry-After')) {
115
+ retryTime = parseRetryAfterToMills(xhr.getResponseHeader('Retry-After'));
116
+ }
117
+ else {
118
+ // exponential backoff with jitter
119
+ retryTime = Math.round(Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) + minDelay);
120
+ }
121
+ retryTimer = setTimeout(function () {
122
+ sendWithRetry(retries - 1, minDelay);
123
+ }, retryTime);
124
+ }
125
+ else {
126
+ var error = new OTLPExporterError("Failed to export with XHR (status: " + xhr.status + ")", xhr.status);
127
+ onError(error);
128
+ clearTimeout(exporterTimer);
129
+ clearTimeout(retryTimer);
130
+ }
95
131
  }
96
- else if (reqIsDestroyed) {
97
- var error = new OTLPExporterError('Request Timeout', xhr.status);
98
- onError(error);
132
+ };
133
+ xhr.onabort = function () {
134
+ if (reqIsDestroyed) {
135
+ var err = new OTLPExporterError('Request Timeout');
136
+ onError(err);
99
137
  }
100
- else {
101
- var error = new OTLPExporterError("Failed to export with XHR (status: " + xhr.status + ")", xhr.status);
102
- clearTimeout(exporterTimer);
103
- onError(error);
138
+ clearTimeout(exporterTimer);
139
+ clearTimeout(retryTimer);
140
+ };
141
+ xhr.onerror = function () {
142
+ if (reqIsDestroyed) {
143
+ var err = new OTLPExporterError('Request Timeout');
144
+ onError(err);
104
145
  }
105
- }
146
+ clearTimeout(exporterTimer);
147
+ clearTimeout(retryTimer);
148
+ };
106
149
  };
150
+ sendWithRetry();
107
151
  }
108
152
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA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AE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEf,GAAG,CAAC,kBAAkB,GAAG;QACvB,IAAI,GAAG,CAAC,UAAU,KAAK,cAAc,CAAC,IAAI,EAAE;YAC1C,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;gBAC1C,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBAChC,SAAS,EAAE,CAAC;aACb;iBAAM,IAAI,cAAc,EAAE;gBACzB,IAAM,KAAK,GAAG,IAAI,iBAAiB,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBACnE,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;iBAAM;gBACL,IAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,wCAAsC,GAAG,CAAC,MAAM,MAAG,EACnD,GAAG,CAAC,MAAM,CACX,CAAC;gBACF,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC5B,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC;AACJ,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 { diag } from '@opentelemetry/api';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Send metrics/spans using browser navigator.sendBeacon\n * @param body\n * @param url\n * @param blobPropertyBag\n * @param onSuccess\n * @param onError\n */\nexport function sendWithBeacon(\n body: string,\n url: string,\n blobPropertyBag: BlobPropertyBag,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {\n diag.debug('sendBeacon - can send', body);\n onSuccess();\n } else {\n const error = new OTLPExporterError(`sendBeacon - cannot send ${body}`);\n onError(error);\n }\n}\n\n/**\n * function to send metrics/spans using browser XMLHttpRequest\n * used when navigator.sendBeacon is not available\n * @param body\n * @param url\n * @param headers\n * @param onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string,\n url: string,\n headers: Record<string, string>,\n exporterTimeout: number,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n let reqIsDestroyed: boolean;\n\n const exporterTimer = setTimeout(() => {\n reqIsDestroyed = true;\n xhr.abort();\n }, exporterTimeout);\n\n const xhr = new XMLHttpRequest();\n xhr.open('POST', url);\n\n const defaultHeaders = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n };\n\n Object.entries({\n ...defaultHeaders,\n ...headers,\n }).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.send(body);\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n if (xhr.status >= 200 && xhr.status <= 299) {\n clearTimeout(exporterTimer);\n diag.debug('xhr success', body);\n onSuccess();\n } else if (reqIsDestroyed) {\n const error = new OTLPExporterError('Request Timeout', xhr.status);\n onError(error);\n } else {\n const error = new OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n clearTimeout(exporterTimer);\n onError(error);\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBA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AM;wBACL,kCAAkC;wBAClC,SAAS,GAAG,IAAI,CAAC,KAAK,CACpB,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,0BAA0B,GAAG,QAAQ,CAAC,GAAG,QAAQ,CACnE,CAAC;qBACH;oBAED,UAAU,GAAG,UAAU,CAAC;wBACtB,aAAa,CAAC,OAAO,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;oBACvC,CAAC,EAAE,SAAS,CAAC,CAAC;iBACf;qBAAM;oBACL,IAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,wCAAsC,GAAG,CAAC,MAAM,MAAG,EACnD,GAAG,CAAC,MAAM,CACX,CAAC;oBACF,OAAO,CAAC,KAAK,CAAC,CAAC;oBACf,YAAY,CAAC,aAAa,CAAC,CAAC;oBAC5B,YAAY,CAAC,UAAU,CAAC,CAAC;iBAC1B;aACF;QACH,CAAC,CAAC;QAEF,GAAG,CAAC,OAAO,GAAG;YACZ,IAAI,cAAc,EAAE;gBAClB,IAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;gBACrD,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;YACD,YAAY,CAAC,aAAa,CAAC,CAAC;YAC5B,YAAY,CAAC,UAAU,CAAC,CAAC;QAC3B,CAAC,CAAC;QAEF,GAAG,CAAC,OAAO,GAAG;YACZ,IAAI,cAAc,EAAE;gBAClB,IAAM,GAAG,GAAG,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;gBACrD,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;YACD,YAAY,CAAC,aAAa,CAAC,CAAC;YAC5B,YAAY,CAAC,UAAU,CAAC,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,aAAa,EAAE,CAAC;AAClB,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 { diag } from '@opentelemetry/api';\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 * Send metrics/spans using browser navigator.sendBeacon\n * @param body\n * @param url\n * @param blobPropertyBag\n * @param onSuccess\n * @param onError\n */\nexport function sendWithBeacon(\n body: string,\n url: string,\n blobPropertyBag: BlobPropertyBag,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {\n diag.debug('sendBeacon - can send', body);\n onSuccess();\n } else {\n const error = new OTLPExporterError(`sendBeacon - cannot send ${body}`);\n onError(error);\n }\n}\n\n/**\n * function to send metrics/spans using browser XMLHttpRequest\n * used when navigator.sendBeacon is not available\n * @param body\n * @param url\n * @param headers\n * @param onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string | Blob,\n url: string,\n headers: Record<string, string>,\n exporterTimeout: number,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n let retryTimer: ReturnType<typeof setTimeout>;\n let xhr: XMLHttpRequest;\n let reqIsDestroyed = false;\n\n const exporterTimer = setTimeout(() => {\n clearTimeout(retryTimer);\n reqIsDestroyed = true;\n\n if (xhr.readyState === XMLHttpRequest.DONE) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n } else {\n xhr.abort();\n }\n }, exporterTimeout);\n\n const sendWithRetry = (\n retries = DEFAULT_EXPORT_MAX_ATTEMPTS,\n minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF\n ) => {\n xhr = new XMLHttpRequest();\n xhr.open('POST', url);\n\n const defaultHeaders = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n };\n\n Object.entries({\n ...defaultHeaders,\n ...headers,\n }).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.send(body);\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE && reqIsDestroyed === false) {\n if (xhr.status >= 200 && xhr.status <= 299) {\n diag.debug('xhr success', body);\n onSuccess();\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n } else if (xhr.status && isExportRetryable(xhr.status) && retries > 0) {\n let retryTime: number;\n minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;\n\n // retry after interval specified in Retry-After header\n if (xhr.getResponseHeader('Retry-After')) {\n retryTime = parseRetryAfterToMills(\n xhr.getResponseHeader('Retry-After')!\n );\n } else {\n // exponential backoff with jitter\n retryTime = Math.round(\n Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) + minDelay\n );\n }\n\n retryTimer = setTimeout(() => {\n sendWithRetry(retries - 1, minDelay);\n }, retryTime);\n } else {\n const error = new OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n onError(error);\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n }\n }\n };\n\n xhr.onabort = () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n };\n\n xhr.onerror = () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError('Request Timeout');\n onError(err);\n }\n clearTimeout(exporterTimer);\n clearTimeout(retryTimer);\n };\n };\n\n sendWithRetry();\n}\n"]}
@@ -1,3 +1,3 @@
1
- export * from './node';
2
- export { OTLPExporterBrowserBase } from './browser';
1
+ export { OTLPExporterNodeBase, sendWithHttp, createHttpAgent, configureCompression, OTLPExporterNodeConfigBase, CompressionAlgorithm, } from './node';
2
+ export { OTLPExporterBrowserBase, sendWithXhr } 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 * from './node';
17
- export { OTLPExporterBrowserBase } from './browser';
16
+ export { OTLPExporterNodeBase, sendWithHttp, createHttpAgent, configureCompression, CompressionAlgorithm, } from './node';
17
+ export { OTLPExporterBrowserBase, sendWithXhr } 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;AACH,cAAc,QAAQ,CAAC;AACvB,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 */\nexport * from './node';\nexport { OTLPExporterBrowserBase } from './browser';\n"]}
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,4 +1,4 @@
1
- export * from './OTLPExporterNodeBase';
2
- export * from './util';
3
- export * from './types';
1
+ export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
2
+ export { sendWithHttp, createHttpAgent, configureCompression } from './util';
3
+ export { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export * from './OTLPExporterNodeBase';
17
- export * from './util';
18
- export * from './types';
16
+ export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
17
+ export { sendWithHttp, createHttpAgent, configureCompression } from './util';
18
+ export { CompressionAlgorithm } from './types';
19
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC;AACvB,cAAc,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 * from './OTLPExporterNodeBase';\nexport * from './util';\nexport * 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,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"]}
@@ -33,6 +33,7 @@ import { diag } from '@opentelemetry/api';
33
33
  import { CompressionAlgorithm } from './types';
34
34
  import { getEnv } from '@opentelemetry/core';
35
35
  import { OTLPExporterError } from '../../types';
36
+ import { DEFAULT_EXPORT_MAX_ATTEMPTS, DEFAULT_EXPORT_INITIAL_BACKOFF, DEFAULT_EXPORT_BACKOFF_MULTIPLIER, DEFAULT_EXPORT_MAX_BACKOFF, isExportRetryable, parseRetryAfterToMills, } from '../../util';
36
37
  /**
37
38
  * Sends data using http
38
39
  * @param collector
@@ -44,16 +45,20 @@ import { OTLPExporterError } from '../../types';
44
45
  export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
45
46
  var exporterTimeout = collector.timeoutMillis;
46
47
  var parsedUrl = new url.URL(collector.url);
47
- var reqIsDestroyed;
48
48
  var nodeVersion = Number(process.versions.node.split('.')[0]);
49
+ var retryTimer;
50
+ var req;
51
+ var reqIsDestroyed = false;
49
52
  var exporterTimer = setTimeout(function () {
53
+ clearTimeout(retryTimer);
50
54
  reqIsDestroyed = true;
51
- // req.abort() was deprecated since v14
52
- if (nodeVersion >= 14) {
53
- req.destroy();
55
+ if (req.destroyed) {
56
+ var err = new OTLPExporterError('Request Timeout');
57
+ onError(err);
54
58
  }
55
59
  else {
56
- req.abort();
60
+ // req.abort() was deprecated since v14
61
+ nodeVersion >= 14 ? req.destroy() : req.abort();
57
62
  }
58
63
  }, exporterTimeout);
59
64
  var options = {
@@ -65,54 +70,91 @@ export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
65
70
  agent: collector.agent,
66
71
  };
67
72
  var request = parsedUrl.protocol === 'http:' ? http.request : https.request;
68
- var req = request(options, function (res) {
69
- var responseData = '';
70
- res.on('data', function (chunk) { return (responseData += chunk); });
71
- res.on('aborted', function () {
73
+ var sendWithRetry = function (retries, minDelay) {
74
+ if (retries === void 0) { retries = DEFAULT_EXPORT_MAX_ATTEMPTS; }
75
+ if (minDelay === void 0) { minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF; }
76
+ req = request(options, function (res) {
77
+ var responseData = '';
78
+ res.on('data', function (chunk) { return (responseData += chunk); });
79
+ res.on('aborted', function () {
80
+ if (reqIsDestroyed) {
81
+ var err = new OTLPExporterError('Request Timeout');
82
+ onError(err);
83
+ }
84
+ });
85
+ res.on('end', function () {
86
+ if (reqIsDestroyed === false) {
87
+ if (res.statusCode && res.statusCode < 299) {
88
+ diag.debug("statusCode: " + res.statusCode, responseData);
89
+ onSuccess();
90
+ // clear all timers since request was completed and promise was resolved
91
+ clearTimeout(exporterTimer);
92
+ clearTimeout(retryTimer);
93
+ }
94
+ else if (res.statusCode &&
95
+ isExportRetryable(res.statusCode) &&
96
+ retries > 0) {
97
+ var retryTime = void 0;
98
+ minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
99
+ // retry after interval specified in Retry-After header
100
+ if (res.headers['retry-after']) {
101
+ retryTime = parseRetryAfterToMills(res.headers['retry-after']);
102
+ }
103
+ else {
104
+ // exponential backoff with jitter
105
+ retryTime = Math.round(Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +
106
+ minDelay);
107
+ }
108
+ retryTimer = setTimeout(function () {
109
+ sendWithRetry(retries - 1, minDelay);
110
+ }, retryTime);
111
+ }
112
+ else {
113
+ var error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
114
+ onError(error);
115
+ // clear all timers since request was completed and promise was resolved
116
+ clearTimeout(exporterTimer);
117
+ clearTimeout(retryTimer);
118
+ }
119
+ }
120
+ });
121
+ });
122
+ req.on('error', function (error) {
72
123
  if (reqIsDestroyed) {
73
- var err = new OTLPExporterError('Request Timeout');
124
+ var err = new OTLPExporterError('Request Timeout', error.code);
74
125
  onError(err);
75
126
  }
76
- });
77
- res.on('end', function () {
78
- if (!reqIsDestroyed) {
79
- if (res.statusCode && res.statusCode < 299) {
80
- diag.debug("statusCode: " + res.statusCode, responseData);
81
- onSuccess();
82
- }
83
- else {
84
- var error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
85
- onError(error);
86
- }
87
- clearTimeout(exporterTimer);
127
+ else {
128
+ onError(error);
88
129
  }
130
+ clearTimeout(exporterTimer);
131
+ clearTimeout(retryTimer);
89
132
  });
90
- });
91
- req.on('error', function (error) {
92
- if (reqIsDestroyed) {
93
- var err = new OTLPExporterError('Request Timeout', error.code);
94
- onError(err);
95
- }
96
- else {
133
+ req.on('abort', function () {
134
+ if (reqIsDestroyed) {
135
+ var err = new OTLPExporterError('Request Timeout');
136
+ onError(err);
137
+ }
97
138
  clearTimeout(exporterTimer);
98
- onError(error);
99
- }
100
- });
101
- switch (collector.compression) {
102
- case CompressionAlgorithm.GZIP: {
103
- req.setHeader('Content-Encoding', 'gzip');
104
- var dataStream = readableFromBuffer(data);
105
- dataStream
106
- .on('error', onError)
107
- .pipe(zlib.createGzip())
108
- .on('error', onError)
109
- .pipe(req);
110
- break;
139
+ clearTimeout(retryTimer);
140
+ });
141
+ switch (collector.compression) {
142
+ case CompressionAlgorithm.GZIP: {
143
+ req.setHeader('Content-Encoding', 'gzip');
144
+ var dataStream = readableFromBuffer(data);
145
+ dataStream
146
+ .on('error', onError)
147
+ .pipe(zlib.createGzip())
148
+ .on('error', onError)
149
+ .pipe(req);
150
+ break;
151
+ }
152
+ default:
153
+ req.end(data);
154
+ break;
111
155
  }
112
- default:
113
- req.end(data);
114
- break;
115
- }
156
+ };
157
+ sendWithRetry();
116
158
  }
117
159
  function readableFromBuffer(buff) {
118
160
  var readable = new Readable();
@@ -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,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IA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OAAO,WAAW,CAAC;KACpB;SAAM;QACL,IAAM,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';\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, ServiceRequest>(\n collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>,\n data: string | Buffer,\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 let reqIsDestroyed: boolean;\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n\n const exporterTimer = setTimeout(() => {\n reqIsDestroyed = true;\n // req.abort() was deprecated since v14\n if (nodeVersion >= 14) {\n req.destroy();\n } else {\n 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 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) {\n if (res.statusCode && res.statusCode < 299) {\n diag.debug(`statusCode: ${res.statusCode}`, responseData);\n onSuccess();\n } else {\n const error = new OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n responseData\n );\n onError(error);\n }\n clearTimeout(exporterTimer);\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 clearTimeout(exporterTimer);\n onError(error);\n }\n });\n\n switch (collector.compression) {\n case CompressionAlgorithm.GZIP: {\n req.setHeader('Content-Encoding', 'gzip');\n const dataStream = readableFromBuffer(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(data);\n break;\n }\n}\n\nfunction readableFromBuffer(buff: string | Buffer): 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;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,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,iCAAiC,EACjC,0BAA0B,EAC1B,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IAE3C,IAAM,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAChD,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CA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I,CAAC,KAAK,CACR,0DAAwD,GAAG,CAAC,OAAS,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,IAAM,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, ServiceRequest>(\n collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>,\n data: string | Buffer,\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 = readableFromBuffer(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(data);\n break;\n }\n };\n sendWithRetry();\n}\n\nfunction readableFromBuffer(buff: string | Buffer): 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,3 +1,7 @@
1
+ export declare const DEFAULT_EXPORT_MAX_ATTEMPTS = 5;
2
+ export declare const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
3
+ export declare const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
4
+ export declare const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
1
5
  /**
2
6
  * Parses headers from config leaving only those that have defined values
3
7
  * @param partialHeaders
@@ -23,4 +27,6 @@ export declare function appendRootPathToUrlIfNeeded(url: string): string;
23
27
  */
24
28
  export declare function configureExporterTimeout(timeoutMillis: number | undefined): number;
25
29
  export declare function invalidTimeout(timeout: number, defaultTimeout: number): number;
30
+ export declare function isExportRetryable(statusCode: number): boolean;
31
+ export declare function parseRetryAfterToMills(retryAfter?: string | null): number;
26
32
  //# sourceMappingURL=util.d.ts.map
package/build/esm/util.js CHANGED
@@ -32,6 +32,10 @@ var __read = (this && this.__read) || function (o, n) {
32
32
  import { diag } from '@opentelemetry/api';
33
33
  import { getEnv } from '@opentelemetry/core';
34
34
  var DEFAULT_TRACE_TIMEOUT = 10000;
35
+ export var DEFAULT_EXPORT_MAX_ATTEMPTS = 5;
36
+ export var DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
37
+ export var DEFAULT_EXPORT_MAX_BACKOFF = 5000;
38
+ export var DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
35
39
  /**
36
40
  * Parses headers from config leaving only those that have defined values
37
41
  * @param partialHeaders
@@ -113,4 +117,23 @@ export function invalidTimeout(timeout, defaultTimeout) {
113
117
  diag.warn('Timeout must be greater than 0', timeout);
114
118
  return defaultTimeout;
115
119
  }
120
+ export function isExportRetryable(statusCode) {
121
+ var retryCodes = [429, 502, 503, 504];
122
+ return retryCodes.includes(statusCode);
123
+ }
124
+ export function parseRetryAfterToMills(retryAfter) {
125
+ if (retryAfter == null) {
126
+ return -1;
127
+ }
128
+ var seconds = Number.parseInt(retryAfter, 10);
129
+ if (Number.isInteger(seconds)) {
130
+ return seconds > 0 ? seconds * 1000 : -1;
131
+ }
132
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
133
+ var delay = new Date(retryAfter).getTime() - Date.now();
134
+ if (delay >= 0) {
135
+ return delay;
136
+ }
137
+ return 0;
138
+ }
116
139
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,IAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,cAAqD;IAArD,+BAAA,EAAA,mBAAqD;IAErD,IAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,UAAC,EAAY;YAAZ,KAAA,aAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;QACjD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;SAC9B;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,cAAW,GAAG,2CAAuC,CAAC,CAAC;SAClE;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,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;AAED,oEAAoE;AACpE,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,cAAsB;IAEtB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,cAAc,CAAC;AACxB,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 { diag } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\n\nconst DEFAULT_TRACE_TIMEOUT = 10000;\n\n/**\n * Parses headers from config leaving only those that have defined values\n * @param partialHeaders\n */\nexport function parseHeaders(\n partialHeaders: Partial<Record<string, unknown>> = {}\n): Record<string, string> {\n const headers: Record<string, string> = {};\n Object.entries(partialHeaders).forEach(([key, value]) => {\n if (typeof value !== 'undefined') {\n headers[key] = String(value);\n } else {\n diag.warn(`Header \"${key}\" has wrong value and will be ignored`);\n }\n });\n return headers;\n}\n\n/**\n * Adds path (version + signal) to a no per-signal endpoint\n * @param url\n * @param path\n * @returns url + path\n */\nexport function appendResourcePathToUrl(url: string, path: string): string {\n if (!url.endsWith('/')) {\n url = url + '/';\n }\n return url + path;\n}\n\n/**\n * Adds root path to signal specific endpoint when endpoint contains no path part and no root path\n * @param url\n * @returns url\n */\nexport function appendRootPathToUrlIfNeeded(url: string): string {\n try {\n const parsedUrl = new URL(url);\n if (parsedUrl.pathname === '') {\n parsedUrl.pathname = parsedUrl.pathname + '/';\n }\n return parsedUrl.toString();\n } catch {\n diag.warn(`Could not parse export URL: '${url}'`);\n return url;\n }\n}\n\n/**\n * Configure exporter trace timeout value from passed in value or environment variables\n * @param timeoutMillis\n * @returns timeout value in milliseconds\n */\nexport function configureExporterTimeout(\n timeoutMillis: number | undefined\n): number {\n if (typeof timeoutMillis === 'number') {\n if (timeoutMillis <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(timeoutMillis, DEFAULT_TRACE_TIMEOUT);\n }\n return timeoutMillis;\n } else {\n return getExporterTimeoutFromEnv();\n }\n}\n\nfunction getExporterTimeoutFromEnv(): number {\n const definedTimeout = Number(\n getEnv().OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ??\n getEnv().OTEL_EXPORTER_OTLP_TIMEOUT\n );\n\n if (definedTimeout <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(definedTimeout, DEFAULT_TRACE_TIMEOUT);\n } else {\n return definedTimeout;\n }\n}\n\n// OTLP exporter configured timeout - using default value of 10000ms\nexport function invalidTimeout(\n timeout: number,\n defaultTimeout: number\n): number {\n diag.warn('Timeout must be greater than 0', timeout);\n\n return defaultTimeout;\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,IAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,CAAC,IAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,IAAM,8BAA8B,GAAG,IAAI,CAAC;AACnD,MAAM,CAAC,IAAM,0BAA0B,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,IAAM,iCAAiC,GAAG,GAAG,CAAC;AAErD;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,cAAqD;IAArD,+BAAA,EAAA,mBAAqD;IAErD,IAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,CAAC,OAAO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C;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\nimport { diag } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\n\nconst DEFAULT_TRACE_TIMEOUT = 10000;\nexport const DEFAULT_EXPORT_MAX_ATTEMPTS = 5;\nexport const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;\nexport const DEFAULT_EXPORT_MAX_BACKOFF = 5000;\nexport const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;\n\n/**\n * Parses headers from config leaving only those that have defined values\n * @param partialHeaders\n */\nexport function parseHeaders(\n partialHeaders: Partial<Record<string, unknown>> = {}\n): Record<string, string> {\n const headers: Record<string, string> = {};\n Object.entries(partialHeaders).forEach(([key, value]) => {\n if (typeof value !== 'undefined') {\n headers[key] = String(value);\n } else {\n diag.warn(`Header \"${key}\" has wrong value and will be ignored`);\n }\n });\n return headers;\n}\n\n/**\n * Adds path (version + signal) to a no per-signal endpoint\n * @param url\n * @param path\n * @returns url + path\n */\nexport function appendResourcePathToUrl(url: string, path: string): string {\n if (!url.endsWith('/')) {\n url = url + '/';\n }\n return url + path;\n}\n\n/**\n * Adds root path to signal specific endpoint when endpoint contains no path part and no root path\n * @param url\n * @returns url\n */\nexport function appendRootPathToUrlIfNeeded(url: string): string {\n try {\n const parsedUrl = new URL(url);\n if (parsedUrl.pathname === '') {\n parsedUrl.pathname = parsedUrl.pathname + '/';\n }\n return parsedUrl.toString();\n } catch {\n diag.warn(`Could not parse export URL: '${url}'`);\n return url;\n }\n}\n\n/**\n * Configure exporter trace timeout value from passed in value or environment variables\n * @param timeoutMillis\n * @returns timeout value in milliseconds\n */\nexport function configureExporterTimeout(\n timeoutMillis: number | undefined\n): number {\n if (typeof timeoutMillis === 'number') {\n if (timeoutMillis <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(timeoutMillis, DEFAULT_TRACE_TIMEOUT);\n }\n return timeoutMillis;\n } else {\n return getExporterTimeoutFromEnv();\n }\n}\n\nfunction getExporterTimeoutFromEnv(): number {\n const definedTimeout = Number(\n getEnv().OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ??\n getEnv().OTEL_EXPORTER_OTLP_TIMEOUT\n );\n\n if (definedTimeout <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(definedTimeout, DEFAULT_TRACE_TIMEOUT);\n } else {\n return definedTimeout;\n }\n}\n\n// OTLP exporter configured timeout - using default value of 10000ms\nexport function invalidTimeout(\n timeout: number,\n defaultTimeout: number\n): number {\n diag.warn('Timeout must be greater than 0', timeout);\n\n return defaultTimeout;\n}\n\nexport function isExportRetryable(statusCode: number): boolean {\n const retryCodes = [429, 502, 503, 504];\n\n return retryCodes.includes(statusCode);\n}\n\nexport function parseRetryAfterToMills(retryAfter?: string | null): number {\n if (retryAfter == null) {\n return -1;\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,2 +1,2 @@
1
- export declare const VERSION = "0.35.0";
1
+ export declare const VERSION = "0.36.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 var VERSION = '0.35.0';
17
+ export var VERSION = '0.36.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,IAAM,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.35.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,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.36.0';\n"]}
@@ -1,5 +1,5 @@
1
- export * from './OTLPExporterBase';
2
1
  export * from './platform';
3
- export * from './types';
4
- export * from './util';
2
+ export { OTLPExporterBase } from './OTLPExporterBase';
3
+ export { OTLPExporterError, OTLPExporterConfigBase, ExportServiceError, } from './types';
4
+ export { parseHeaders, appendResourcePathToUrl, appendRootPathToUrlIfNeeded, configureExporterTimeout, invalidTimeout, } from './util';
5
5
  //# sourceMappingURL=index.d.ts.map