@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/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = exports.OTLPExporterError = exports.OTLPExporterBase = void 0;
|
|
13
14
|
/*
|
|
14
15
|
* Copyright The OpenTelemetry Authors
|
|
15
16
|
*
|
|
@@ -25,8 +26,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
26
|
* See the License for the specific language governing permissions and
|
|
26
27
|
* limitations under the License.
|
|
27
28
|
*/
|
|
28
|
-
__exportStar(require("./OTLPExporterBase"), exports);
|
|
29
29
|
__exportStar(require("./platform"), exports);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
var OTLPExporterBase_1 = require("./OTLPExporterBase");
|
|
31
|
+
Object.defineProperty(exports, "OTLPExporterBase", { enumerable: true, get: function () { return OTLPExporterBase_1.OTLPExporterBase; } });
|
|
32
|
+
var types_1 = require("./types");
|
|
33
|
+
Object.defineProperty(exports, "OTLPExporterError", { enumerable: true, get: function () { return types_1.OTLPExporterError; } });
|
|
34
|
+
var util_1 = require("./util");
|
|
35
|
+
Object.defineProperty(exports, "parseHeaders", { enumerable: true, get: function () { return util_1.parseHeaders; } });
|
|
36
|
+
Object.defineProperty(exports, "appendResourcePathToUrl", { enumerable: true, get: function () { return util_1.appendResourcePathToUrl; } });
|
|
37
|
+
Object.defineProperty(exports, "appendRootPathToUrlIfNeeded", { enumerable: true, get: function () { return util_1.appendRootPathToUrlIfNeeded; } });
|
|
38
|
+
Object.defineProperty(exports, "configureExporterTimeout", { enumerable: true, get: function () { return util_1.configureExporterTimeout; } });
|
|
39
|
+
Object.defineProperty(exports, "invalidTimeout", { enumerable: true, get: function () { return util_1.invalidTimeout; } });
|
|
32
40
|
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAA2B;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,iCAIiB;AAHf,0GAAA,iBAAiB,OAAA;AAInB,+BAMgB;AALd,oGAAA,YAAY,OAAA;AACZ,+GAAA,uBAAuB,OAAA;AACvB,mHAAA,2BAA2B,OAAA;AAC3B,gHAAA,wBAAwB,OAAA;AACxB,sGAAA,cAAc,OAAA","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"]}
|
|
@@ -14,16 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
27
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
|
|
18
|
+
exports.sendWithXhr = exports.OTLPExporterBrowserBase = void 0;
|
|
19
|
+
var OTLPExporterBrowserBase_1 = require("./OTLPExporterBrowserBase");
|
|
20
|
+
Object.defineProperty(exports, "OTLPExporterBrowserBase", { enumerable: true, get: function () { return OTLPExporterBrowserBase_1.OTLPExporterBrowserBase; } });
|
|
21
|
+
var util_1 = require("./util");
|
|
22
|
+
Object.defineProperty(exports, "sendWithXhr", { enumerable: true, get: function () { return util_1.sendWithXhr; } });
|
|
29
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,+BAAqC;AAA5B,mGAAA,WAAW,OAAA","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
|
|
@@ -18,6 +18,7 @@ exports.sendWithXhr = exports.sendWithBeacon = void 0;
|
|
|
18
18
|
*/
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const types_1 = require("../../types");
|
|
21
|
+
const util_1 = require("../../util");
|
|
21
22
|
/**
|
|
22
23
|
* Send metrics/spans using browser navigator.sendBeacon
|
|
23
24
|
* @param body
|
|
@@ -47,39 +48,80 @@ exports.sendWithBeacon = sendWithBeacon;
|
|
|
47
48
|
* @param onError
|
|
48
49
|
*/
|
|
49
50
|
function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
50
|
-
let
|
|
51
|
+
let retryTimer;
|
|
52
|
+
let xhr;
|
|
53
|
+
let reqIsDestroyed = false;
|
|
51
54
|
const exporterTimer = setTimeout(() => {
|
|
55
|
+
clearTimeout(retryTimer);
|
|
52
56
|
reqIsDestroyed = true;
|
|
53
|
-
xhr.abort();
|
|
54
|
-
}, exporterTimeout);
|
|
55
|
-
const xhr = new XMLHttpRequest();
|
|
56
|
-
xhr.open('POST', url);
|
|
57
|
-
const defaultHeaders = {
|
|
58
|
-
Accept: 'application/json',
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
};
|
|
61
|
-
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
62
|
-
xhr.setRequestHeader(k, v);
|
|
63
|
-
});
|
|
64
|
-
xhr.send(body);
|
|
65
|
-
xhr.onreadystatechange = () => {
|
|
66
57
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
const err = new types_1.OTLPExporterError('Request Timeout');
|
|
59
|
+
onError(err);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
xhr.abort();
|
|
63
|
+
}
|
|
64
|
+
}, exporterTimeout);
|
|
65
|
+
const sendWithRetry = (retries = util_1.DEFAULT_EXPORT_MAX_ATTEMPTS, minDelay = util_1.DEFAULT_EXPORT_INITIAL_BACKOFF) => {
|
|
66
|
+
xhr = new XMLHttpRequest();
|
|
67
|
+
xhr.open('POST', url);
|
|
68
|
+
const defaultHeaders = {
|
|
69
|
+
Accept: 'application/json',
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
};
|
|
72
|
+
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
73
|
+
xhr.setRequestHeader(k, v);
|
|
74
|
+
});
|
|
75
|
+
xhr.send(body);
|
|
76
|
+
xhr.onreadystatechange = () => {
|
|
77
|
+
if (xhr.readyState === XMLHttpRequest.DONE && reqIsDestroyed === false) {
|
|
78
|
+
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
79
|
+
api_1.diag.debug('xhr success', body);
|
|
80
|
+
onSuccess();
|
|
81
|
+
clearTimeout(exporterTimer);
|
|
82
|
+
clearTimeout(retryTimer);
|
|
83
|
+
}
|
|
84
|
+
else if (xhr.status && (0, util_1.isExportRetryable)(xhr.status) && retries > 0) {
|
|
85
|
+
let retryTime;
|
|
86
|
+
minDelay = util_1.DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
|
|
87
|
+
// retry after interval specified in Retry-After header
|
|
88
|
+
if (xhr.getResponseHeader('Retry-After')) {
|
|
89
|
+
retryTime = (0, util_1.parseRetryAfterToMills)(xhr.getResponseHeader('Retry-After'));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// exponential backoff with jitter
|
|
93
|
+
retryTime = Math.round(Math.random() * (util_1.DEFAULT_EXPORT_MAX_BACKOFF - minDelay) + minDelay);
|
|
94
|
+
}
|
|
95
|
+
retryTimer = setTimeout(() => {
|
|
96
|
+
sendWithRetry(retries - 1, minDelay);
|
|
97
|
+
}, retryTime);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const error = new types_1.OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status);
|
|
101
|
+
onError(error);
|
|
102
|
+
clearTimeout(exporterTimer);
|
|
103
|
+
clearTimeout(retryTimer);
|
|
104
|
+
}
|
|
71
105
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
};
|
|
107
|
+
xhr.onabort = () => {
|
|
108
|
+
if (reqIsDestroyed) {
|
|
109
|
+
const err = new types_1.OTLPExporterError('Request Timeout');
|
|
110
|
+
onError(err);
|
|
75
111
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
clearTimeout(exporterTimer);
|
|
113
|
+
clearTimeout(retryTimer);
|
|
114
|
+
};
|
|
115
|
+
xhr.onerror = () => {
|
|
116
|
+
if (reqIsDestroyed) {
|
|
117
|
+
const err = new types_1.OTLPExporterError('Request Timeout');
|
|
118
|
+
onError(err);
|
|
80
119
|
}
|
|
81
|
-
|
|
120
|
+
clearTimeout(exporterTimer);
|
|
121
|
+
clearTimeout(retryTimer);
|
|
122
|
+
};
|
|
82
123
|
};
|
|
124
|
+
sendWithRetry();
|
|
83
125
|
}
|
|
84
126
|
exports.sendWithXhr = sendWithXhr;
|
|
85
127
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA0C;AAC1C,uCAAgD;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA0C;AAC1C,uCAAgD;AAChD,qCAOoB;AAEpB;;;;;;;GAOG;AACH,SAAgB,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,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,sCAAsC,GAAG,CAAC,MAAM,GAAG,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,GAAG,EAAE;YACjB,IAAI,cAAc,EAAE;gBAClB,MAAM,GAAG,GAAG,IAAI,yBAAiB,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,yBAAiB,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;AAvGD,kCAuGC","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
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.OTLPExporterBrowserBase = void 0;
|
|
14
2
|
/*
|
|
15
3
|
* Copyright The OpenTelemetry Authors
|
|
16
4
|
*
|
|
@@ -26,7 +14,15 @@ exports.OTLPExporterBrowserBase = void 0;
|
|
|
26
14
|
* See the License for the specific language governing permissions and
|
|
27
15
|
* limitations under the License.
|
|
28
16
|
*/
|
|
29
|
-
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.sendWithXhr = exports.OTLPExporterBrowserBase = exports.CompressionAlgorithm = exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp = exports.OTLPExporterNodeBase = void 0;
|
|
19
|
+
var node_1 = require("./node");
|
|
20
|
+
Object.defineProperty(exports, "OTLPExporterNodeBase", { enumerable: true, get: function () { return node_1.OTLPExporterNodeBase; } });
|
|
21
|
+
Object.defineProperty(exports, "sendWithHttp", { enumerable: true, get: function () { return node_1.sendWithHttp; } });
|
|
22
|
+
Object.defineProperty(exports, "createHttpAgent", { enumerable: true, get: function () { return node_1.createHttpAgent; } });
|
|
23
|
+
Object.defineProperty(exports, "configureCompression", { enumerable: true, get: function () { return node_1.configureCompression; } });
|
|
24
|
+
Object.defineProperty(exports, "CompressionAlgorithm", { enumerable: true, get: function () { return node_1.CompressionAlgorithm; } });
|
|
30
25
|
var browser_1 = require("./browser");
|
|
31
26
|
Object.defineProperty(exports, "OTLPExporterBrowserBase", { enumerable: true, get: function () { return browser_1.OTLPExporterBrowserBase; } });
|
|
27
|
+
Object.defineProperty(exports, "sendWithXhr", { enumerable: true, get: function () { return browser_1.sendWithXhr; } });
|
|
32
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAOgB;AANd,4GAAA,oBAAoB,OAAA;AACpB,oGAAA,YAAY,OAAA;AACZ,uGAAA,eAAe,OAAA;AACf,4GAAA,oBAAoB,OAAA;AAEpB,4GAAA,oBAAoB,OAAA;AAEtB,qCAAiE;AAAxD,kHAAA,uBAAuB,OAAA;AAAE,sGAAA,WAAW,OAAA","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
|
|
@@ -14,18 +14,14 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
27
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
exports.CompressionAlgorithm = exports.configureCompression = exports.createHttpAgent = exports.sendWithHttp = exports.OTLPExporterNodeBase = void 0;
|
|
19
|
+
var OTLPExporterNodeBase_1 = require("./OTLPExporterNodeBase");
|
|
20
|
+
Object.defineProperty(exports, "OTLPExporterNodeBase", { enumerable: true, get: function () { return OTLPExporterNodeBase_1.OTLPExporterNodeBase; } });
|
|
21
|
+
var util_1 = require("./util");
|
|
22
|
+
Object.defineProperty(exports, "sendWithHttp", { enumerable: true, get: function () { return util_1.sendWithHttp; } });
|
|
23
|
+
Object.defineProperty(exports, "createHttpAgent", { enumerable: true, get: function () { return util_1.createHttpAgent; } });
|
|
24
|
+
Object.defineProperty(exports, "configureCompression", { enumerable: true, get: function () { return util_1.configureCompression; } });
|
|
25
|
+
var types_1 = require("./types");
|
|
26
|
+
Object.defineProperty(exports, "CompressionAlgorithm", { enumerable: true, get: function () { return types_1.CompressionAlgorithm; } });
|
|
31
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,+BAA6E;AAApE,oGAAA,YAAY,OAAA;AAAE,uGAAA,eAAe,OAAA;AAAE,4GAAA,oBAAoB,OAAA;AAC5D,iCAA2E;AAAtC,6GAAA,oBAAoB,OAAA","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"]}
|
|
@@ -25,6 +25,7 @@ const api_1 = require("@opentelemetry/api");
|
|
|
25
25
|
const types_1 = require("./types");
|
|
26
26
|
const core_1 = require("@opentelemetry/core");
|
|
27
27
|
const types_2 = require("../../types");
|
|
28
|
+
const util_1 = require("../../util");
|
|
28
29
|
/**
|
|
29
30
|
* Sends data using http
|
|
30
31
|
* @param collector
|
|
@@ -36,16 +37,20 @@ const types_2 = require("../../types");
|
|
|
36
37
|
function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
37
38
|
const exporterTimeout = collector.timeoutMillis;
|
|
38
39
|
const parsedUrl = new url.URL(collector.url);
|
|
39
|
-
let reqIsDestroyed;
|
|
40
40
|
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
41
|
+
let retryTimer;
|
|
42
|
+
let req;
|
|
43
|
+
let reqIsDestroyed = false;
|
|
41
44
|
const exporterTimer = setTimeout(() => {
|
|
45
|
+
clearTimeout(retryTimer);
|
|
42
46
|
reqIsDestroyed = true;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
if (req.destroyed) {
|
|
48
|
+
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
49
|
+
onError(err);
|
|
46
50
|
}
|
|
47
51
|
else {
|
|
48
|
-
req.abort()
|
|
52
|
+
// req.abort() was deprecated since v14
|
|
53
|
+
nodeVersion >= 14 ? req.destroy() : req.abort();
|
|
49
54
|
}
|
|
50
55
|
}, exporterTimeout);
|
|
51
56
|
const options = {
|
|
@@ -57,54 +62,89 @@ function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
|
57
62
|
agent: collector.agent,
|
|
58
63
|
};
|
|
59
64
|
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
const sendWithRetry = (retries = util_1.DEFAULT_EXPORT_MAX_ATTEMPTS, minDelay = util_1.DEFAULT_EXPORT_INITIAL_BACKOFF) => {
|
|
66
|
+
req = request(options, (res) => {
|
|
67
|
+
let responseData = '';
|
|
68
|
+
res.on('data', chunk => (responseData += chunk));
|
|
69
|
+
res.on('aborted', () => {
|
|
70
|
+
if (reqIsDestroyed) {
|
|
71
|
+
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
72
|
+
onError(err);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
res.on('end', () => {
|
|
76
|
+
if (reqIsDestroyed === false) {
|
|
77
|
+
if (res.statusCode && res.statusCode < 299) {
|
|
78
|
+
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
79
|
+
onSuccess();
|
|
80
|
+
// clear all timers since request was completed and promise was resolved
|
|
81
|
+
clearTimeout(exporterTimer);
|
|
82
|
+
clearTimeout(retryTimer);
|
|
83
|
+
}
|
|
84
|
+
else if (res.statusCode &&
|
|
85
|
+
(0, util_1.isExportRetryable)(res.statusCode) &&
|
|
86
|
+
retries > 0) {
|
|
87
|
+
let retryTime;
|
|
88
|
+
minDelay = util_1.DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
|
|
89
|
+
// retry after interval specified in Retry-After header
|
|
90
|
+
if (res.headers['retry-after']) {
|
|
91
|
+
retryTime = (0, util_1.parseRetryAfterToMills)(res.headers['retry-after']);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// exponential backoff with jitter
|
|
95
|
+
retryTime = Math.round(Math.random() * (util_1.DEFAULT_EXPORT_MAX_BACKOFF - minDelay) +
|
|
96
|
+
minDelay);
|
|
97
|
+
}
|
|
98
|
+
retryTimer = setTimeout(() => {
|
|
99
|
+
sendWithRetry(retries - 1, minDelay);
|
|
100
|
+
}, retryTime);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
104
|
+
onError(error);
|
|
105
|
+
// clear all timers since request was completed and promise was resolved
|
|
106
|
+
clearTimeout(exporterTimer);
|
|
107
|
+
clearTimeout(retryTimer);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
req.on('error', (error) => {
|
|
64
113
|
if (reqIsDestroyed) {
|
|
65
|
-
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
114
|
+
const err = new types_2.OTLPExporterError('Request Timeout', error.code);
|
|
66
115
|
onError(err);
|
|
67
116
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!reqIsDestroyed) {
|
|
71
|
-
if (res.statusCode && res.statusCode < 299) {
|
|
72
|
-
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
73
|
-
onSuccess();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
77
|
-
onError(error);
|
|
78
|
-
}
|
|
79
|
-
clearTimeout(exporterTimer);
|
|
117
|
+
else {
|
|
118
|
+
onError(error);
|
|
80
119
|
}
|
|
120
|
+
clearTimeout(exporterTimer);
|
|
121
|
+
clearTimeout(retryTimer);
|
|
81
122
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
123
|
+
req.on('abort', () => {
|
|
124
|
+
if (reqIsDestroyed) {
|
|
125
|
+
const err = new types_2.OTLPExporterError('Request Timeout');
|
|
126
|
+
onError(err);
|
|
127
|
+
}
|
|
89
128
|
clearTimeout(exporterTimer);
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
clearTimeout(retryTimer);
|
|
130
|
+
});
|
|
131
|
+
switch (collector.compression) {
|
|
132
|
+
case types_1.CompressionAlgorithm.GZIP: {
|
|
133
|
+
req.setHeader('Content-Encoding', 'gzip');
|
|
134
|
+
const dataStream = readableFromBuffer(data);
|
|
135
|
+
dataStream
|
|
136
|
+
.on('error', onError)
|
|
137
|
+
.pipe(zlib.createGzip())
|
|
138
|
+
.on('error', onError)
|
|
139
|
+
.pipe(req);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
default:
|
|
143
|
+
req.end(data);
|
|
144
|
+
break;
|
|
103
145
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
146
|
+
};
|
|
147
|
+
sendWithRetry();
|
|
108
148
|
}
|
|
109
149
|
exports.sendWithHttp = sendWithHttp;
|
|
110
150
|
function readableFromBuff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AAC,GAAa,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;QACxE,OAAO,IAAI,KAAK,iBAAG,SAAS,EAAE,IAAI,IAAK,MAAM,CAAC,gBAAgB,EAAG,CAAC;KACnE;IAAC,OAAO,GAAG,EAAE;QACZ,UAAI,CAAC,KAAK,CACR,wDAAwD,GAAG,CAAC,OAAO,EAAE,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AApBD,0CAoBC;AAED,SAAgB,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,IAAA,aAAM,GAAE,CAAC,qCAAqC;YAC9C,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,4BAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,4BAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC;AAbD,oDAaC","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,2BAA2B;AAC3B,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAAkC;AAGlC,4CAA0C;AAC1C,mCAA+C;AAC/C,8CAA6C;AAC7C,uCAAgD;AAChD,qCAOoB;AAEpB;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IAE3C,MAAM,eAAe,GAAG,SAAS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,CAAC,KAAK,CAAC,KAAK,CAAC;QACxE,OAAO,IAAI,KAAK,iBAAG,SAAS,EAAE,IAAI,IAAK,MAAM,CAAC,gBAAgB,EAAG,CAAC;KACnE;IAAC,OAAO,GAAG,EAAE;QACZ,UAAI,CAAC,KAAK,CACR,wDAAwD,GAAG,CAAC,OAAO,EAAE,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AApBD,0CAoBC;AAED,SAAgB,oBAAoB,CAClC,WAA6C;IAE7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GACtB,IAAA,aAAM,GAAE,CAAC,qCAAqC;YAC9C,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QAC1C,OAAO,kBAAkB,KAAK,4BAAoB,CAAC,IAAI;YACrD,CAAC,CAAC,4BAAoB,CAAC,IAAI;YAC3B,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC;AAbD,oDAaC","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/src/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/src/util.js
CHANGED
|
@@ -15,10 +15,14 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = void 0;
|
|
18
|
+
exports.parseRetryAfterToMills = exports.isExportRetryable = exports.invalidTimeout = exports.configureExporterTimeout = exports.appendRootPathToUrlIfNeeded = exports.appendResourcePathToUrl = exports.parseHeaders = exports.DEFAULT_EXPORT_BACKOFF_MULTIPLIER = exports.DEFAULT_EXPORT_MAX_BACKOFF = exports.DEFAULT_EXPORT_INITIAL_BACKOFF = exports.DEFAULT_EXPORT_MAX_ATTEMPTS = void 0;
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const core_1 = require("@opentelemetry/core");
|
|
21
21
|
const DEFAULT_TRACE_TIMEOUT = 10000;
|
|
22
|
+
exports.DEFAULT_EXPORT_MAX_ATTEMPTS = 5;
|
|
23
|
+
exports.DEFAULT_EXPORT_INITIAL_BACKOFF = 1000;
|
|
24
|
+
exports.DEFAULT_EXPORT_MAX_BACKOFF = 5000;
|
|
25
|
+
exports.DEFAULT_EXPORT_BACKOFF_MULTIPLIER = 1.5;
|
|
22
26
|
/**
|
|
23
27
|
* Parses headers from config leaving only those that have defined values
|
|
24
28
|
* @param partialHeaders
|
|
@@ -103,4 +107,25 @@ function invalidTimeout(timeout, defaultTimeout) {
|
|
|
103
107
|
return defaultTimeout;
|
|
104
108
|
}
|
|
105
109
|
exports.invalidTimeout = invalidTimeout;
|
|
110
|
+
function isExportRetryable(statusCode) {
|
|
111
|
+
const retryCodes = [429, 502, 503, 504];
|
|
112
|
+
return retryCodes.includes(statusCode);
|
|
113
|
+
}
|
|
114
|
+
exports.isExportRetryable = isExportRetryable;
|
|
115
|
+
function parseRetryAfterToMills(retryAfter) {
|
|
116
|
+
if (retryAfter == null) {
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
const seconds = Number.parseInt(retryAfter, 10);
|
|
120
|
+
if (Number.isInteger(seconds)) {
|
|
121
|
+
return seconds > 0 ? seconds * 1000 : -1;
|
|
122
|
+
}
|
|
123
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#directives
|
|
124
|
+
const delay = new Date(retryAfter).getTime() - Date.now();
|
|
125
|
+
if (delay >= 0) {
|
|
126
|
+
return delay;
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
exports.parseRetryAfterToMills = parseRetryAfterToMills;
|
|
106
131
|
//# sourceMappingURL=util.js.map
|