@opentelemetry/otlp-exporter-base 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/LICENSE +201 -0
- package/README.md +42 -0
- package/build/src/OTLPExporterBase.d.ts +39 -0
- package/build/src/OTLPExporterBase.js +102 -0
- package/build/src/OTLPExporterBase.js.map +1 -0
- package/build/src/index.d.ts +5 -0
- package/build/src/index.js +32 -0
- package/build/src/index.js.map +1 -0
- package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +18 -0
- package/build/src/platform/browser/OTLPExporterBrowserBase.js +74 -0
- package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -0
- package/build/src/platform/browser/index.d.ts +2 -0
- package/build/src/platform/browser/index.js +29 -0
- package/build/src/platform/browser/index.js.map +1 -0
- package/build/src/platform/browser/util.d.ts +21 -0
- package/build/src/platform/browser/util.js +74 -0
- package/build/src/platform/browser/util.js.map +1 -0
- package/build/src/platform/index.d.ts +3 -0
- package/build/src/platform/index.js +32 -0
- package/build/src/platform/index.js.map +1 -0
- package/build/src/platform/node/OTLPExporterNodeBase.d.ts +20 -0
- package/build/src/platform/node/OTLPExporterNodeBase.js +62 -0
- package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -0
- package/build/src/platform/node/index.d.ts +4 -0
- package/build/src/platform/node/index.js +31 -0
- package/build/src/platform/node/index.js.map +1 -0
- package/build/src/platform/node/types.d.ts +17 -0
- package/build/src/platform/node/types.js +9 -0
- package/build/src/platform/node/types.js.map +1 -0
- package/build/src/platform/node/util.d.ts +19 -0
- package/build/src/platform/node/util.js +117 -0
- package/build/src/platform/node/util.js.map +1 -0
- package/build/src/types.d.ts +34 -0
- package/build/src/types.js +31 -0
- package/build/src/types.js.map +1 -0
- package/build/src/util.d.ts +7 -0
- package/build/src/util.js +43 -0
- package/build/src/util.js.map +1 -0
- package/build/src/version.d.ts +2 -0
- package/build/src/version.js +21 -0
- package/build/src/version.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendWithXhr = exports.sendWithBeacon = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright The OpenTelemetry Authors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const api_1 = require("@opentelemetry/api");
|
|
20
|
+
const types_1 = require("../../types");
|
|
21
|
+
/**
|
|
22
|
+
* Send metrics/spans using browser navigator.sendBeacon
|
|
23
|
+
* @param body
|
|
24
|
+
* @param url
|
|
25
|
+
* @param blobPropertyBag
|
|
26
|
+
* @param onSuccess
|
|
27
|
+
* @param onError
|
|
28
|
+
*/
|
|
29
|
+
function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
|
|
30
|
+
if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
|
|
31
|
+
api_1.diag.debug('sendBeacon - can send', body);
|
|
32
|
+
onSuccess();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const error = new types_1.OTLPExporterError(`sendBeacon - cannot send ${body}`);
|
|
36
|
+
onError(error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.sendWithBeacon = sendWithBeacon;
|
|
40
|
+
/**
|
|
41
|
+
* function to send metrics/spans using browser XMLHttpRequest
|
|
42
|
+
* used when navigator.sendBeacon is not available
|
|
43
|
+
* @param body
|
|
44
|
+
* @param url
|
|
45
|
+
* @param headers
|
|
46
|
+
* @param onSuccess
|
|
47
|
+
* @param onError
|
|
48
|
+
*/
|
|
49
|
+
function sendWithXhr(body, url, headers, onSuccess, onError) {
|
|
50
|
+
const xhr = new XMLHttpRequest();
|
|
51
|
+
xhr.open('POST', url);
|
|
52
|
+
const defaultHeaders = {
|
|
53
|
+
'Accept': 'application/json',
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
};
|
|
56
|
+
Object.entries(Object.assign(Object.assign({}, defaultHeaders), headers)).forEach(([k, v]) => {
|
|
57
|
+
xhr.setRequestHeader(k, v);
|
|
58
|
+
});
|
|
59
|
+
xhr.send(body);
|
|
60
|
+
xhr.onreadystatechange = () => {
|
|
61
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
62
|
+
if (xhr.status >= 200 && xhr.status <= 299) {
|
|
63
|
+
api_1.diag.debug('xhr success', body);
|
|
64
|
+
onSuccess();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const error = new types_1.OTLPExporterError(`Failed to export with XHR (status: ${xhr.status})`, xhr.status);
|
|
68
|
+
onError(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.sendWithXhr = sendWithXhr;
|
|
74
|
+
//# 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,4CAA0C;AAC1C,uCAAgD;AAEhD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,IAAY,EACZ,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAA2C;IAE3C,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAA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C;gBACF,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AAtCD,kCAsCC","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 onSuccess: () => void,\n onError: (error: 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 OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n onError(error);\n }\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.OTLPExporterBrowserBase = void 0;
|
|
14
|
+
/*
|
|
15
|
+
* Copyright The OpenTelemetry Authors
|
|
16
|
+
*
|
|
17
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
25
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
* See the License for the specific language governing permissions and
|
|
27
|
+
* limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
__exportStar(require("./node"), exports);
|
|
30
|
+
var browser_1 = require("./browser");
|
|
31
|
+
Object.defineProperty(exports, "OTLPExporterBrowserBase", { enumerable: true, get: function () { return browser_1.OTLPExporterBrowserBase; } });
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,yCAAuB;AACvB,qCAAoD;AAA3C,kHAAA,uBAAuB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './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,62 @@
|
|
|
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 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 OTLPExporterNodeBase extends OTLPExporterBase_1.OTLPExporterBase {
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
super(config);
|
|
30
|
+
this.DEFAULT_HEADERS = {};
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
if (config.metadata) {
|
|
33
|
+
api_1.diag.warn('Metadata cannot be set when using http');
|
|
34
|
+
}
|
|
35
|
+
this.headers = Object.assign(this.DEFAULT_HEADERS, (0, util_1.parseHeaders)(config.headers), core_1.baggageUtils.parseKeyPairsIntoRecord((0, core_1.getEnv)().OTEL_EXPORTER_OTLP_HEADERS));
|
|
36
|
+
this.agent = (0, util_2.createHttpAgent)(config);
|
|
37
|
+
this.compression = (0, util_2.configureCompression)(config.compression);
|
|
38
|
+
}
|
|
39
|
+
onInit(_config) { }
|
|
40
|
+
send(objects, onSuccess, onError) {
|
|
41
|
+
if (this._shutdownOnce.isCalled) {
|
|
42
|
+
api_1.diag.debug('Shutdown already started. Cannot send objects');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const serviceRequest = this.convert(objects);
|
|
46
|
+
const promise = new Promise((resolve, reject) => {
|
|
47
|
+
(0, util_2.sendWithHttp)(this, JSON.stringify(serviceRequest), 'application/json', resolve, reject);
|
|
48
|
+
})
|
|
49
|
+
.then(onSuccess, onError);
|
|
50
|
+
this._sendingPromises.push(promise);
|
|
51
|
+
const popPromise = () => {
|
|
52
|
+
const index = this._sendingPromises.indexOf(promise);
|
|
53
|
+
this._sendingPromises.splice(index, 1);
|
|
54
|
+
};
|
|
55
|
+
promise.then(popPromise, popPromise);
|
|
56
|
+
}
|
|
57
|
+
// TODO: end gzip stream from util.ts if not undefined
|
|
58
|
+
// It should perhaps be a class member here instead of a variable in util.ts
|
|
59
|
+
onShutdown() { }
|
|
60
|
+
}
|
|
61
|
+
exports.OTLPExporterNodeBase = OTLPExporterNodeBase;
|
|
62
|
+
//# 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,6DAA0D;AAG1D,qCAA0C;AAC1C,iCAA6E;AAC7E,4CAA0C;AAC1C,8CAA2D;AAE3D;;GAEG;AACH,MAAsB,oBAGpB,SAAQ,mCAIT;IAMC,YAAY,SAAq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BAAgB,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;AA/DD,oDA+DC","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,31 @@
|
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
__exportStar(require("./OTLPExporterNodeBase"), exports);
|
|
29
|
+
__exportStar(require("./util"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
//# 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,yDAAuC;AACvC,yCAAuB;AACvB,0CAAwB","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,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -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,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureCompression = 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 api_1 = require("@opentelemetry/api");
|
|
25
|
+
const types_1 = require("./types");
|
|
26
|
+
const core_1 = require("@opentelemetry/core");
|
|
27
|
+
const types_2 = require("../../types");
|
|
28
|
+
let gzip;
|
|
29
|
+
/**
|
|
30
|
+
* Sends data using http
|
|
31
|
+
* @param collector
|
|
32
|
+
* @param data
|
|
33
|
+
* @param contentType
|
|
34
|
+
* @param onSuccess
|
|
35
|
+
* @param onError
|
|
36
|
+
*/
|
|
37
|
+
function sendWithHttp(collector, data, contentType, onSuccess, onError) {
|
|
38
|
+
const parsedUrl = new url.URL(collector.url);
|
|
39
|
+
const options = {
|
|
40
|
+
hostname: parsedUrl.hostname,
|
|
41
|
+
port: parsedUrl.port,
|
|
42
|
+
path: parsedUrl.pathname,
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: Object.assign({ 'Content-Type': contentType }, collector.headers),
|
|
45
|
+
agent: collector.agent,
|
|
46
|
+
};
|
|
47
|
+
const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
|
|
48
|
+
const req = request(options, (res) => {
|
|
49
|
+
let responseData = '';
|
|
50
|
+
res.on('data', chunk => (responseData += chunk));
|
|
51
|
+
res.on('end', () => {
|
|
52
|
+
if (res.statusCode && res.statusCode < 299) {
|
|
53
|
+
api_1.diag.debug(`statusCode: ${res.statusCode}`, responseData);
|
|
54
|
+
onSuccess();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const error = new types_2.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
|
|
58
|
+
onError(error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
req.on('error', (error) => {
|
|
63
|
+
onError(error);
|
|
64
|
+
});
|
|
65
|
+
switch (collector.compression) {
|
|
66
|
+
case types_1.CompressionAlgorithm.GZIP: {
|
|
67
|
+
if (!gzip) {
|
|
68
|
+
gzip = zlib.createGzip();
|
|
69
|
+
}
|
|
70
|
+
req.setHeader('Content-Encoding', 'gzip');
|
|
71
|
+
const dataStream = readableFromBuffer(data);
|
|
72
|
+
dataStream.on('error', onError)
|
|
73
|
+
.pipe(gzip).on('error', onError)
|
|
74
|
+
.pipe(req);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
req.end(data);
|
|
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
|
+
function configureCompression(compression) {
|
|
108
|
+
if (compression) {
|
|
109
|
+
return compression;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const definedCompression = (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || (0, core_1.getEnv)().OTEL_EXPORTER_OTLP_COMPRESSION;
|
|
113
|
+
return definedCompression === types_1.CompressionAlgorithm.GZIP ? types_1.CompressionAlgorithm.GZIP : types_1.CompressionAlgorithm.NONE;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.configureCompression = configureCompression;
|
|
117
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/node/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,2BAA2B;AAC3B,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAAkC;AAGlC,4CAA0C;AAC1C,mCAA+C;AAC/C,8CAA6C;AAC7C,uCAAgD;AAEhD,IAAI,IAA2B,CAAC;AAEhC;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IAE3C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE7C,MAAM,OAAO,GAA+C;QAC1D,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,QAAQ;QACxB,MAAM,EAAE,MAAM;QACd,OAAO,kBACL,cAAc,EAAE,WAAW,IACxB,SAAS,CAAC,OAAO,CACrB;QACD,KAAK,EAAE,SAAS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CAAC;KAClB;AACH,CAAC;AApBD,0CAoBC;AAED,SAAgB,oBAAoB,CAAC,WAA6C;IAChF,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,MAAM,kBAAkB,GAAG,IAAA,aAAM,GAAE,CAAC,qCAAqC,IAAI,IAAA,aAAM,GAAE,CAAC,8BAA8B,CAAC;QACrH,OAAO,kBAAkB,KAAK,4BAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,4BAAoB,CAAC,IAAI,CAAC;KACjH;AACH,CAAC;AAPD,oDAOC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as url from 'url';\nimport * as http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nimport { OTLPExporterNodeConfigBase } from '.';\nimport { diag } from '@opentelemetry/api';\nimport { CompressionAlgorithm } from './types';\nimport { getEnv } from '@opentelemetry/core';\nimport { OTLPExporterError } from '../../types';\n\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: 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-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 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.end(data);\n break;\n }\n}\n\nfunction readableFromBuffer(buff: string | Buffer): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n config: OTLPExporterNodeConfigBase\n): http.Agent | https.Agent | undefined {\n if (config.httpAgentOptions && config.keepAlive === false) {\n diag.warn('httpAgentOptions is used only when keepAlive is true');\n return undefined;\n }\n\n if (config.keepAlive === false || !config.url) return undefined;\n\n try {\n const parsedUrl = new url.URL(config.url as string);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent({ keepAlive: true, ...config.httpAgentOptions });\n } catch (err) {\n diag.error(\n `collector exporter failed to create http agent. err: ${err.message}`\n );\n return undefined;\n }\n}\n\nexport function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm {\n if (compression) {\n return compression;\n } else {\n const definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;\n return definedCompression === CompressionAlgorithm.GZIP ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE;\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SpanAttributes } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for handling error
|
|
4
|
+
*/
|
|
5
|
+
export declare class OTLPExporterError extends Error {
|
|
6
|
+
readonly code?: number;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly data?: string;
|
|
9
|
+
constructor(message?: string, code?: number, data?: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface for handling export service errors
|
|
13
|
+
*/
|
|
14
|
+
export interface ExportServiceError {
|
|
15
|
+
name: string;
|
|
16
|
+
code: number;
|
|
17
|
+
details: string;
|
|
18
|
+
metadata: {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
message: string;
|
|
22
|
+
stack: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Collector Exporter base config
|
|
26
|
+
*/
|
|
27
|
+
export interface OTLPExporterConfigBase {
|
|
28
|
+
headers?: Partial<Record<string, unknown>>;
|
|
29
|
+
hostname?: string;
|
|
30
|
+
attributes?: SpanAttributes;
|
|
31
|
+
url?: string;
|
|
32
|
+
concurrencyLimit?: number;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
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.OTLPExporterError = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Interface for handling error
|
|
21
|
+
*/
|
|
22
|
+
class OTLPExporterError extends Error {
|
|
23
|
+
constructor(message, code, data) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'OTLPExporterError';
|
|
26
|
+
this.data = data;
|
|
27
|
+
this.code = code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.OTLPExporterError = OTLPExporterError;
|
|
31
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAK1C,YAAY,OAAgB,EAAE,IAAa,EAAE,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAW,mBAAmB,CAAC;QAKnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,8CAUC","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 } from '@opentelemetry/api';\n\n/**\n * Interface for handling error\n */\nexport class OTLPExporterError extends Error {\n readonly code?: number;\n override readonly name: string = 'OTLPExporterError';\n readonly data?: string;\n\n constructor(message?: string, code?: number, data?: string) {\n super(message);\n this.data = data;\n this.code = code;\n }\n}\n\n/**\n * Interface for handling export service errors\n */\nexport interface ExportServiceError {\n name: string;\n code: number;\n details: string;\n metadata: { [key: string]: unknown };\n message: string;\n stack: string;\n}\n\n/**\n * Collector Exporter base config\n */\nexport interface OTLPExporterConfigBase {\n headers?: Partial<Record<string, unknown>>;\n hostname?: string;\n attributes?: SpanAttributes;\n url?: string;\n concurrencyLimit?: number;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1,43 @@
|
|
|
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.appendResourcePathToUrlIfNotPresent = exports.parseHeaders = void 0;
|
|
19
|
+
const api_1 = require("@opentelemetry/api");
|
|
20
|
+
/**
|
|
21
|
+
* Parses headers from config leaving only those that have defined values
|
|
22
|
+
* @param partialHeaders
|
|
23
|
+
*/
|
|
24
|
+
function parseHeaders(partialHeaders = {}) {
|
|
25
|
+
const headers = {};
|
|
26
|
+
Object.entries(partialHeaders).forEach(([key, value]) => {
|
|
27
|
+
if (typeof value !== 'undefined') {
|
|
28
|
+
headers[key] = String(value);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
api_1.diag.warn(`Header "${key}" has wrong value and will be ignored`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return headers;
|
|
35
|
+
}
|
|
36
|
+
exports.parseHeaders = parseHeaders;
|
|
37
|
+
function appendResourcePathToUrlIfNotPresent(url, path) {
|
|
38
|
+
if (url.match(/v\d\/(traces|metrics)$/))
|
|
39
|
+
return url;
|
|
40
|
+
return url + path;
|
|
41
|
+
}
|
|
42
|
+
exports.appendResourcePathToUrlIfNotPresent = appendResourcePathToUrlIfNotPresent;
|
|
43
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAE1C;;;GAGG;AACH,SAAgB,YAAY,CAC1B,iBAAmD,EAAE;IAErD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACtD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;SAC9B;aAAM;YACL,UAAI,CAAC,IAAI,CAAC,WAAW,GAAG,uCAAuC,CAAC,CAAC;SAClE;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAZD,oCAYC;AAED,SAAgB,mCAAmC,CAAC,GAAW,EAAE,IAAY;IAC3E,IAAI,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC;QAAE,OAAO,GAAG,CAAC;IAEpD,OAAO,GAAG,GAAG,IAAI,CAAC;AACpB,CAAC;AAJD,kFAIC","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';\n\n/**\n * Parses headers from config leaving only those that have defined values\n * @param partialHeaders\n */\nexport function parseHeaders(\n partialHeaders: Partial<Record<string, unknown>> = {}\n): Record<string, string> {\n const headers: Record<string, string> = {};\n Object.entries(partialHeaders).forEach(([key, value]) => {\n if (typeof value !== 'undefined') {\n headers[key] = String(value);\n } else {\n diag.warn(`Header \"${key}\" has wrong value and will be ignored`);\n }\n });\n return headers;\n}\n\nexport function appendResourcePathToUrlIfNotPresent(url: string, path: string): string {\n if (url.match(/v\\d\\/(traces|metrics)$/)) return url;\n\n return url + path;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
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.VERSION = void 0;
|
|
19
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
20
|
+
exports.VERSION = '0.28.0';
|
|
21
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.28.0';\n"]}
|