@opentelemetry/otlp-exporter-base 0.52.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/esm/OTLPExporterBase.d.ts +3 -0
- package/build/esm/OTLPExporterBase.js.map +1 -1
- package/build/esm/export-response.d.ts +14 -0
- package/build/esm/export-response.js +17 -0
- package/build/esm/export-response.js.map +1 -0
- package/build/esm/exporter-transport.d.ts +6 -0
- package/build/esm/exporter-transport.js +17 -0
- package/build/esm/exporter-transport.js.map +1 -0
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/is-export-retryable.d.ts +3 -0
- package/build/esm/is-export-retryable.js +35 -0
- package/build/esm/is-export-retryable.js.map +1 -0
- package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js +36 -27
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/esm/platform/browser/index.d.ts +0 -1
- package/build/esm/platform/browser/index.js +0 -1
- package/build/esm/platform/browser/index.js.map +1 -1
- package/build/esm/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/esm/platform/browser/send-beacon-transport.js +47 -0
- package/build/esm/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/esm/platform/browser/xhr-transport.d.ts +11 -0
- package/build/esm/platform/browser/xhr-transport.js +101 -0
- package/build/esm/platform/browser/xhr-transport.js.map +1 -0
- 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/OTLPExporterNodeBase.d.ts +5 -12
- package/build/esm/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/esm/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/esm/platform/node/http-exporter-transport.js +87 -0
- package/build/esm/platform/node/http-exporter-transport.js.map +1 -0
- package/build/esm/platform/node/http-transport-types.d.ts +12 -0
- package/build/esm/platform/node/http-transport-types.js +17 -0
- package/build/esm/platform/node/http-transport-types.js.map +1 -0
- package/build/esm/platform/node/http-transport-utils.d.ts +16 -0
- package/build/esm/platform/node/http-transport-utils.js +127 -0
- package/build/esm/platform/node/http-transport-utils.js.map +1 -0
- package/build/esm/platform/node/index.d.ts +0 -1
- package/build/esm/platform/node/index.js +0 -1
- package/build/esm/platform/node/index.js.map +1 -1
- package/build/esm/platform/node/util.d.ts +0 -16
- package/build/esm/platform/node/util.js +0 -164
- package/build/esm/platform/node/util.js.map +1 -1
- package/build/esm/retrying-transport.d.ts +8 -0
- package/build/esm/retrying-transport.js +119 -0
- package/build/esm/retrying-transport.js.map +1 -0
- 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/OTLPExporterBase.d.ts +3 -0
- package/build/esnext/OTLPExporterBase.js.map +1 -1
- package/build/esnext/export-response.d.ts +14 -0
- package/build/esnext/export-response.js +17 -0
- package/build/esnext/export-response.js.map +1 -0
- package/build/esnext/exporter-transport.d.ts +6 -0
- package/build/esnext/exporter-transport.js +17 -0
- package/build/esnext/exporter-transport.js.map +1 -0
- package/build/esnext/index.d.ts +2 -0
- package/build/esnext/index.js +3 -0
- package/build/esnext/index.js.map +1 -1
- package/build/esnext/is-export-retryable.d.ts +3 -0
- package/build/esnext/is-export-retryable.js +35 -0
- package/build/esnext/is-export-retryable.js.map +1 -0
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +36 -16
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/esnext/platform/browser/index.d.ts +0 -1
- package/build/esnext/platform/browser/index.js +0 -1
- package/build/esnext/platform/browser/index.js.map +1 -1
- package/build/esnext/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/esnext/platform/browser/send-beacon-transport.js +45 -0
- package/build/esnext/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/esnext/platform/browser/xhr-transport.d.ts +11 -0
- package/build/esnext/platform/browser/xhr-transport.js +82 -0
- package/build/esnext/platform/browser/xhr-transport.js.map +1 -0
- 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/OTLPExporterNodeBase.d.ts +5 -12
- package/build/esnext/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/esnext/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/esnext/platform/node/http-exporter-transport.js +47 -0
- package/build/esnext/platform/node/http-exporter-transport.js.map +1 -0
- package/build/esnext/platform/node/http-transport-types.d.ts +12 -0
- package/build/esnext/platform/node/http-transport-types.js +17 -0
- package/build/esnext/platform/node/http-transport-types.js.map +1 -0
- package/build/esnext/platform/node/http-transport-utils.d.ts +16 -0
- package/build/esnext/platform/node/http-transport-utils.js +116 -0
- package/build/esnext/platform/node/http-transport-utils.js.map +1 -0
- package/build/esnext/platform/node/index.d.ts +0 -1
- package/build/esnext/platform/node/index.js +0 -1
- package/build/esnext/platform/node/index.js.map +1 -1
- package/build/esnext/platform/node/util.d.ts +0 -16
- package/build/esnext/platform/node/util.js +0 -151
- package/build/esnext/platform/node/util.js.map +1 -1
- package/build/esnext/retrying-transport.d.ts +8 -0
- package/build/esnext/retrying-transport.js +69 -0
- package/build/esnext/retrying-transport.js.map +1 -0
- 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/OTLPExporterBase.d.ts +3 -0
- package/build/src/OTLPExporterBase.js.map +1 -1
- package/build/src/export-response.d.ts +14 -0
- package/build/src/export-response.js +18 -0
- package/build/src/export-response.js.map +1 -0
- package/build/src/exporter-transport.d.ts +6 -0
- package/build/src/exporter-transport.js +18 -0
- package/build/src/exporter-transport.js.map +1 -0
- package/build/src/index.d.ts +2 -0
- package/build/src/index.js +15 -12
- package/build/src/index.js.map +1 -1
- package/build/src/is-export-retryable.d.ts +3 -0
- package/build/src/is-export-retryable.js +40 -0
- package/build/src/is-export-retryable.js.map +1 -0
- package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
- package/build/src/platform/browser/OTLPExporterBrowserBase.js +36 -16
- package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/src/platform/browser/index.d.ts +0 -1
- package/build/src/platform/browser/index.js +1 -3
- package/build/src/platform/browser/index.js.map +1 -1
- package/build/src/platform/browser/send-beacon-transport.d.ts +10 -0
- package/build/src/platform/browser/send-beacon-transport.js +49 -0
- package/build/src/platform/browser/send-beacon-transport.js.map +1 -0
- package/build/src/platform/browser/xhr-transport.d.ts +11 -0
- package/build/src/platform/browser/xhr-transport.js +86 -0
- package/build/src/platform/browser/xhr-transport.js.map +1 -0
- package/build/src/platform/index.d.ts +2 -2
- package/build/src/platform/index.js +1 -5
- package/build/src/platform/index.js.map +1 -1
- package/build/src/platform/node/OTLPExporterNodeBase.d.ts +5 -12
- package/build/src/platform/node/OTLPExporterNodeBase.js +52 -12
- package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -1
- package/build/src/platform/node/http-exporter-transport.d.ts +4 -0
- package/build/src/platform/node/http-exporter-transport.js +51 -0
- package/build/src/platform/node/http-exporter-transport.js.map +1 -0
- package/build/src/platform/node/http-transport-types.d.ts +12 -0
- package/build/src/platform/node/http-transport-types.js +18 -0
- package/build/src/platform/node/http-transport-types.js.map +1 -0
- package/build/src/platform/node/http-transport-utils.d.ts +16 -0
- package/build/src/platform/node/http-transport-utils.js +121 -0
- package/build/src/platform/node/http-transport-utils.js.map +1 -0
- package/build/src/platform/node/index.d.ts +0 -1
- package/build/src/platform/node/index.js +1 -5
- package/build/src/platform/node/index.js.map +1 -1
- package/build/src/platform/node/util.d.ts +0 -16
- package/build/src/platform/node/util.js +2 -155
- package/build/src/platform/node/util.js.map +1 -1
- package/build/src/retrying-transport.d.ts +8 -0
- package/build/src/retrying-transport.js +73 -0
- package/build/src/retrying-transport.js.map +1 -0
- 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 +11 -12
- package/build/esm/platform/browser/util.d.ts +0 -21
- package/build/esm/platform/browser/util.js +0 -152
- package/build/esm/platform/browser/util.js.map +0 -1
- package/build/esnext/platform/browser/util.d.ts +0 -21
- package/build/esnext/platform/browser/util.js +0 -122
- package/build/esnext/platform/browser/util.js.map +0 -1
- package/build/src/platform/browser/util.d.ts +0 -21
- package/build/src/platform/browser/util.js +0 -127
- package/build/src/platform/browser/util.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrying-transport.js","sourceRoot":"","sources":["../../src/retrying-transport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKH,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,MAAM,GAAG,GAAG,CAAC;AAEnB;;GAEG;AACH,SAAS,SAAS;IAChB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AAC/C,CAAC;AAED,MAAM,iBAAiB;IACrB,YAAoB,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IAAG,CAAC;IAE9C,KAAK,CACX,IAAgB,EAChB,aAAqB,EACrB,QAAgB;QAEhB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,E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AAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AALD,0DAKC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { IExporterTransport } from './exporter-transport';\nimport { ExportResponse } from './export-response';\n\nconst MAX_ATTEMPTS = 5;\nconst INITIAL_BACKOFF = 1000;\nconst MAX_BACKOFF = 5000;\nconst BACKOFF_MULTIPLIER = 1.5;\nconst JITTER = 0.2;\n\n/**\n * Get a pseudo-random jitter that falls in the range of [-JITTER, +JITTER]\n */\nfunction getJitter() {\n return Math.random() * (2 * JITTER) - JITTER;\n}\n\nclass RetryingTransport implements IExporterTransport {\n constructor(private _transport: IExporterTransport) {}\n\n private retry(\n data: Uint8Array,\n timeoutMillis: number,\n inMillis: number\n ): Promise<ExportResponse> {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n this._transport.send(data, timeoutMillis).then(resolve, reject);\n }, inMillis);\n });\n }\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n const deadline = Date.now() + timeoutMillis;\n let result = await this._transport.send(data, timeoutMillis);\n let attempts = MAX_ATTEMPTS;\n let nextBackoff = INITIAL_BACKOFF;\n\n while (result.status === 'retryable' && attempts > 0) {\n attempts--;\n\n // use maximum of computed backoff and 0 to avoid negative timeouts\n const backoff = Math.max(\n Math.min(nextBackoff, MAX_BACKOFF) + getJitter(),\n 0\n );\n nextBackoff = nextBackoff * BACKOFF_MULTIPLIER;\n const retryInMillis = result.retryInMillis ?? backoff;\n\n // return when expected retry time is after the export deadline.\n const remainingTimeoutMillis = deadline - Date.now();\n if (retryInMillis > remainingTimeoutMillis) {\n return result;\n }\n\n result = await this.retry(data, remainingTimeoutMillis, retryInMillis);\n }\n\n return result;\n }\n\n shutdown() {\n return this._transport.shutdown();\n }\n}\n\n/**\n * Creates an Exporter Transport that retries on 'retryable' response.\n */\nexport function createRetryingTransport(options: {\n // Underlying transport to wrap.\n transport: IExporterTransport;\n}): IExporterTransport {\n return new RetryingTransport(options.transport);\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.53.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,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;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.53.0';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/otlp-exporter-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "OpenTelemetry OTLP Exporter base (for internal use only)",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
24
24
|
"tdd": "npm run test -- --watch-extensions ts --watch",
|
|
25
25
|
"tdd:browser": "karma start",
|
|
26
|
-
"test": "nyc
|
|
26
|
+
"test": "nyc mocha 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'",
|
|
27
27
|
"test:browser": "karma start --single-run",
|
|
28
28
|
"version": "node ../../../scripts/version-update.js",
|
|
29
29
|
"watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
|
|
@@ -62,31 +62,30 @@
|
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@opentelemetry/core": "1.
|
|
66
|
-
"@opentelemetry/otlp-transformer": "0.
|
|
65
|
+
"@opentelemetry/core": "1.26.0",
|
|
66
|
+
"@opentelemetry/otlp-transformer": "0.53.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@babel/core": "7.
|
|
70
|
-
"@babel/preset-env": "7.
|
|
69
|
+
"@babel/core": "7.25.2",
|
|
70
|
+
"@babel/preset-env": "7.25.3",
|
|
71
71
|
"@opentelemetry/api": "1.9.0",
|
|
72
|
-
"@types/mocha": "10.0.
|
|
72
|
+
"@types/mocha": "10.0.7",
|
|
73
73
|
"@types/node": "18.6.5",
|
|
74
74
|
"@types/sinon": "17.0.3",
|
|
75
|
-
"babel-plugin-istanbul": "
|
|
75
|
+
"babel-plugin-istanbul": "7.0.0",
|
|
76
76
|
"codecov": "3.8.3",
|
|
77
77
|
"cross-var": "1.1.0",
|
|
78
|
-
"karma": "6.4.
|
|
78
|
+
"karma": "6.4.4",
|
|
79
79
|
"karma-chrome-launcher": "3.1.0",
|
|
80
80
|
"karma-coverage": "2.2.1",
|
|
81
81
|
"karma-mocha": "2.0.1",
|
|
82
82
|
"karma-spec-reporter": "0.0.36",
|
|
83
83
|
"karma-webpack": "5.0.1",
|
|
84
84
|
"lerna": "6.6.2",
|
|
85
|
-
"mocha": "10.
|
|
85
|
+
"mocha": "10.7.3",
|
|
86
86
|
"nyc": "15.1.0",
|
|
87
87
|
"sinon": "15.1.2",
|
|
88
88
|
"ts-loader": "9.5.1",
|
|
89
|
-
"ts-mocha": "10.0.0",
|
|
90
89
|
"typescript": "4.4.4",
|
|
91
90
|
"webpack": "5.89.0",
|
|
92
91
|
"webpack-cli": "5.1.4",
|
|
@@ -97,5 +96,5 @@
|
|
|
97
96
|
},
|
|
98
97
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-exporter-base",
|
|
99
98
|
"sideEffects": false,
|
|
100
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "720bc8c70d47029cb6b41a34ffdc3d25cbaa2f80"
|
|
101
100
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { OTLPExporterError } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
4
|
-
* @param body
|
|
5
|
-
* @param url
|
|
6
|
-
* @param blobPropertyBag
|
|
7
|
-
* @param onSuccess
|
|
8
|
-
* @param onError
|
|
9
|
-
*/
|
|
10
|
-
export declare function sendWithBeacon(body: Uint8Array, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
11
|
-
/**
|
|
12
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
13
|
-
* used when navigator.sendBeacon is not available
|
|
14
|
-
* @param body
|
|
15
|
-
* @param url
|
|
16
|
-
* @param headers
|
|
17
|
-
* @param onSuccess
|
|
18
|
-
* @param onError
|
|
19
|
-
*/
|
|
20
|
-
export declare function sendWithXhr(body: Uint8Array, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
21
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
-
if (!m) return o;
|
|
15
|
-
var i = m.call(o), r, ar = [], e;
|
|
16
|
-
try {
|
|
17
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
-
}
|
|
19
|
-
catch (error) { e = { error: error }; }
|
|
20
|
-
finally {
|
|
21
|
-
try {
|
|
22
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
-
}
|
|
24
|
-
finally { if (e) throw e.error; }
|
|
25
|
-
}
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
/*
|
|
29
|
-
* Copyright The OpenTelemetry Authors
|
|
30
|
-
*
|
|
31
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
-
* you may not use this file except in compliance with the License.
|
|
33
|
-
* You may obtain a copy of the License at
|
|
34
|
-
*
|
|
35
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
-
*
|
|
37
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
38
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
-
* See the License for the specific language governing permissions and
|
|
41
|
-
* limitations under the License.
|
|
42
|
-
*/
|
|
43
|
-
import { diag } from '@opentelemetry/api';
|
|
44
|
-
import { OTLPExporterError } from '../../types';
|
|
45
|
-
import { DEFAULT_EXPORT_MAX_ATTEMPTS, DEFAULT_EXPORT_INITIAL_BACKOFF, DEFAULT_EXPORT_BACKOFF_MULTIPLIER, DEFAULT_EXPORT_MAX_BACKOFF, isExportRetryable, parseRetryAfterToMills, } from '../../util';
|
|
46
|
-
/**
|
|
47
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
48
|
-
* @param body
|
|
49
|
-
* @param url
|
|
50
|
-
* @param blobPropertyBag
|
|
51
|
-
* @param onSuccess
|
|
52
|
-
* @param onError
|
|
53
|
-
*/
|
|
54
|
-
export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
55
|
-
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
56
|
-
diag.debug('sendBeacon - can send', body);
|
|
57
|
-
onSuccess();
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
var error = new OTLPExporterError("sendBeacon - cannot send " + body);
|
|
61
|
-
onError(error);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
66
|
-
* used when navigator.sendBeacon is not available
|
|
67
|
-
* @param body
|
|
68
|
-
* @param url
|
|
69
|
-
* @param headers
|
|
70
|
-
* @param onSuccess
|
|
71
|
-
* @param onError
|
|
72
|
-
*/
|
|
73
|
-
export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
74
|
-
var retryTimer;
|
|
75
|
-
var xhr;
|
|
76
|
-
var reqIsDestroyed = false;
|
|
77
|
-
var exporterTimer = setTimeout(function () {
|
|
78
|
-
clearTimeout(retryTimer);
|
|
79
|
-
reqIsDestroyed = true;
|
|
80
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
81
|
-
var err = new OTLPExporterError('Request Timeout');
|
|
82
|
-
onError(err);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
xhr.abort();
|
|
86
|
-
}
|
|
87
|
-
}, exporterTimeout);
|
|
88
|
-
var sendWithRetry = function (retries, minDelay) {
|
|
89
|
-
if (retries === void 0) { retries = DEFAULT_EXPORT_MAX_ATTEMPTS; }
|
|
90
|
-
if (minDelay === void 0) { minDelay = DEFAULT_EXPORT_INITIAL_BACKOFF; }
|
|
91
|
-
xhr = new XMLHttpRequest();
|
|
92
|
-
xhr.open('POST', url);
|
|
93
|
-
var defaultHeaders = {
|
|
94
|
-
Accept: 'application/json',
|
|
95
|
-
'Content-Type': 'application/json',
|
|
96
|
-
};
|
|
97
|
-
Object.entries(__assign(__assign({}, defaultHeaders), headers)).forEach(function (_a) {
|
|
98
|
-
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
99
|
-
xhr.setRequestHeader(k, v);
|
|
100
|
-
});
|
|
101
|
-
xhr.send(body);
|
|
102
|
-
xhr.onreadystatechange = function () {
|
|
103
|
-
if (xhr.readyState === XMLHttpRequest.DONE && reqIsDestroyed === false) {
|
|
104
|
-
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
105
|
-
diag.debug('xhr success', body);
|
|
106
|
-
onSuccess();
|
|
107
|
-
clearTimeout(exporterTimer);
|
|
108
|
-
clearTimeout(retryTimer);
|
|
109
|
-
}
|
|
110
|
-
else if (xhr.status && isExportRetryable(xhr.status) && retries > 0) {
|
|
111
|
-
var retryTime = void 0;
|
|
112
|
-
minDelay = DEFAULT_EXPORT_BACKOFF_MULTIPLIER * minDelay;
|
|
113
|
-
// retry after interval specified in Retry-After header
|
|
114
|
-
if (xhr.getResponseHeader('Retry-After')) {
|
|
115
|
-
retryTime = parseRetryAfterToMills(xhr.getResponseHeader('Retry-After'));
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// exponential backoff with jitter
|
|
119
|
-
retryTime = Math.round(Math.random() * (DEFAULT_EXPORT_MAX_BACKOFF - minDelay) + minDelay);
|
|
120
|
-
}
|
|
121
|
-
retryTimer = setTimeout(function () {
|
|
122
|
-
sendWithRetry(retries - 1, minDelay);
|
|
123
|
-
}, retryTime);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
var error = new OTLPExporterError("Failed to export with XHR (status: " + xhr.status + ")", xhr.status);
|
|
127
|
-
onError(error);
|
|
128
|
-
clearTimeout(exporterTimer);
|
|
129
|
-
clearTimeout(retryTimer);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
xhr.onabort = function () {
|
|
134
|
-
if (reqIsDestroyed) {
|
|
135
|
-
var err = new OTLPExporterError('Request Timeout');
|
|
136
|
-
onError(err);
|
|
137
|
-
}
|
|
138
|
-
clearTimeout(exporterTimer);
|
|
139
|
-
clearTimeout(retryTimer);
|
|
140
|
-
};
|
|
141
|
-
xhr.onerror = function () {
|
|
142
|
-
if (reqIsDestroyed) {
|
|
143
|
-
var err = new OTLPExporterError('Request Timeout');
|
|
144
|
-
onError(err);
|
|
145
|
-
}
|
|
146
|
-
clearTimeout(exporterTimer);
|
|
147
|
-
clearTimeout(retryTimer);
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
sendWithRetry();
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
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C,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: Uint8Array,\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: Uint8Array,\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,21 +0,0 @@
|
|
|
1
|
-
import { OTLPExporterError } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
4
|
-
* @param body
|
|
5
|
-
* @param url
|
|
6
|
-
* @param blobPropertyBag
|
|
7
|
-
* @param onSuccess
|
|
8
|
-
* @param onError
|
|
9
|
-
*/
|
|
10
|
-
export declare function sendWithBeacon(body: Uint8Array, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
11
|
-
/**
|
|
12
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
13
|
-
* used when navigator.sendBeacon is not available
|
|
14
|
-
* @param body
|
|
15
|
-
* @param url
|
|
16
|
-
* @param headers
|
|
17
|
-
* @param onSuccess
|
|
18
|
-
* @param onError
|
|
19
|
-
*/
|
|
20
|
-
export declare function sendWithXhr(body: Uint8Array, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
21
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright The OpenTelemetry Authors
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { diag } from '@opentelemetry/api';
|
|
17
|
-
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';
|
|
19
|
-
/**
|
|
20
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
21
|
-
* @param body
|
|
22
|
-
* @param url
|
|
23
|
-
* @param blobPropertyBag
|
|
24
|
-
* @param onSuccess
|
|
25
|
-
* @param onError
|
|
26
|
-
*/
|
|
27
|
-
export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
28
|
-
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
29
|
-
diag.debug('sendBeacon - can send', body);
|
|
30
|
-
onSuccess();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const error = new OTLPExporterError(`sendBeacon - cannot send ${body}`);
|
|
34
|
-
onError(error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
39
|
-
* used when navigator.sendBeacon is not available
|
|
40
|
-
* @param body
|
|
41
|
-
* @param url
|
|
42
|
-
* @param headers
|
|
43
|
-
* @param onSuccess
|
|
44
|
-
* @param onError
|
|
45
|
-
*/
|
|
46
|
-
export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
47
|
-
let retryTimer;
|
|
48
|
-
let xhr;
|
|
49
|
-
let reqIsDestroyed = false;
|
|
50
|
-
const exporterTimer = setTimeout(() => {
|
|
51
|
-
clearTimeout(retryTimer);
|
|
52
|
-
reqIsDestroyed = true;
|
|
53
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
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
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
xhr.onabort = () => {
|
|
104
|
-
if (reqIsDestroyed) {
|
|
105
|
-
const err = new OTLPExporterError('Request Timeout');
|
|
106
|
-
onError(err);
|
|
107
|
-
}
|
|
108
|
-
clearTimeout(exporterTimer);
|
|
109
|
-
clearTimeout(retryTimer);
|
|
110
|
-
};
|
|
111
|
-
xhr.onerror = () => {
|
|
112
|
-
if (reqIsDestroyed) {
|
|
113
|
-
const err = new OTLPExporterError('Request Timeout');
|
|
114
|
-
onError(err);
|
|
115
|
-
}
|
|
116
|
-
clearTimeout(exporterTimer);
|
|
117
|
-
clearTimeout(retryTimer);
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
sendWithRetry();
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAgB,EAChB,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAA2C;IAE3C,IAAI,SAAS,CAAC,UAAU,C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qBAAM;oBACL,MAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,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,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: Uint8Array,\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: Uint8Array,\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,21 +0,0 @@
|
|
|
1
|
-
import { OTLPExporterError } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
4
|
-
* @param body
|
|
5
|
-
* @param url
|
|
6
|
-
* @param blobPropertyBag
|
|
7
|
-
* @param onSuccess
|
|
8
|
-
* @param onError
|
|
9
|
-
*/
|
|
10
|
-
export declare function sendWithBeacon(body: Uint8Array, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
11
|
-
/**
|
|
12
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
13
|
-
* used when navigator.sendBeacon is not available
|
|
14
|
-
* @param body
|
|
15
|
-
* @param url
|
|
16
|
-
* @param headers
|
|
17
|
-
* @param onSuccess
|
|
18
|
-
* @param onError
|
|
19
|
-
*/
|
|
20
|
-
export declare function sendWithXhr(body: Uint8Array, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
21
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendWithXhr = exports.sendWithBeacon = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright The OpenTelemetry Authors
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
const api_1 = require("@opentelemetry/api");
|
|
20
|
-
const types_1 = require("../../types");
|
|
21
|
-
const util_1 = require("../../util");
|
|
22
|
-
/**
|
|
23
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
24
|
-
* @param body
|
|
25
|
-
* @param url
|
|
26
|
-
* @param blobPropertyBag
|
|
27
|
-
* @param onSuccess
|
|
28
|
-
* @param onError
|
|
29
|
-
*/
|
|
30
|
-
function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
31
|
-
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
32
|
-
api_1.diag.debug('sendBeacon - can send', body);
|
|
33
|
-
onSuccess();
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const error = new types_1.OTLPExporterError(`sendBeacon - cannot send ${body}`);
|
|
37
|
-
onError(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.sendWithBeacon = sendWithBeacon;
|
|
41
|
-
/**
|
|
42
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
43
|
-
* used when navigator.sendBeacon is not available
|
|
44
|
-
* @param body
|
|
45
|
-
* @param url
|
|
46
|
-
* @param headers
|
|
47
|
-
* @param onSuccess
|
|
48
|
-
* @param onError
|
|
49
|
-
*/
|
|
50
|
-
function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
51
|
-
let retryTimer;
|
|
52
|
-
let xhr;
|
|
53
|
-
let reqIsDestroyed = false;
|
|
54
|
-
const exporterTimer = setTimeout(() => {
|
|
55
|
-
clearTimeout(retryTimer);
|
|
56
|
-
reqIsDestroyed = true;
|
|
57
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
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
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
xhr.onabort = () => {
|
|
108
|
-
if (reqIsDestroyed) {
|
|
109
|
-
const err = new types_1.OTLPExporterError('Request Timeout');
|
|
110
|
-
onError(err);
|
|
111
|
-
}
|
|
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);
|
|
119
|
-
}
|
|
120
|
-
clearTimeout(exporterTimer);
|
|
121
|
-
clearTimeout(retryTimer);
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
sendWithRetry();
|
|
125
|
-
}
|
|
126
|
-
exports.sendWithXhr = sendWithXhr;
|
|
127
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAgB,EAChB,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,UAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;QAC1C,SAAS,EAAE,CAAC;KACb;SAAM;QACL,MAAM,KAAK,GAAG,IAAI,yBAAiB,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;QACxE,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;AACH,CAAC;AAdD,wCAcC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CACzB,IAAgB,EAChB,GAAW,EACX,OAA+B,EAC/B,eAAuB,EACvB,SAAqB,EACrB,OAA2C;IAE3C,IAAI,UAAyC,CAAC;IAC9C,IAAI,GAAmB,CAAC;IACxB,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,aAAa,GAAG,UAAU,CAAC,G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AO,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: Uint8Array,\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: Uint8Array,\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"]}
|