@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.
- package/build/esm/index.d.ts +3 -3
- package/build/esm/index.js +3 -3
- package/build/esm/index.js.map +1 -1
- package/build/esm/platform/browser/index.d.ts +2 -1
- package/build/esm/platform/browser/index.js +2 -1
- package/build/esm/platform/browser/index.js.map +1 -1
- package/build/esm/platform/browser/util.d.ts +1 -1
- package/build/esm/platform/browser/util.js +71 -27
- package/build/esm/platform/browser/util.js.map +1 -1
- package/build/esm/platform/index.d.ts +2 -2
- package/build/esm/platform/index.js +2 -2
- package/build/esm/platform/index.js.map +1 -1
- package/build/esm/platform/node/index.d.ts +3 -3
- package/build/esm/platform/node/index.js +3 -3
- package/build/esm/platform/node/index.js.map +1 -1
- package/build/esm/platform/node/util.js +88 -46
- package/build/esm/platform/node/util.js.map +1 -1
- package/build/esm/util.d.ts +6 -0
- package/build/esm/util.js +23 -0
- package/build/esm/util.js.map +1 -1
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/index.d.ts +3 -3
- package/build/esnext/index.js +3 -3
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/platform/browser/index.d.ts +2 -1
- package/build/esnext/platform/browser/index.js +2 -1
- package/build/esnext/platform/browser/index.js.map +1 -1
- package/build/esnext/platform/browser/util.d.ts +1 -1
- package/build/esnext/platform/browser/util.js +68 -26
- package/build/esnext/platform/browser/util.js.map +1 -1
- package/build/esnext/platform/index.d.ts +2 -2
- package/build/esnext/platform/index.js +2 -2
- package/build/esnext/platform/index.js.map +1 -1
- package/build/esnext/platform/node/index.d.ts +3 -3
- package/build/esnext/platform/node/index.js +3 -3
- package/build/esnext/platform/node/index.js.map +1 -1
- package/build/esnext/platform/node/util.js +86 -46
- package/build/esnext/platform/node/util.js.map +1 -1
- package/build/esnext/util.d.ts +6 -0
- package/build/esnext/util.js +23 -0
- package/build/esnext/util.js.map +1 -1
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/src/index.d.ts +3 -3
- package/build/src/index.js +11 -3
- package/build/src/index.js.map +1 -1
- package/build/src/platform/browser/index.d.ts +2 -1
- package/build/src/platform/browser/index.js +5 -11
- package/build/src/platform/browser/index.js.map +1 -1
- package/build/src/platform/browser/util.d.ts +1 -1
- package/build/src/platform/browser/util.js +68 -26
- package/build/src/platform/browser/util.js.map +1 -1
- package/build/src/platform/index.d.ts +2 -2
- package/build/src/platform/index.js +9 -13
- package/build/src/platform/index.js.map +1 -1
- package/build/src/platform/node/index.d.ts +3 -3
- package/build/src/platform/node/index.js +9 -13
- package/build/src/platform/node/index.js.map +1 -1
- package/build/src/platform/node/util.js +86 -46
- package/build/src/platform/node/util.js.map +1 -1
- package/build/src/util.d.ts +6 -0
- package/build/src/util.js +26 -1
- package/build/src/util.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +4 -4
package/build/esnext/index.js
CHANGED
|
@@ -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
|
|
19
|
-
export
|
|
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,
|
|
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"]}
|
|
@@ -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
|
|
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,
|
|
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
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { diag } from '@opentelemetry/api';
|
|
17
17
|
import { OTLPExporterError } from '../../types';
|
|
18
|
+
import { DEFAULT_EXPORT_MAX_ATTEMPTS, DEFAULT_EXPORT_INITIAL_BACKOFF, DEFAULT_EXPORT_BACKOFF_MULTIPLIER, DEFAULT_EXPORT_MAX_BACKOFF, isExportRetryable, parseRetryAfterToMills, } from '../../util';
|
|
18
19
|
/**
|
|
19
20
|
* Send metrics/spans using browser navigator.sendBeacon
|
|
20
21
|
* @param body
|
|
@@ -43,38 +44,79 @@ export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
|
43
44
|
* @param onError
|
|
44
45
|
*/
|
|
45
46
|
export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
46
|
-
let
|
|
47
|
+
let retryTimer;
|
|
48
|
+
let xhr;
|
|
49
|
+
let reqIsDestroyed = false;
|
|
47
50
|
const exporterTimer = setTimeout(() => {
|
|
51
|
+
clearTimeout(retryTimer);
|
|
48
52
|
reqIsDestroyed = true;
|
|
49
|
-
xhr.abort();
|
|
50
|
-
}, exporterTimeout);
|
|
51
|
-
const xhr = new XMLHttpRequest();
|
|
52
|
-
xhr.open('POST', url);
|
|
53
|
-
const defaultHeaders = {
|
|
54
|
-
Accept: 'application/json',
|
|
55
|
-
'Content-Type': 'application/json',
|
|
56
|
-
};
|
|
57
|
-
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
58
|
-
xhr.setRequestHeader(k, v);
|
|
59
|
-
});
|
|
60
|
-
xhr.send(body);
|
|
61
|
-
xhr.onreadystatechange = () => {
|
|
62
53
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
55
|
+
onError(err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
xhr.abort();
|
|
59
|
+
}
|
|
60
|
+
}, exporterTimeout);
|
|
61
|
+
const sendWithRetry = (retries = DEFAULT_EXPORT_MAX_ATTEMPTS, minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF) => {
|
|
62
|
+
xhr = new XMLHttpRequest();
|
|
63
|
+
xhr.open('POST', url);
|
|
64
|
+
const defaultHeaders = {
|
|
65
|
+
Accept: 'application/json',
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
};
|
|
68
|
+
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
69
|
+
xhr.setRequestHeader(k, v);
|
|
70
|
+
});
|
|
71
|
+
xhr.send(body);
|
|
72
|
+
xhr.onreadystatechange = () => {
|
|
73
|
+
if (xhr.readyState === XMLHttpRequest.DONE && reqIsDestroyed === false) {
|
|
74
|
+
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
75
|
+
diag.debug('xhr success', body);
|
|
76
|
+
onSuccess();
|
|
77
|
+
clearTimeout(exporterTimer);
|
|
78
|
+
clearTimeout(retryTimer);
|
|
79
|
+
}
|
|
80
|
+
else if (xhr.status && isExportRetryable(xhr.status) && retries > 0) {
|
|
81
|
+
let retryTime;
|
|
82
|
+
minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
|
|
83
|
+
// retry after interval specified in Retry-After header
|
|
84
|
+
if (xhr.getResponseHeader('Retry-After')) {
|
|
85
|
+
retryTime = parseRetryAfterToMills(xhr.getResponseHeader('Retry-After'));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// exponential backoff with jitter
|
|
89
|
+
retryTime = Math.round(Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) + minDelay);
|
|
90
|
+
}
|
|
91
|
+
retryTimer = setTimeout(() => {
|
|
92
|
+
sendWithRetry(retries - 1, minDelay);
|
|
93
|
+
}, retryTime);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const error = new OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status);
|
|
97
|
+
onError(error);
|
|
98
|
+
clearTimeout(exporterTimer);
|
|
99
|
+
clearTimeout(retryTimer);
|
|
100
|
+
}
|
|
67
101
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
102
|
+
};
|
|
103
|
+
xhr.onabort = () => {
|
|
104
|
+
if (reqIsDestroyed) {
|
|
105
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
106
|
+
onError(err);
|
|
71
107
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
clearTimeout(exporterTimer);
|
|
109
|
+
clearTimeout(retryTimer);
|
|
110
|
+
};
|
|
111
|
+
xhr.onerror = () => {
|
|
112
|
+
if (reqIsDestroyed) {
|
|
113
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
114
|
+
onError(err);
|
|
76
115
|
}
|
|
77
|
-
|
|
116
|
+
clearTimeout(exporterTimer);
|
|
117
|
+
clearTimeout(retryTimer);
|
|
118
|
+
};
|
|
78
119
|
};
|
|
120
|
+
sendWithRetry();
|
|
79
121
|
}
|
|
80
122
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
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,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
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,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,cAAc,CAC5B,IAAY,EACZ,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAA2C;IAE3C,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE;QAChE,IAAI,CAAC,KAAK,CAAC,uBAAuB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BACF,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,GAAG,EAAE;YACjB,IAAI,cAAc,EAAE;gBAClB,MAAM,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,GAAG,EAAE;YACjB,IAAI,cAAc,EAAE;gBAClB,MAAM,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
|
|
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
|
|
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;
|
|
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
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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
|
|
17
|
-
export
|
|
18
|
-
export
|
|
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,
|
|
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"]}
|
|
@@ -22,6 +22,7 @@ import { diag } from '@opentelemetry/api';
|
|
|
22
22
|
import { CompressionAlgorithm } from './types';
|
|
23
23
|
import { getEnv } from '@opentelemetry/core';
|
|
24
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';
|
|
25
26
|
/**
|
|
26
27
|
* Sends data using http
|
|
27
28
|
* @param collector
|
|
@@ -33,16 +34,20 @@ import { OTLPExporterError } from '../../types';
|
|
|
33
34
|
export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
34
35
|
const exporterTimeout = collector.timeoutMillis;
|
|
35
36
|
const parsedUrl = new url.URL(collector.url);
|
|
36
|
-
let reqIsDestroyed;
|
|
37
37
|
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
38
|
+
let retryTimer;
|
|
39
|
+
let req;
|
|
40
|
+
let reqIsDestroyed = false;
|
|
38
41
|
const exporterTimer = setTimeout(() => {
|
|
42
|
+
clearTimeout(retryTimer);
|
|
39
43
|
reqIsDestroyed = true;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
if (req.destroyed) {
|
|
45
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
46
|
+
onError(err);
|
|
43
47
|
}
|
|
44
48
|
else {
|
|
45
|
-
req.abort()
|
|
49
|
+
// req.abort() was deprecated since v14
|
|
50
|
+
nodeVersion >= 14 ? req.destroy() : req.abort();
|
|
46
51
|
}
|
|
47
52
|
}, exporterTimeout);
|
|
48
53
|
const options = {
|
|
@@ -54,54 +59,89 @@ export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
|
54
59
|
agent: collector.agent,
|
|
55
60
|
};
|
|
56
61
|
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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) => {
|
|
61
110
|
if (reqIsDestroyed) {
|
|
62
|
-
const err = new OTLPExporterError('Request Timeout');
|
|
111
|
+
const err = new OTLPExporterError('Request Timeout', error.code);
|
|
63
112
|
onError(err);
|
|
64
113
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!reqIsDestroyed) {
|
|
68
|
-
if (res.statusCode && res.statusCode < 299) {
|
|
69
|
-
diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
70
|
-
onSuccess();
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
74
|
-
onError(error);
|
|
75
|
-
}
|
|
76
|
-
clearTimeout(exporterTimer);
|
|
114
|
+
else {
|
|
115
|
+
onError(error);
|
|
77
116
|
}
|
|
117
|
+
clearTimeout(exporterTimer);
|
|
118
|
+
clearTimeout(retryTimer);
|
|
78
119
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
120
|
+
req.on('abort', () => {
|
|
121
|
+
if (reqIsDestroyed) {
|
|
122
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
123
|
+
onError(err);
|
|
124
|
+
}
|
|
86
125
|
clearTimeout(exporterTimer);
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
clearTimeout(retryTimer);
|
|
127
|
+
});
|
|
128
|
+
switch (collector.compression) {
|
|
129
|
+
case CompressionAlgorithm.GZIP: {
|
|
130
|
+
req.setHeader('Content-Encoding', 'gzip');
|
|
131
|
+
const dataStream = readableFromBuffer(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(data);
|
|
141
|
+
break;
|
|
100
142
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
143
|
+
};
|
|
144
|
+
sendWithRetry();
|
|
105
145
|
}
|
|
106
146
|
function readableFromBuffer(buff) {
|
|
107
147
|
const 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;IAE3C,MAAM,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAChD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,cAAuB,CAAC;IAC5B,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CA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AK,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,MAAM,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAChD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;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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, 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"]}
|
package/build/esnext/util.d.ts
CHANGED
|
@@ -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/esnext/util.js
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
import { diag } from '@opentelemetry/api';
|
|
17
17
|
import { getEnv } from '@opentelemetry/core';
|
|
18
18
|
const DEFAULT_TRACE_TIMEOUT = 10000;
|
|
19
|
+
export const DEFAULT_EXPORT_MAX_ATTEMPTS = 5;
|
|
20
|
+
export const DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
|
|
21
|
+
export const DEFAULT_EXPORT_MAX_BACKOFF = 5000;
|
|
22
|
+
export const DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
|
|
19
23
|
/**
|
|
20
24
|
* Parses headers from config leaving only those that have defined values
|
|
21
25
|
* @param partialHeaders
|
|
@@ -95,4 +99,23 @@ export function invalidTimeout(timeout, defaultTimeout) {
|
|
|
95
99
|
diag.warn('Timeout must be greater than 0', timeout);
|
|
96
100
|
return defaultTimeout;
|
|
97
101
|
}
|
|
102
|
+
export function isExportRetryable(statusCode) {
|
|
103
|
+
const retryCodes = [429, 502, 503, 504];
|
|
104
|
+
return retryCodes.includes(statusCode);
|
|
105
|
+
}
|
|
106
|
+
export function parseRetryAfterToMills(retryAfter) {
|
|
107
|
+
if (retryAfter == null) {
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
const seconds = Number.parseInt(retryAfter, 10);
|
|
111
|
+
if (Number.isInteger(seconds)) {
|
|
112
|
+
return seconds > 0 ? seconds * 1000 : -1;
|
|
113
|
+
}
|
|
114
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
|
|
115
|
+
const delay = new Date(retryAfter).getTime() - Date.now();
|
|
116
|
+
if (delay >= 0) {
|
|
117
|
+
return delay;
|
|
118
|
+
}
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
98
121
|
//# sourceMappingURL=util.js.map
|
package/build/esnext/util.js.map
CHANGED
|
@@ -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,MAAM,qBAAqB,GAAG,KAAK,CAAC;
|
|
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,MAAM,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MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC7B,OAAO,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1C;IACD,mFAAmF;IACnF,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE1D,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IACD,OAAO,CAAC,CAAC;AACX,CAAC","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.
|
|
1
|
+
export declare const VERSION = "0.36.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esnext/version.js
CHANGED
|
@@ -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.
|
|
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.36.0';\n"]}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './OTLPExporterBase';
|
|
2
1
|
export * from './platform';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
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
|