@opentelemetry/exporter-trace-otlp-http 0.27.0 → 0.28.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/README.md +3 -9
- package/build/esm/index.d.ts +0 -2
- package/build/esm/index.js +0 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/platform/browser/OTLPTraceExporter.d.ts +2 -2
- package/build/esm/platform/browser/OTLPTraceExporter.js +2 -3
- package/build/esm/platform/browser/OTLPTraceExporter.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/index.d.ts +0 -1
- package/build/esm/platform/index.js +0 -1
- package/build/esm/platform/index.js.map +1 -1
- package/build/esm/platform/node/OTLPTraceExporter.d.ts +2 -2
- package/build/esm/platform/node/OTLPTraceExporter.js +3 -3
- package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
- package/build/esm/platform/node/index.d.ts +0 -3
- package/build/esm/platform/node/index.js +0 -3
- package/build/esm/platform/node/index.js.map +1 -1
- package/build/esm/transform.d.ts +2 -2
- package/build/esm/transform.js +18 -2
- package/build/esm/transform.js.map +1 -1
- package/build/esm/types.d.ts +1 -33
- package/build/esm/types.js +0 -30
- package/build/esm/types.js.map +1 -1
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/index.d.ts +4 -0
- package/build/esnext/index.js +19 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +13 -0
- package/build/esnext/platform/browser/OTLPTraceExporter.js +42 -0
- package/build/esnext/platform/browser/OTLPTraceExporter.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/index.d.ts +2 -0
- package/build/esnext/platform/index.js +17 -0
- package/build/esnext/platform/index.js.map +1 -0
- package/build/esnext/platform/node/OTLPTraceExporter.d.ts +13 -0
- package/build/esnext/platform/node/OTLPTraceExporter.js +43 -0
- package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -0
- package/build/esnext/platform/node/index.d.ts +2 -0
- package/build/esnext/platform/node/index.js +17 -0
- package/build/esnext/platform/node/index.js.map +1 -0
- package/build/esnext/transform.d.ts +80 -0
- package/build/esnext/transform.js +266 -0
- package/build/esnext/transform.js.map +1 -0
- package/build/esnext/types.d.ts +209 -0
- package/build/esnext/types.js +145 -0
- package/build/esnext/types.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/index.d.ts +0 -2
- package/build/src/index.js +1 -4
- package/build/src/index.js.map +1 -1
- package/build/src/platform/browser/OTLPTraceExporter.d.ts +2 -2
- package/build/src/platform/browser/OTLPTraceExporter.js +9 -10
- package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
- package/build/src/platform/browser/index.d.ts +0 -1
- package/build/src/platform/browser/index.js +0 -1
- package/build/src/platform/browser/index.js.map +1 -1
- package/build/src/platform/index.d.ts +0 -1
- package/build/src/platform/index.js +0 -3
- package/build/src/platform/index.js.map +1 -1
- package/build/src/platform/node/OTLPTraceExporter.d.ts +2 -2
- package/build/src/platform/node/OTLPTraceExporter.js +10 -10
- package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
- package/build/src/platform/node/index.d.ts +0 -3
- package/build/src/platform/node/index.js +0 -3
- package/build/src/platform/node/index.js.map +1 -1
- package/build/src/transform.d.ts +2 -2
- package/build/src/transform.js.map +1 -1
- package/build/src/types.d.ts +1 -33
- package/build/src/types.js +1 -13
- package/build/src/types.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 +30 -21
- package/build/esm/OTLPExporterBase.d.ts +0 -36
- package/build/esm/OTLPExporterBase.js +0 -114
- package/build/esm/OTLPExporterBase.js.map +0 -1
- package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js +0 -91
- package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
- package/build/esm/platform/browser/util.d.ts +0 -17
- package/build/esm/platform/browser/util.js +0 -77
- package/build/esm/platform/browser/util.js.map +0 -1
- package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +0 -20
- package/build/esm/platform/node/OTLPExporterNodeBase.js +0 -82
- package/build/esm/platform/node/OTLPExporterNodeBase.js.map +0 -1
- package/build/esm/platform/node/types.d.ts +0 -17
- package/build/esm/platform/node/types.js +0 -6
- package/build/esm/platform/node/types.js.map +0 -1
- package/build/esm/platform/node/util.d.ts +0 -17
- package/build/esm/platform/node/util.js +0 -113
- package/build/esm/platform/node/util.js.map +0 -1
- package/build/esm/util.d.ts +0 -7
- package/build/esm/util.js +0 -40
- package/build/esm/util.js.map +0 -1
- package/build/src/OTLPExporterBase.d.ts +0 -36
- package/build/src/OTLPExporterBase.js +0 -113
- package/build/src/OTLPExporterBase.js.map +0 -1
- package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
- package/build/src/platform/browser/OTLPExporterBrowserBase.js +0 -74
- package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
- package/build/src/platform/browser/util.d.ts +0 -17
- package/build/src/platform/browser/util.js +0 -70
- package/build/src/platform/browser/util.js.map +0 -1
- package/build/src/platform/node/OTLPExporterNodeBase.d.ts +0 -20
- package/build/src/platform/node/OTLPExporterNodeBase.js +0 -65
- package/build/src/platform/node/OTLPExporterNodeBase.js.map +0 -1
- package/build/src/platform/node/types.d.ts +0 -17
- package/build/src/platform/node/types.js +0 -9
- package/build/src/platform/node/types.js.map +0 -1
- package/build/src/platform/node/util.d.ts +0 -17
- package/build/src/platform/node/util.js +0 -107
- package/build/src/platform/node/util.js.map +0 -1
- package/build/src/util.d.ts +0 -7
- package/build/src/util.js +0 -43
- package/build/src/util.js.map +0 -1
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright The OpenTelemetry Authors
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.OTLPExporterBase = void 0;
|
|
19
|
-
const api_1 = require("@opentelemetry/api");
|
|
20
|
-
const core_1 = require("@opentelemetry/core");
|
|
21
|
-
/**
|
|
22
|
-
* Collector Exporter abstract base class
|
|
23
|
-
*/
|
|
24
|
-
class OTLPExporterBase {
|
|
25
|
-
/**
|
|
26
|
-
* @param config
|
|
27
|
-
*/
|
|
28
|
-
constructor(config = {}) {
|
|
29
|
-
this._isShutdown = false;
|
|
30
|
-
this._shuttingDownPromise = Promise.resolve();
|
|
31
|
-
this._sendingPromises = [];
|
|
32
|
-
this.url = this.getDefaultUrl(config);
|
|
33
|
-
if (typeof config.hostname === 'string') {
|
|
34
|
-
this.hostname = config.hostname;
|
|
35
|
-
}
|
|
36
|
-
this.attributes = config.attributes;
|
|
37
|
-
this.shutdown = this.shutdown.bind(this);
|
|
38
|
-
this._concurrencyLimit =
|
|
39
|
-
typeof config.concurrencyLimit === 'number'
|
|
40
|
-
? config.concurrencyLimit
|
|
41
|
-
: Infinity;
|
|
42
|
-
// platform dependent
|
|
43
|
-
this.onInit(config);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Export items.
|
|
47
|
-
* @param items
|
|
48
|
-
* @param resultCallback
|
|
49
|
-
*/
|
|
50
|
-
export(items, resultCallback) {
|
|
51
|
-
if (this._isShutdown) {
|
|
52
|
-
resultCallback({
|
|
53
|
-
code: core_1.ExportResultCode.FAILED,
|
|
54
|
-
error: new Error('Exporter has been shutdown'),
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (this._sendingPromises.length >= this._concurrencyLimit) {
|
|
59
|
-
resultCallback({
|
|
60
|
-
code: core_1.ExportResultCode.FAILED,
|
|
61
|
-
error: new Error('Concurrent export limit reached'),
|
|
62
|
-
});
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this._export(items)
|
|
66
|
-
.then(() => {
|
|
67
|
-
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
68
|
-
})
|
|
69
|
-
.catch((error) => {
|
|
70
|
-
resultCallback({ code: core_1.ExportResultCode.FAILED, error });
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
_export(items) {
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
try {
|
|
76
|
-
api_1.diag.debug('items to be sent', items);
|
|
77
|
-
this.send(items, resolve, reject);
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
reject(e);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Shutdown the exporter.
|
|
86
|
-
*/
|
|
87
|
-
shutdown() {
|
|
88
|
-
if (this._isShutdown) {
|
|
89
|
-
api_1.diag.debug('shutdown already started');
|
|
90
|
-
return this._shuttingDownPromise;
|
|
91
|
-
}
|
|
92
|
-
this._isShutdown = true;
|
|
93
|
-
api_1.diag.debug('shutdown started');
|
|
94
|
-
this._shuttingDownPromise = new Promise((resolve, reject) => {
|
|
95
|
-
Promise.resolve()
|
|
96
|
-
.then(() => {
|
|
97
|
-
return this.onShutdown();
|
|
98
|
-
})
|
|
99
|
-
.then(() => {
|
|
100
|
-
return Promise.all(this._sendingPromises);
|
|
101
|
-
})
|
|
102
|
-
.then(() => {
|
|
103
|
-
resolve();
|
|
104
|
-
})
|
|
105
|
-
.catch(e => {
|
|
106
|
-
reject(e);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
return this._shuttingDownPromise;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.OTLPExporterBase = OTLPExporterBase;
|
|
113
|
-
//# sourceMappingURL=OTLPExporterBase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/OTLPExporterBase.ts"],"names":[],"mappings":"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","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 { SpanAttributes, diag } from '@opentelemetry/api';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\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 attributes?: SpanAttributes;\n protected _concurrencyLimit: number;\n protected _isShutdown: boolean = false;\n private _shuttingDownPromise: Promise<void> = Promise.resolve();\n protected _sendingPromises: Promise<unknown>[] = [];\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.attributes = config.attributes;\n\n this.shutdown = this.shutdown.bind(this);\n\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : Infinity;\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._isShutdown) {\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 if (this._isShutdown) {\n diag.debug('shutdown already started');\n return this._shuttingDownPromise;\n }\n this._isShutdown = true;\n diag.debug('shutdown started');\n this._shuttingDownPromise = new Promise((resolve, reject) => {\n Promise.resolve()\n .then(() => {\n return this.onShutdown();\n })\n .then(() => {\n return Promise.all(this._sendingPromises);\n })\n .then(() => {\n resolve();\n })\n .catch(e => {\n reject(e);\n });\n });\n return this._shuttingDownPromise;\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"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright The OpenTelemetry Authors
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.OTLPExporterBrowserBase = void 0;
|
|
19
|
-
const OTLPExporterBase_1 = require("../../OTLPExporterBase");
|
|
20
|
-
const util_1 = require("../../util");
|
|
21
|
-
const util_2 = require("./util");
|
|
22
|
-
const api_1 = require("@opentelemetry/api");
|
|
23
|
-
const core_1 = require("@opentelemetry/core");
|
|
24
|
-
/**
|
|
25
|
-
* Collector Metric Exporter abstract base class
|
|
26
|
-
*/
|
|
27
|
-
class OTLPExporterBrowserBase extends OTLPExporterBase_1.OTLPExporterBase {
|
|
28
|
-
/**
|
|
29
|
-
* @param config
|
|
30
|
-
*/
|
|
31
|
-
constructor(config = {}) {
|
|
32
|
-
super(config);
|
|
33
|
-
this._useXHR = false;
|
|
34
|
-
this._useXHR =
|
|
35
|
-
!!config.headers || typeof navigator.sendBeacon !== 'function';
|
|
36
|
-
if (this._useXHR) {
|
|
37
|
-
this._headers = Object.assign({}, util_1.parseHeaders(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord(core_1.getEnv().OTEL_EXPORTER_OTLP_HEADERS));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this._headers = {};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
onInit() {
|
|
44
|
-
window.addEventListener('unload', this.shutdown);
|
|
45
|
-
}
|
|
46
|
-
onShutdown() {
|
|
47
|
-
window.removeEventListener('unload', this.shutdown);
|
|
48
|
-
}
|
|
49
|
-
send(items, onSuccess, onError) {
|
|
50
|
-
if (this._isShutdown) {
|
|
51
|
-
api_1.diag.debug('Shutdown already started. Cannot send objects');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const serviceRequest = this.convert(items);
|
|
55
|
-
const body = JSON.stringify(serviceRequest);
|
|
56
|
-
const promise = new Promise((resolve, reject) => {
|
|
57
|
-
if (this._useXHR) {
|
|
58
|
-
util_2.sendWithXhr(body, this.url, this._headers, resolve, reject);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
util_2.sendWithBeacon(body, this.url, { type: 'application/json' }, resolve, reject);
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
.then(onSuccess, onError);
|
|
65
|
-
this._sendingPromises.push(promise);
|
|
66
|
-
const popPromise = () => {
|
|
67
|
-
const index = this._sendingPromises.indexOf(promise);
|
|
68
|
-
this._sendingPromises.splice(index, 1);
|
|
69
|
-
};
|
|
70
|
-
promise.then(popPromise, popPromise);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.OTLPExporterBrowserBase = OTLPExporterBrowserBase;
|
|
74
|
-
//# sourceMappingURL=OTLPExporterBrowserBase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6DAA0D;AAG1D,qCAA0C;AAC1C,iCAAqD;AACrD,4CAA0C;AAC1C,8CAA2D;AAE3D;;GAEG;AACH,MAAsB,uBAGlB,SAAQ,mCAIT;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,mBAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,mBAAY,CAAC,uBAAuB,CAClC,aAAM,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,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CACF,KAAmB,EACnB,SAAqB,EACrB,OAAqD;QAErD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,UAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAE5C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpD,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,kBAAW,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aAC7D;iBAAM;gBACL,qBAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aAC/E;QACH,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,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;CACF;AAnED,0DAmEC","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 { 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._isShutdown) {\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, 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"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as otlpTypes from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
4
|
-
* @param body
|
|
5
|
-
* @param onSuccess
|
|
6
|
-
* @param onError
|
|
7
|
-
*/
|
|
8
|
-
export declare function sendWithBeacon(body: string, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
|
|
9
|
-
/**
|
|
10
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
11
|
-
* used when navigator.sendBeacon is not available
|
|
12
|
-
* @param body
|
|
13
|
-
* @param onSuccess
|
|
14
|
-
* @param onError
|
|
15
|
-
*/
|
|
16
|
-
export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
|
|
17
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,70 +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 otlpTypes = require("../../types");
|
|
21
|
-
/**
|
|
22
|
-
* Send metrics/spans using browser navigator.sendBeacon
|
|
23
|
-
* @param body
|
|
24
|
-
* @param onSuccess
|
|
25
|
-
* @param onError
|
|
26
|
-
*/
|
|
27
|
-
function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
28
|
-
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
29
|
-
api_1.diag.debug('sendBeacon - can send', body);
|
|
30
|
-
onSuccess();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const error = new otlpTypes.OTLPExporterError(`sendBeacon - cannot send ${body}`);
|
|
34
|
-
onError(error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.sendWithBeacon = sendWithBeacon;
|
|
38
|
-
/**
|
|
39
|
-
* function to send metrics/spans using browser XMLHttpRequest
|
|
40
|
-
* used when navigator.sendBeacon is not available
|
|
41
|
-
* @param body
|
|
42
|
-
* @param onSuccess
|
|
43
|
-
* @param onError
|
|
44
|
-
*/
|
|
45
|
-
function sendWithXhr(body, url, headers, onSuccess, onError) {
|
|
46
|
-
const xhr = new XMLHttpRequest();
|
|
47
|
-
xhr.open('POST', url);
|
|
48
|
-
const defaultHeaders = {
|
|
49
|
-
'Accept': 'application/json',
|
|
50
|
-
'Content-Type': 'application/json',
|
|
51
|
-
};
|
|
52
|
-
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
53
|
-
xhr.setRequestHeader(k, v);
|
|
54
|
-
});
|
|
55
|
-
xhr.send(body);
|
|
56
|
-
xhr.onreadystatechange = () => {
|
|
57
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
58
|
-
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
59
|
-
api_1.diag.debug('xhr success', body);
|
|
60
|
-
onSuccess();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const error = new otlpTypes.OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status);
|
|
64
|
-
onError(error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
exports.sendWithXhr = sendWithXhr;
|
|
70
|
-
//# 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,yCAAyC;AAEzC;;;;;GAKG;AACH,SAAgB,cAAc,CAC5B,IAAY,EACZ,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAAqD;IAErD,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,SAAS,CAAC,iBAAiB,CAC3C,4BAA4B,IAAI,EAAE,CACnC,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;AACH,CAAC;AAhBD,wCAgBC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,IAAY,EACZ,GAAW,EACX,OAA+B,EAC/B,SAAqB,EACrB,OAAqD;IAErD,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IACjC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtB,MAAM,cAAc,GAAG;QACrB,QAAQ,EAAE,kBAAkB;QAC5B,cAAc,EAAE,kBAAkB;KACnC,CAAC;IAEF,MAAM,CAAC,OAAO,iCACT,cAAc,GACd,OAAO,EACV,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QACpB,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEf,GAAG,CAAC,kBAAkB,GAAG,GAAG,EAAE;QAC5B,IAAI,GAAG,CAAC,UAAU,KAAK,cAAc,CAAC,IAAI,EAAE;YAC1C,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;gBAC1C,UAAI,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBAChC,SAAS,EAAE,CAAC;aACb;iBAAM;gBACL,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,iBAAiB,CAC3C,sCAAsC,GAAG,CAAC,MAAM,GAAG,EACnD,GAAG,CAAC,MAAM,CACX,CAAC;gBAEF,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AAvCD,kCAuCC","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 * as otlpTypes from '../../types';\n\n/**\n * Send metrics/spans using browser navigator.sendBeacon\n * @param body\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: otlpTypes.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 otlpTypes.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 onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string,\n url: string,\n headers: Record<string, string>,\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n): void {\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 diag.debug('xhr success', body);\n onSuccess();\n } else {\n const error = new otlpTypes.OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n\n onError(error);\n }\n }\n };\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright The OpenTelemetry Authors
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.OTLPExporterNodeBase = void 0;
|
|
19
|
-
const OTLPExporterBase_1 = require("../../OTLPExporterBase");
|
|
20
|
-
const types_1 = require("./types");
|
|
21
|
-
const util_1 = require("../../util");
|
|
22
|
-
const util_2 = require("./util");
|
|
23
|
-
const api_1 = require("@opentelemetry/api");
|
|
24
|
-
const core_1 = require("@opentelemetry/core");
|
|
25
|
-
/**
|
|
26
|
-
* Collector Metric Exporter abstract base class
|
|
27
|
-
*/
|
|
28
|
-
class OTLPExporterNodeBase extends OTLPExporterBase_1.OTLPExporterBase {
|
|
29
|
-
constructor(config = {}) {
|
|
30
|
-
super(config);
|
|
31
|
-
this.DEFAULT_HEADERS = {};
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
if (config.metadata) {
|
|
34
|
-
api_1.diag.warn('Metadata cannot be set when using http');
|
|
35
|
-
}
|
|
36
|
-
this.headers = Object.assign(this.DEFAULT_HEADERS, util_1.parseHeaders(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord(core_1.getEnv().OTEL_EXPORTER_OTLP_HEADERS));
|
|
37
|
-
this.agent = util_2.createHttpAgent(config);
|
|
38
|
-
this.compression = config.compression || types_1.CompressionAlgorithm.NONE;
|
|
39
|
-
}
|
|
40
|
-
onInit(_config) {
|
|
41
|
-
this._isShutdown = false;
|
|
42
|
-
}
|
|
43
|
-
send(objects, onSuccess, onError) {
|
|
44
|
-
if (this._isShutdown) {
|
|
45
|
-
api_1.diag.debug('Shutdown already started. Cannot send objects');
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const serviceRequest = this.convert(objects);
|
|
49
|
-
const promise = new Promise((resolve, reject) => {
|
|
50
|
-
util_2.sendWithHttp(this, JSON.stringify(serviceRequest), 'application/json', resolve, reject);
|
|
51
|
-
})
|
|
52
|
-
.then(onSuccess, onError);
|
|
53
|
-
this._sendingPromises.push(promise);
|
|
54
|
-
const popPromise = () => {
|
|
55
|
-
const index = this._sendingPromises.indexOf(promise);
|
|
56
|
-
this._sendingPromises.splice(index, 1);
|
|
57
|
-
};
|
|
58
|
-
promise.then(popPromise, popPromise);
|
|
59
|
-
}
|
|
60
|
-
// TODO: end gzip stream from util.ts if not undefined
|
|
61
|
-
// It should perhaps be a class member here instead of a variable in util.ts
|
|
62
|
-
onShutdown() { }
|
|
63
|
-
}
|
|
64
|
-
exports.OTLPExporterNodeBase = OTLPExporterNodeBase;
|
|
65
|
-
//# sourceMappingURL=OTLPExporterNodeBase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAKH,6DAA0D;AAC1D,mCAA2E;AAE3E,qCAA0C;AAC1C,iCAAuD;AACvD,4CAA0C;AAC1C,8CAA2D;AAE3D;;GAEG;AACH,MAAsB,oBAGpB,SAAQ,mCAIT;IAMC,YAAY,SAAqC,EAAE;QACjD,KAAK,CAAC,MAAM,CAAC,CAAC;QANhB,oBAAe,GAA2B,EAAE,CAAC;QAO3C,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,UAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,IAAI,CAAC,eAAe,EACpB,mBAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,mBAAY,CAAC,uBAAuB,CAAC,aAAM,EAAE,CAAC,0BAA0B,CAAC,CAC1E,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,sBAAe,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,4BAAoB,CAAC,IAAI,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,OAAmC;QACxC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,IAAI,CACF,OAAqB,EACrB,SAAqB,EACrB,OAAqD;QAErD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,UAAI,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,mBAAY,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,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,sDAAsD;IACtD,4EAA4E;IAC5E,UAAU,KAAU,CAAC;CACtB;AAjED,oDAiEC","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 } 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 = config.compression || CompressionAlgorithm.NONE;\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {\n this._isShutdown = false;\n }\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._isShutdown) {\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"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompressionAlgorithm = void 0;
|
|
4
|
-
var CompressionAlgorithm;
|
|
5
|
-
(function (CompressionAlgorithm) {
|
|
6
|
-
CompressionAlgorithm["NONE"] = "none";
|
|
7
|
-
CompressionAlgorithm["GZIP"] = "gzip";
|
|
8
|
-
})(CompressionAlgorithm = exports.CompressionAlgorithm || (exports.CompressionAlgorithm = {}));
|
|
9
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/platform/node/types.ts"],"names":[],"mappings":";;;AA8BA,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,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"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as http from 'http';
|
|
3
|
-
import * as https from 'https';
|
|
4
|
-
import * as otlpTypes from '../../types';
|
|
5
|
-
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
|
|
6
|
-
import { OTLPExporterNodeConfigBase } from '.';
|
|
7
|
-
/**
|
|
8
|
-
* Sends data using http
|
|
9
|
-
* @param collector
|
|
10
|
-
* @param data
|
|
11
|
-
* @param contentType
|
|
12
|
-
* @param onSuccess
|
|
13
|
-
* @param onError
|
|
14
|
-
*/
|
|
15
|
-
export declare function sendWithHttp<ExportItem, ServiceRequest>(collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>, data: string | Buffer, contentType: string, onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
|
|
16
|
-
export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
|
|
17
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHttpAgent = exports.sendWithHttp = 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 url = require("url");
|
|
20
|
-
const http = require("http");
|
|
21
|
-
const https = require("https");
|
|
22
|
-
const zlib = require("zlib");
|
|
23
|
-
const stream_1 = require("stream");
|
|
24
|
-
const otlpTypes = require("../../types");
|
|
25
|
-
const api_1 = require("@opentelemetry/api");
|
|
26
|
-
const types_1 = require("./types");
|
|
27
|
-
let gzip;
|
|
28
|
-
/**
|
|
29
|
-
* Sends data using http
|
|
30
|
-
* @param collector
|
|
31
|
-
* @param data
|
|
32
|
-
* @param contentType
|
|
33
|
-
* @param onSuccess
|
|
34
|
-
* @param onError
|
|
35
|
-
*/
|
|
36
|
-
function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
37
|
-
const parsedUrl = new url.URL(collector.url);
|
|
38
|
-
const options = {
|
|
39
|
-
hostname: parsedUrl.hostname,
|
|
40
|
-
port: parsedUrl.port,
|
|
41
|
-
path: parsedUrl.pathname,
|
|
42
|
-
method: 'POST',
|
|
43
|
-
headers: Object.assign({ 'Content-Length': Buffer.byteLength(data), 'Content-Type': contentType }, collector.headers),
|
|
44
|
-
agent: collector.agent,
|
|
45
|
-
};
|
|
46
|
-
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
47
|
-
const req = request(options, (res) => {
|
|
48
|
-
let responseData = '';
|
|
49
|
-
res.on('data', chunk => (responseData += chunk));
|
|
50
|
-
res.on('end', () => {
|
|
51
|
-
if (res.statusCode && res.statusCode < 299) {
|
|
52
|
-
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
53
|
-
onSuccess();
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const error = new otlpTypes.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
57
|
-
onError(error);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
req.on('error', (error) => {
|
|
62
|
-
onError(error);
|
|
63
|
-
});
|
|
64
|
-
switch (collector.compression) {
|
|
65
|
-
case types_1.CompressionAlgorithm.GZIP: {
|
|
66
|
-
if (!gzip) {
|
|
67
|
-
gzip = zlib.createGzip();
|
|
68
|
-
}
|
|
69
|
-
req.setHeader('Content-Encoding', 'gzip');
|
|
70
|
-
const dataStream = readableFromBuffer(data);
|
|
71
|
-
dataStream.on('error', onError)
|
|
72
|
-
.pipe(gzip).on('error', onError)
|
|
73
|
-
.pipe(req);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
default:
|
|
77
|
-
req.write(data);
|
|
78
|
-
req.end();
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.sendWithHttp = sendWithHttp;
|
|
83
|
-
function readableFromBuffer(buff) {
|
|
84
|
-
const readable = new stream_1.Readable();
|
|
85
|
-
readable.push(buff);
|
|
86
|
-
readable.push(null);
|
|
87
|
-
return readable;
|
|
88
|
-
}
|
|
89
|
-
function createHttpAgent(config) {
|
|
90
|
-
if (config.httpAgentOptions && config.keepAlive === false) {
|
|
91
|
-
api_1.diag.warn('httpAgentOptions is used only when keepAlive is true');
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
if (config.keepAlive === false || !config.url)
|
|
95
|
-
return undefined;
|
|
96
|
-
try {
|
|
97
|
-
const parsedUrl = new url.URL(config.url);
|
|
98
|
-
const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
|
|
99
|
-
return new Agent(Object.assign({ keepAlive: true }, config.httpAgentOptions));
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
api_1.diag.error(`collector exporter failed to create http agent. err: ${err.message}`);
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.createHttpAgent = createHttpAgent;
|
|
107
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as url from 'url';\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport * as otlpTypes from '../../types';\nimport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nimport { OTLPExporterNodeConfigBase } from '.';\nimport { diag } from '@opentelemetry/api';\nimport { CompressionAlgorithm } from './types';\n\nlet gzip: zlib.Gzip | undefined;\n\n/**\n * Sends data using http\n * @param collector\n * @param data\n * @param contentType\n * @param onSuccess\n * @param onError\n */\nexport function sendWithHttp<ExportItem, ServiceRequest>(\n collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>,\n data: string | Buffer,\n contentType: string,\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n): void {\n const parsedUrl = new url.URL(collector.url);\n\n const options: http.RequestOptions | https.RequestOptions = {\n hostname: parsedUrl.hostname,\n port: parsedUrl.port,\n path: parsedUrl.pathname,\n method: 'POST',\n headers: {\n 'Content-Length': Buffer.byteLength(data),\n 'Content-Type': contentType,\n ...collector.headers,\n },\n agent: collector.agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const req = request(options, (res: http.IncomingMessage) => {\n let responseData = '';\n res.on('data', chunk => (responseData += chunk));\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n diag.debug(`statusCode: ${res.statusCode}`, responseData);\n onSuccess();\n } else {\n const error = new otlpTypes.OTLPExporterError(\n res.statusMessage,\n res.statusCode,\n responseData\n );\n onError(error);\n }\n });\n });\n\n\n req.on('error', (error: Error) => {\n onError(error);\n });\n\n switch (collector.compression) {\n case CompressionAlgorithm.GZIP: {\n if (!gzip) {\n gzip = zlib.createGzip();\n }\n req.setHeader('Content-Encoding', 'gzip');\n const dataStream = readableFromBuffer(data);\n dataStream.on('error', onError)\n .pipe(gzip).on('error', onError)\n .pipe(req);\n\n break;\n }\n default:\n req.write(data);\n req.end();\n\n break;\n }\n}\n\nfunction readableFromBuffer(buff: string | Buffer): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n config: OTLPExporterNodeConfigBase\n): http.Agent | https.Agent | undefined {\n if (config.httpAgentOptions && config.keepAlive === false) {\n diag.warn('httpAgentOptions is used only when keepAlive is true');\n return undefined;\n }\n\n if (config.keepAlive === false || !config.url) return undefined;\n\n try {\n const parsedUrl = new url.URL(config.url as string);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent({ keepAlive: true, ...config.httpAgentOptions });\n } catch (err) {\n diag.error(\n `collector exporter failed to create http agent. err: ${err.message}`\n );\n return undefined;\n }\n}\n"]}
|
package/build/src/util.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses headers from config leaving only those that have defined values
|
|
3
|
-
* @param partialHeaders
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseHeaders(partialHeaders?: Partial<Record<string, unknown>>): Record<string, string>;
|
|
6
|
-
export declare function appendResourcePathToUrlIfNotPresent(url: string, path: string): string;
|
|
7
|
-
//# sourceMappingURL=util.d.ts.map
|