@opentelemetry/otlp-exporter-base 0.28.0 → 0.29.2
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 +38 -0
- package/build/esm/OTLPExporterBase.js +103 -0
- package/build/esm/OTLPExporterBase.js.map +1 -0
- package/build/esm/index.d.ts +5 -0
- package/build/esm/index.js +20 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +18 -0
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js +91 -0
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -0
- package/build/esm/platform/browser/index.d.ts +2 -0
- package/build/esm/platform/browser/index.js +17 -0
- package/build/esm/platform/browser/index.js.map +1 -0
- package/build/esm/platform/browser/util.d.ts +21 -0
- package/build/esm/platform/browser/util.js +108 -0
- package/build/esm/platform/browser/util.js.map +1 -0
- package/build/esm/platform/index.d.ts +3 -0
- package/build/esm/platform/index.js +18 -0
- package/build/esm/platform/index.js.map +1 -0
- package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +20 -0
- package/build/esm/platform/node/OTLPExporterNodeBase.js +79 -0
- package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -0
- package/build/esm/platform/node/index.d.ts +4 -0
- package/build/esm/platform/node/index.js +19 -0
- package/build/esm/platform/node/index.js.map +1 -0
- package/build/esm/platform/node/types.d.ts +17 -0
- package/build/esm/platform/node/types.js +6 -0
- package/build/esm/platform/node/types.js.map +1 -0
- package/build/esm/platform/node/util.d.ts +19 -0
- package/build/esm/platform/node/util.js +151 -0
- package/build/esm/platform/node/util.js.map +1 -0
- package/build/esm/types.d.ts +35 -0
- package/build/esm/types.js +46 -0
- package/build/esm/types.js.map +1 -0
- package/build/esm/util.d.ts +27 -0
- package/build/esm/util.js +110 -0
- package/build/esm/util.js.map +1 -0
- package/build/esm/version.d.ts +2 -0
- package/build/esm/version.js +18 -0
- package/build/esm/version.js.map +1 -0
- package/build/esnext/OTLPExporterBase.d.ts +38 -0
- package/build/esnext/OTLPExporterBase.js +99 -0
- package/build/esnext/OTLPExporterBase.js.map +1 -0
- package/build/esnext/index.d.ts +5 -0
- package/build/esnext/index.js +20 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +18 -0
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +70 -0
- package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -0
- package/build/esnext/platform/browser/index.d.ts +2 -0
- package/build/esnext/platform/browser/index.js +17 -0
- package/build/esnext/platform/browser/index.js.map +1 -0
- package/build/esnext/platform/browser/util.d.ts +21 -0
- package/build/esnext/platform/browser/util.js +80 -0
- package/build/esnext/platform/browser/util.js.map +1 -0
- package/build/esnext/platform/index.d.ts +3 -0
- package/build/esnext/platform/index.js +18 -0
- package/build/esnext/platform/index.js.map +1 -0
- package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +20 -0
- package/build/esnext/platform/node/OTLPExporterNodeBase.js +58 -0
- package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -0
- package/build/esnext/platform/node/index.d.ts +4 -0
- package/build/esnext/platform/node/index.js +19 -0
- package/build/esnext/platform/node/index.js.map +1 -0
- package/build/esnext/platform/node/types.d.ts +17 -0
- package/build/esnext/platform/node/types.js +6 -0
- package/build/esnext/platform/node/types.js.map +1 -0
- package/build/esnext/platform/node/util.d.ts +19 -0
- package/build/esnext/platform/node/util.js +140 -0
- package/build/esnext/platform/node/util.js.map +1 -0
- package/build/esnext/types.d.ts +35 -0
- package/build/esnext/types.js +27 -0
- package/build/esnext/types.js.map +1 -0
- package/build/esnext/util.d.ts +27 -0
- package/build/esnext/util.js +92 -0
- package/build/esnext/util.js.map +1 -0
- package/build/esnext/version.d.ts +2 -0
- package/build/esnext/version.js +18 -0
- package/build/esnext/version.js.map +1 -0
- package/build/src/OTLPExporterBase.d.ts +1 -2
- package/build/src/OTLPExporterBase.js +2 -1
- package/build/src/OTLPExporterBase.js.map +1 -1
- package/build/src/platform/browser/OTLPExporterBrowserBase.js +1 -1
- package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
- package/build/src/platform/browser/util.d.ts +1 -1
- package/build/src/platform/browser/util.js +12 -1
- package/build/src/platform/browser/util.js.map +1 -1
- package/build/src/platform/node/util.js +37 -8
- package/build/src/platform/node/util.js.map +1 -1
- package/build/src/types.d.ts +3 -2
- package/build/src/types.js.map +1 -1
- package/build/src/util.d.ts +21 -1
- package/build/src/util.js +62 -5
- 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 +10 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/OTLPExporterBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAYpC;;OAEG;IACH,YAAY,SAAY,EAAO;QANrB,qBAAgB,GAAuB,EAAE,CAAC;QAOlD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;YACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SACjC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,aAAa,GAAG,IAAI,cAAc,CAAC,IAAI,CA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F,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;gBACtC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aACnC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACK,SAAS;QACf,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC/B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;aACtC,IAAI,CAAC,GAAG,EAAE;YACT,6BAA6B;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;CAWF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\nimport { ExportResult, ExportResultCode, BindOnceFuture } from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nimport { configureExporterTimeout } from './util';\n\n/**\n * Collector Exporter abstract base class\n */\nexport abstract class OTLPExporterBase<\n T extends OTLPExporterConfigBase,\n ExportItem,\n ServiceRequest\n > {\n public readonly url: string;\n public readonly hostname: string | undefined;\n public readonly timeoutMillis: number;\n protected _concurrencyLimit: number;\n protected _sendingPromises: Promise<unknown>[] = [];\n protected _shutdownOnce: BindOnceFuture<void>;\n\n /**\n * @param config\n */\n constructor(config: T = {} as T) {\n this.url = this.getDefaultUrl(config);\n if (typeof config.hostname === 'string') {\n this.hostname = config.hostname;\n }\n\n this.shutdown = this.shutdown.bind(this);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : Infinity;\n\n this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);\n\n // platform dependent\n this.onInit(config);\n }\n\n /**\n * Export items.\n * @param items\n * @param resultCallback\n */\n export(items: ExportItem[], resultCallback: (result: ExportResult) => void): void {\n if (this._shutdownOnce.isCalled) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been shutdown'),\n });\n return;\n }\n\n if (this._sendingPromises.length >= this._concurrencyLimit) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Concurrent export limit reached'),\n });\n return;\n }\n\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error: ExportServiceError) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: ExportItem[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n diag.debug('items to be sent', items);\n this.send(items, resolve, reject);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Shutdown the exporter.\n */\n shutdown(): Promise<void> {\n return this._shutdownOnce.call();\n }\n\n /**\n * Called by _shutdownOnce with BindOnceFuture\n */\n private _shutdown(): Promise<void> {\n diag.debug('shutdown started');\n this.onShutdown();\n return Promise.all(this._sendingPromises)\n .then(() => {\n /** ignore resolved values */\n });\n }\n\n abstract onShutdown(): void;\n abstract onInit(config: T): void;\n abstract send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void;\n abstract getDefaultUrl(config: T): string;\n abstract convert(objects: ExportItem[]): ServiceRequest;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export * from './OTLPExporterBase';
|
|
17
|
+
export * from './platform';
|
|
18
|
+
export * from './types';
|
|
19
|
+
export * from './util';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './OTLPExporterBase';\nexport * from './platform';\nexport * from './types';\nexport * from './util';\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OTLPExporterBase } from '../../OTLPExporterBase';
|
|
2
|
+
import { OTLPExporterConfigBase } from '../../types';
|
|
3
|
+
import * as otlpTypes from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Collector Metric Exporter abstract base class
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class OTLPExporterBrowserBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem, ServiceRequest> {
|
|
8
|
+
protected _headers: Record<string, string>;
|
|
9
|
+
private _useXHR;
|
|
10
|
+
/**
|
|
11
|
+
* @param config
|
|
12
|
+
*/
|
|
13
|
+
constructor(config?: OTLPExporterConfigBase);
|
|
14
|
+
onInit(): void;
|
|
15
|
+
onShutdown(): void;
|
|
16
|
+
send(items: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=OTLPExporterBrowserBase.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { OTLPExporterBase } from '../../OTLPExporterBase';
|
|
17
|
+
import { parseHeaders } from '../../util';
|
|
18
|
+
import { sendWithBeacon, sendWithXhr } from './util';
|
|
19
|
+
import { diag } from '@opentelemetry/api';
|
|
20
|
+
import { getEnv, baggageUtils } from '@opentelemetry/core';
|
|
21
|
+
/**
|
|
22
|
+
* Collector Metric Exporter abstract base class
|
|
23
|
+
*/
|
|
24
|
+
export class OTLPExporterBrowserBase extends OTLPExporterBase {
|
|
25
|
+
/**
|
|
26
|
+
* @param config
|
|
27
|
+
*/
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
super(config);
|
|
30
|
+
this._useXHR = false;
|
|
31
|
+
this._useXHR =
|
|
32
|
+
!!config.headers || typeof navigator.sendBeacon !== 'function';
|
|
33
|
+
if (this._useXHR) {
|
|
34
|
+
this._headers = Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this._headers = {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
onInit() {
|
|
41
|
+
window.addEventListener('unload', this.shutdown);
|
|
42
|
+
}
|
|
43
|
+
onShutdown() {
|
|
44
|
+
window.removeEventListener('unload', this.shutdown);
|
|
45
|
+
}
|
|
46
|
+
send(items, onSuccess, onError) {
|
|
47
|
+
if (this._shutdownOnce.isCalled) {
|
|
48
|
+
diag.debug('Shutdown already started. Cannot send objects');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const serviceRequest = this.convert(items);
|
|
52
|
+
const body = JSON.stringify(serviceRequest);
|
|
53
|
+
const promise = new Promise((resolve, reject) => {
|
|
54
|
+
if (this._useXHR) {
|
|
55
|
+
sendWithXhr(body, this.url, this._headers, this.timeoutMillis, resolve, reject);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
sendWithBeacon(body, this.url, { type: 'application/json' }, resolve, reject);
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
.then(onSuccess, onError);
|
|
62
|
+
this._sendingPromises.push(promise);
|
|
63
|
+
const popPromise = () => {
|
|
64
|
+
const index = this._sendingPromises.indexOf(promise);
|
|
65
|
+
this._sendingPromises.splice(index, 1);
|
|
66
|
+
};
|
|
67
|
+
promise.then(popPromise, popPromise);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=OTLPExporterBrowserBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAgB,uBAGlB,SAAQ,gBAIT;IAID;;OAEG;IACH,YAAY,SAAiC,EAAE;QAC7C,KAAK,CAAC,MAAM,CAAC,CAAC;QANR,YAAO,GAAY,KAAK,CAAC;QAO/B,IAAI,CAAC,OAAO;YACV,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,CAAC;QACjE,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAC3B,EAAE,EACF,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,uBAAuB,CAClC,MAAM,EAAE,CAAC,0BAA0B,CACpC,CACF,CAAC;SACH;aAAM;YACL,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;SACpB;IACH,CAAC;IAED,MAAM;QACJ,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,UAAU;QACR,MAAM,CAAC,m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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 { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterConfigBase } from '../../types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { sendWithBeacon, sendWithXhr } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterBrowserBase<\n ExportItem,\n ServiceRequest\n > extends OTLPExporterBase<\n OTLPExporterConfigBase,\n ExportItem,\n ServiceRequest\n > {\n protected _headers: Record<string, string>;\n private _useXHR: boolean = false;\n\n /**\n * @param config\n */\n constructor(config: OTLPExporterConfigBase = {}) {\n super(config);\n this._useXHR =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n if (this._useXHR) {\n this._headers = Object.assign(\n {},\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n )\n );\n } else {\n this._headers = {};\n }\n }\n\n onInit(): void {\n window.addEventListener('unload', this.shutdown);\n }\n\n onShutdown(): void {\n window.removeEventListener('unload', this.shutdown);\n }\n\n send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n const serviceRequest = this.convert(items);\n const body = JSON.stringify(serviceRequest);\n\n const promise = new Promise<void>((resolve, reject) => {\n if (this._useXHR) {\n sendWithXhr(body, this.url, this._headers, this.timeoutMillis, resolve, reject);\n } else {\n sendWithBeacon(body, this.url, { type: 'application/json' }, resolve, reject);\n }\n })\n .then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export * from './OTLPExporterBrowserBase';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,2BAA2B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './OTLPExporterBrowserBase';\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
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: string, 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: string, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
21
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
/**
|
|
19
|
+
* Send metrics/spans using browser navigator.sendBeacon
|
|
20
|
+
* @param body
|
|
21
|
+
* @param url
|
|
22
|
+
* @param blobPropertyBag
|
|
23
|
+
* @param onSuccess
|
|
24
|
+
* @param onError
|
|
25
|
+
*/
|
|
26
|
+
export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
27
|
+
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
28
|
+
diag.debug('sendBeacon - can send', body);
|
|
29
|
+
onSuccess();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const error = new OTLPExporterError(`sendBeacon - cannot send ${body}`);
|
|
33
|
+
onError(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* function to send metrics/spans using browser XMLHttpRequest
|
|
38
|
+
* used when navigator.sendBeacon is not available
|
|
39
|
+
* @param body
|
|
40
|
+
* @param url
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param onSuccess
|
|
43
|
+
* @param onError
|
|
44
|
+
*/
|
|
45
|
+
export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
|
|
46
|
+
let reqIsDestroyed;
|
|
47
|
+
const exporterTimer = setTimeout(() => {
|
|
48
|
+
reqIsDestroyed = true;
|
|
49
|
+
xhr.abort();
|
|
50
|
+
}, exporterTimeout);
|
|
51
|
+
const xhr = new XMLHttpRequest();
|
|
52
|
+
xhr.open('POST', url);
|
|
53
|
+
const defaultHeaders = {
|
|
54
|
+
'Accept': 'application/json',
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
};
|
|
57
|
+
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
58
|
+
xhr.setRequestHeader(k, v);
|
|
59
|
+
});
|
|
60
|
+
xhr.send(body);
|
|
61
|
+
xhr.onreadystatechange = () => {
|
|
62
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
63
|
+
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
64
|
+
clearTimeout(exporterTimer);
|
|
65
|
+
diag.debug('xhr success', body);
|
|
66
|
+
onSuccess();
|
|
67
|
+
}
|
|
68
|
+
else if (reqIsDestroyed) {
|
|
69
|
+
const error = new OTLPExporterError('Request Timeout', xhr.status);
|
|
70
|
+
onError(error);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const error = new OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status);
|
|
74
|
+
clearTimeout(exporterTimer);
|
|
75
|
+
onError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAA2C;IAE3C,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE;QAChE,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;QAC1C,SAAS,EAAE,CAAC;KACb;SAAM;QACL,MAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,4BAA4B,IAAI,EAAE,CACnC,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,GAAW,EACX,OAA+B,EAC/B,eAAuB,EACvB,SAAqB,EACrB,OAA2C;IAE3C,IAAI,cAAuB,CAAC;IA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C,CAAC;gBAC5B,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Send metrics/spans using browser navigator.sendBeacon\n * @param body\n * @param url\n * @param blobPropertyBag\n * @param onSuccess\n * @param onError\n */\nexport function sendWithBeacon(\n body: string,\n url: string,\n blobPropertyBag: BlobPropertyBag,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {\n diag.debug('sendBeacon - can send', body);\n onSuccess();\n } else {\n const error = new OTLPExporterError(\n `sendBeacon - cannot send ${body}`\n );\n onError(error);\n }\n}\n\n/**\n * function to send metrics/spans using browser XMLHttpRequest\n * used when navigator.sendBeacon is not available\n * @param body\n * @param url\n * @param headers\n * @param onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string,\n url: string,\n headers: Record<string, string>,\n exporterTimeout: number,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n let reqIsDestroyed: boolean;\n\n const exporterTimer = setTimeout(() => {\n reqIsDestroyed = true;\n xhr.abort();\n }, exporterTimeout);\n\n const xhr = new XMLHttpRequest();\n xhr.open('POST', url);\n\n const defaultHeaders = {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json',\n };\n\n Object.entries({\n ...defaultHeaders,\n ...headers,\n }).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.send(body);\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n if (xhr.status >= 200 && xhr.status <= 299) {\n clearTimeout(exporterTimer);\n diag.debug('xhr success', body);\n onSuccess();\n } else if (reqIsDestroyed) {\n const error = new OTLPExporterError(\n 'Request Timeout', xhr.status\n );\n onError(error);\n } else {\n const error = new OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n clearTimeout(exporterTimer);\n onError(error);\n }\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export * from './node';
|
|
17
|
+
export { OTLPExporterBrowserBase } from './browser';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './node';\nexport { OTLPExporterBrowserBase } from './browser';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type * as https from 'https';
|
|
4
|
+
import { OTLPExporterBase } from '../../OTLPExporterBase';
|
|
5
|
+
import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
|
|
6
|
+
import * as otlpTypes from '../../types';
|
|
7
|
+
/**
|
|
8
|
+
* Collector Metric Exporter abstract base class
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class OTLPExporterNodeBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem, ServiceRequest> {
|
|
11
|
+
DEFAULT_HEADERS: Record<string, string>;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
agent: http.Agent | https.Agent | undefined;
|
|
14
|
+
compression: CompressionAlgorithm;
|
|
15
|
+
constructor(config?: OTLPExporterNodeConfigBase);
|
|
16
|
+
onInit(_config: OTLPExporterNodeConfigBase): void;
|
|
17
|
+
send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
|
|
18
|
+
onShutdown(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { OTLPExporterBase } from '../../OTLPExporterBase';
|
|
17
|
+
import { parseHeaders } from '../../util';
|
|
18
|
+
import { createHttpAgent, sendWithHttp, configureCompression } from './util';
|
|
19
|
+
import { diag } from '@opentelemetry/api';
|
|
20
|
+
import { getEnv, baggageUtils } from '@opentelemetry/core';
|
|
21
|
+
/**
|
|
22
|
+
* Collector Metric Exporter abstract base class
|
|
23
|
+
*/
|
|
24
|
+
export class OTLPExporterNodeBase extends OTLPExporterBase {
|
|
25
|
+
constructor(config = {}) {
|
|
26
|
+
super(config);
|
|
27
|
+
this.DEFAULT_HEADERS = {};
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
if (config.metadata) {
|
|
30
|
+
diag.warn('Metadata cannot be set when using http');
|
|
31
|
+
}
|
|
32
|
+
this.headers = Object.assign(this.DEFAULT_HEADERS, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
|
|
33
|
+
this.agent = createHttpAgent(config);
|
|
34
|
+
this.compression = configureCompression(config.compression);
|
|
35
|
+
}
|
|
36
|
+
onInit(_config) { }
|
|
37
|
+
send(objects, onSuccess, onError) {
|
|
38
|
+
if (this._shutdownOnce.isCalled) {
|
|
39
|
+
diag.debug('Shutdown already started. Cannot send objects');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const serviceRequest = this.convert(objects);
|
|
43
|
+
const promise = new Promise((resolve, reject) => {
|
|
44
|
+
sendWithHttp(this, JSON.stringify(serviceRequest), 'application/json', resolve, reject);
|
|
45
|
+
})
|
|
46
|
+
.then(onSuccess, onError);
|
|
47
|
+
this._sendingPromises.push(promise);
|
|
48
|
+
const popPromise = () => {
|
|
49
|
+
const index = this._sendingPromises.indexOf(promise);
|
|
50
|
+
this._sendingPromises.splice(index, 1);
|
|
51
|
+
};
|
|
52
|
+
promise.then(popPromise, popPromise);
|
|
53
|
+
}
|
|
54
|
+
// TODO: end gzip stream from util.ts if not undefined
|
|
55
|
+
// It should perhaps be a class member here instead of a variable in util.ts
|
|
56
|
+
onShutdown() { }
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=OTLPExporterNodeBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAgB,oBAGpB,SAAQ,gBAIT;IAMC,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,MAAM,CAAC,CAAC;QANhB,oBAAe,GAA2B,EAAE,CAAC;QAO3C,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,eAAe,EACpB,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,0BAA0B,CAAC,CAC1E,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,OAAmC,IAAS,CAAC;IAEpD,IAAI,CACF,OAAqB,EACrB,SAAqB,EACrB,OAAqD;QAErD,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE7C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpD,YAAY,CACV,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAC9B,kBAAkB,EAClB,OAAO,EACP,MAAM,CACP,CAAC;QACJ,CAAC,CAAC;aACC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,sDAAsD;IACtD,4EAA4E;IAC5E,UAAU,KAAU,CAAC;CACtB","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 type * as http from 'http';\nimport type * as https from 'https';\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { createHttpAgent, sendWithHttp, configureCompression } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceRequest\n> extends OTLPExporterBase<\n OTLPExporterNodeConfigBase,\n ExportItem,\n ServiceRequest\n> {\n DEFAULT_HEADERS: Record<string, string> = {};\n headers: Record<string, string>;\n agent: http.Agent | https.Agent | undefined;\n compression: CompressionAlgorithm;\n\n constructor(config: OTLPExporterNodeConfigBase = {}) {\n super(config);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((config as any).metadata) {\n diag.warn('Metadata cannot be set when using http');\n }\n this.headers = Object.assign(\n this.DEFAULT_HEADERS,\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)\n );\n this.agent = createHttpAgent(config);\n this.compression = configureCompression(config.compression);\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n const serviceRequest = this.convert(objects);\n\n const promise = new Promise<void>((resolve, reject) => {\n sendWithHttp(\n this,\n JSON.stringify(serviceRequest),\n 'application/json',\n resolve,\n reject\n );\n })\n .then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n\n // TODO: end gzip stream from util.ts if not undefined\n // It should perhaps be a class member here instead of a variable in util.ts\n onShutdown(): void {}\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export * from './OTLPExporterNodeBase';
|
|
17
|
+
export * from './util';
|
|
18
|
+
export * from './types';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './OTLPExporterNodeBase';\nexport * from './util';\nexport * from './types';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
3
|
+
import type * as https from 'https';
|
|
4
|
+
import { OTLPExporterConfigBase } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* Collector Exporter node base config
|
|
7
|
+
*/
|
|
8
|
+
export interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {
|
|
9
|
+
keepAlive?: boolean;
|
|
10
|
+
compression?: CompressionAlgorithm;
|
|
11
|
+
httpAgentOptions?: http.AgentOptions | https.AgentOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare enum CompressionAlgorithm {
|
|
14
|
+
NONE = "none",
|
|
15
|
+
GZIP = "gzip"
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/platform/node/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B","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 type * as http from 'http';\nimport type * as https from 'https';\n\nimport { OTLPExporterConfigBase } from '../../types';\n\n/**\n * Collector Exporter node base config\n */\nexport interface OTLPExporterNodeConfigBase\n extends OTLPExporterConfigBase {\n keepAlive?: boolean;\n compression?: CompressionAlgorithm;\n httpAgentOptions?: http.AgentOptions | https.AgentOptions;\n}\n\nexport enum CompressionAlgorithm {\n NONE = 'none',\n GZIP = 'gzip'\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
|
|
5
|
+
import { OTLPExporterNodeConfigBase } from '.';
|
|
6
|
+
import { CompressionAlgorithm } from './types';
|
|
7
|
+
import { OTLPExporterError } from '../../types';
|
|
8
|
+
/**
|
|
9
|
+
* Sends data using http
|
|
10
|
+
* @param collector
|
|
11
|
+
* @param data
|
|
12
|
+
* @param contentType
|
|
13
|
+
* @param onSuccess
|
|
14
|
+
* @param onError
|
|
15
|
+
*/
|
|
16
|
+
export declare function sendWithHttp<ExportItem, ServiceRequest>(collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>, data: string | Buffer, contentType: string, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
|
|
17
|
+
export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
|
|
18
|
+
export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
|
|
19
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as url from 'url';
|
|
17
|
+
import * as http from 'http';
|
|
18
|
+
import * as https from 'https';
|
|
19
|
+
import * as zlib from 'zlib';
|
|
20
|
+
import { Readable } from 'stream';
|
|
21
|
+
import { diag } from '@opentelemetry/api';
|
|
22
|
+
import { CompressionAlgorithm } from './types';
|
|
23
|
+
import { getEnv } from '@opentelemetry/core';
|
|
24
|
+
import { OTLPExporterError } from '../../types';
|
|
25
|
+
let gzip;
|
|
26
|
+
/**
|
|
27
|
+
* Sends data using http
|
|
28
|
+
* @param collector
|
|
29
|
+
* @param data
|
|
30
|
+
* @param contentType
|
|
31
|
+
* @param onSuccess
|
|
32
|
+
* @param onError
|
|
33
|
+
*/
|
|
34
|
+
export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
35
|
+
const exporterTimeout = collector.timeoutMillis;
|
|
36
|
+
const parsedUrl = new url.URL(collector.url);
|
|
37
|
+
let reqIsDestroyed;
|
|
38
|
+
const nodeVersion = Number(process.versions.node.split('.')[0]);
|
|
39
|
+
const exporterTimer = setTimeout(() => {
|
|
40
|
+
reqIsDestroyed = true;
|
|
41
|
+
// req.abort() was deprecated since v14
|
|
42
|
+
if (nodeVersion >= 14) {
|
|
43
|
+
req.destroy();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
req.abort();
|
|
47
|
+
}
|
|
48
|
+
}, exporterTimeout);
|
|
49
|
+
const options = {
|
|
50
|
+
hostname: parsedUrl.hostname,
|
|
51
|
+
port: parsedUrl.port,
|
|
52
|
+
path: parsedUrl.pathname,
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: Object.assign({ 'Content-Type': contentType }, collector.headers),
|
|
55
|
+
agent: collector.agent,
|
|
56
|
+
};
|
|
57
|
+
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
58
|
+
const req = request(options, (res) => {
|
|
59
|
+
let responseData = '';
|
|
60
|
+
res.on('data', chunk => (responseData += chunk));
|
|
61
|
+
res.on('aborted', () => {
|
|
62
|
+
if (reqIsDestroyed) {
|
|
63
|
+
const err = new OTLPExporterError('Request Timeout');
|
|
64
|
+
onError(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
res.on('end', () => {
|
|
68
|
+
if (!reqIsDestroyed) {
|
|
69
|
+
if (res.statusCode && res.statusCode < 299) {
|
|
70
|
+
diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
71
|
+
onSuccess();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
75
|
+
onError(error);
|
|
76
|
+
}
|
|
77
|
+
clearTimeout(exporterTimer);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
req.on('error', (error) => {
|
|
82
|
+
if (reqIsDestroyed) {
|
|
83
|
+
const err = new OTLPExporterError('Request Timeout', error.code);
|
|
84
|
+
onError(err);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
clearTimeout(exporterTimer);
|
|
88
|
+
onError(error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
switch (collector.compression) {
|
|
92
|
+
case CompressionAlgorithm.GZIP: {
|
|
93
|
+
if (!gzip) {
|
|
94
|
+
gzip = zlib.createGzip();
|
|
95
|
+
}
|
|
96
|
+
req.setHeader('Content-Encoding', 'gzip');
|
|
97
|
+
const dataStream = readableFromBuffer(data);
|
|
98
|
+
dataStream.on('error', onError)
|
|
99
|
+
.pipe(gzip).on('error', onError)
|
|
100
|
+
.pipe(req);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
req.end(data);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function readableFromBuffer(buff) {
|
|
109
|
+
const readable = new Readable();
|
|
110
|
+
readable.push(buff);
|
|
111
|
+
readable.push(null);
|
|
112
|
+
return readable;
|
|
113
|
+
}
|
|
114
|
+
export function createHttpAgent(config) {
|
|
115
|
+
if (config.httpAgentOptions && config.keepAlive === false) {
|
|
116
|
+
diag.warn('httpAgentOptions is used only when keepAlive is true');
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
if (config.keepAlive === false || !config.url)
|
|
120
|
+
return undefined;
|
|
121
|
+
try {
|
|
122
|
+
const parsedUrl = new url.URL(config.url);
|
|
123
|
+
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
|
|
124
|
+
return new Agent(Object.assign({ keepAlive: true }, config.httpAgentOptions));
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
diag.error(`collector exporter failed to create http agent. err: ${err.message}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function configureCompression(compression) {
|
|
132
|
+
if (compression) {
|
|
133
|
+
return compression;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;
|
|
137
|
+
return definedCompression === CompressionAlgorithm.GZIP ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=util.js.map
|