@opentelemetry/exporter-trace-otlp-http 0.27.0 → 0.29.1

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.
Files changed (119) hide show
  1. package/README.md +47 -21
  2. package/build/esm/index.d.ts +0 -4
  3. package/build/esm/index.js +0 -5
  4. package/build/esm/index.js.map +1 -1
  5. package/build/esm/platform/browser/OTLPTraceExporter.d.ts +4 -5
  6. package/build/esm/platform/browser/OTLPTraceExporter.js +7 -8
  7. package/build/esm/platform/browser/OTLPTraceExporter.js.map +1 -1
  8. package/build/esm/platform/browser/index.d.ts +0 -1
  9. package/build/esm/platform/browser/index.js +0 -1
  10. package/build/esm/platform/browser/index.js.map +1 -1
  11. package/build/esm/platform/index.d.ts +0 -1
  12. package/build/esm/platform/index.js +0 -1
  13. package/build/esm/platform/index.js.map +1 -1
  14. package/build/esm/platform/node/OTLPTraceExporter.d.ts +5 -5
  15. package/build/esm/platform/node/OTLPTraceExporter.js +8 -8
  16. package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
  17. package/build/esm/platform/node/index.d.ts +0 -3
  18. package/build/esm/platform/node/index.js +0 -3
  19. package/build/esm/platform/node/index.js.map +1 -1
  20. package/build/esm/version.d.ts +1 -1
  21. package/build/esm/version.js +1 -1
  22. package/build/esm/version.js.map +1 -1
  23. package/build/esnext/index.d.ts +2 -0
  24. package/build/esnext/index.js +17 -0
  25. package/build/esnext/index.js.map +1 -0
  26. package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +12 -0
  27. package/build/esnext/platform/browser/OTLPTraceExporter.js +42 -0
  28. package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -0
  29. package/build/esnext/platform/browser/index.d.ts +2 -0
  30. package/build/esnext/platform/browser/index.js +17 -0
  31. package/build/esnext/platform/browser/index.js.map +1 -0
  32. package/build/esnext/platform/index.d.ts +2 -0
  33. package/build/esnext/platform/index.js +17 -0
  34. package/build/esnext/platform/index.js.map +1 -0
  35. package/build/esnext/platform/node/OTLPTraceExporter.d.ts +13 -0
  36. package/build/esnext/platform/node/OTLPTraceExporter.js +43 -0
  37. package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -0
  38. package/build/esnext/platform/node/index.d.ts +2 -0
  39. package/build/esnext/platform/node/index.js +17 -0
  40. package/build/esnext/platform/node/index.js.map +1 -0
  41. package/build/esnext/version.d.ts +2 -0
  42. package/build/esnext/version.js +18 -0
  43. package/build/esnext/version.js.map +1 -0
  44. package/build/src/index.d.ts +0 -4
  45. package/build/src/index.js +0 -8
  46. package/build/src/index.js.map +1 -1
  47. package/build/src/platform/browser/OTLPTraceExporter.d.ts +4 -5
  48. package/build/src/platform/browser/OTLPTraceExporter.js +11 -12
  49. package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
  50. package/build/src/platform/browser/index.d.ts +0 -1
  51. package/build/src/platform/browser/index.js +0 -1
  52. package/build/src/platform/browser/index.js.map +1 -1
  53. package/build/src/platform/index.d.ts +0 -1
  54. package/build/src/platform/index.js +0 -3
  55. package/build/src/platform/index.js.map +1 -1
  56. package/build/src/platform/node/OTLPTraceExporter.d.ts +5 -5
  57. package/build/src/platform/node/OTLPTraceExporter.js +12 -12
  58. package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
  59. package/build/src/platform/node/index.d.ts +0 -3
  60. package/build/src/platform/node/index.js +0 -3
  61. package/build/src/platform/node/index.js.map +1 -1
  62. package/build/src/version.d.ts +1 -1
  63. package/build/src/version.js +1 -1
  64. package/build/src/version.js.map +1 -1
  65. package/package.json +32 -22
  66. package/build/esm/OTLPExporterBase.d.ts +0 -36
  67. package/build/esm/OTLPExporterBase.js +0 -114
  68. package/build/esm/OTLPExporterBase.js.map +0 -1
  69. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  70. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +0 -91
  71. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  72. package/build/esm/platform/browser/util.d.ts +0 -17
  73. package/build/esm/platform/browser/util.js +0 -77
  74. package/build/esm/platform/browser/util.js.map +0 -1
  75. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  76. package/build/esm/platform/node/OTLPExporterNodeBase.js +0 -82
  77. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +0 -1
  78. package/build/esm/platform/node/types.d.ts +0 -17
  79. package/build/esm/platform/node/types.js +0 -6
  80. package/build/esm/platform/node/types.js.map +0 -1
  81. package/build/esm/platform/node/util.d.ts +0 -17
  82. package/build/esm/platform/node/util.js +0 -113
  83. package/build/esm/platform/node/util.js.map +0 -1
  84. package/build/esm/transform.d.ts +0 -80
  85. package/build/esm/transform.js +0 -271
  86. package/build/esm/transform.js.map +0 -1
  87. package/build/esm/types.d.ts +0 -241
  88. package/build/esm/types.js +0 -176
  89. package/build/esm/types.js.map +0 -1
  90. package/build/esm/util.d.ts +0 -7
  91. package/build/esm/util.js +0 -40
  92. package/build/esm/util.js.map +0 -1
  93. package/build/src/OTLPExporterBase.d.ts +0 -36
  94. package/build/src/OTLPExporterBase.js +0 -113
  95. package/build/src/OTLPExporterBase.js.map +0 -1
  96. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  97. package/build/src/platform/browser/OTLPExporterBrowserBase.js +0 -74
  98. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  99. package/build/src/platform/browser/util.d.ts +0 -17
  100. package/build/src/platform/browser/util.js +0 -70
  101. package/build/src/platform/browser/util.js.map +0 -1
  102. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  103. package/build/src/platform/node/OTLPExporterNodeBase.js +0 -65
  104. package/build/src/platform/node/OTLPExporterNodeBase.js.map +0 -1
  105. package/build/src/platform/node/types.d.ts +0 -17
  106. package/build/src/platform/node/types.js +0 -9
  107. package/build/src/platform/node/types.js.map +0 -1
  108. package/build/src/platform/node/util.d.ts +0 -17
  109. package/build/src/platform/node/util.js +0 -107
  110. package/build/src/platform/node/util.js.map +0 -1
  111. package/build/src/transform.d.ts +0 -80
  112. package/build/src/transform.js +0 -282
  113. package/build/src/transform.js.map +0 -1
  114. package/build/src/types.d.ts +0 -241
  115. package/build/src/types.js +0 -160
  116. package/build/src/types.js.map +0 -1
  117. package/build/src/util.d.ts +0 -7
  118. package/build/src/util.js +0 -43
  119. package/build/src/util.js.map +0 -1
@@ -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/OTLPExporterNode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P,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":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,2BAA2B;AAC3B,6BAA6B;AAC7B,+BAA+B;AAC/B,6BAA6B;AAC7B,mCAA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AAK,EAAE;QACzD,UAAI,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;QAClE,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAEhE,IAAI;QACF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAa,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;QACxE,OAAO,IAAI,KAAK,iBAAG,SAAS,EAAE,IAAI,IAAK,MAAM,CAAC,gBAAgB,EAAG,CAAC;KACnE;IAAC,OAAO,GAAG,EAAE;QACZ,UAAI,CAAC,KAAK,CACR,wDAAwD,GAAG,CAAC,OAAO,EAAE,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AApBD,0CAoBC","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"]}
@@ -1,80 +0,0 @@
1
- import { SpanAttributes, SpanKind, SpanStatus, TraceState } from '@opentelemetry/api';
2
- import * as core from '@opentelemetry/core';
3
- import { Resource } from '@opentelemetry/resources';
4
- import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
5
- import { OTLPExporterBase } from './OTLPExporterBase';
6
- import { opentelemetryProto, OTLPExporterConfigBase } from './types';
7
- /**
8
- * Converts attributes to KeyValue array
9
- * @param attributes
10
- */
11
- export declare function toCollectorAttributes(attributes: SpanAttributes): opentelemetryProto.common.v1.KeyValue[];
12
- /**
13
- * Converts array of unknown value to ArrayValue
14
- * @param values
15
- */
16
- export declare function toCollectorArrayValue(values: unknown[]): opentelemetryProto.common.v1.ArrayValue;
17
- /**
18
- * Converts attributes to KeyValueList
19
- * @param attributes
20
- */
21
- export declare function toCollectorKeyValueList(attributes: SpanAttributes): opentelemetryProto.common.v1.KeyValueList;
22
- /**
23
- * Converts key and unknown value to KeyValue
24
- * @param value event value
25
- */
26
- export declare function toCollectorAttributeKeyValue(key: string, value: unknown): opentelemetryProto.common.v1.KeyValue;
27
- /**
28
- * Converts unknown value to AnyValue
29
- * @param value
30
- */
31
- export declare function toCollectorAnyValue(value: unknown): opentelemetryProto.common.v1.AnyValue;
32
- /**
33
- *
34
- * Converts events
35
- * @param events array of events
36
- */
37
- export declare function toCollectorEvents(timedEvents: TimedEvent[]): opentelemetryProto.trace.v1.Span.Event[];
38
- /**
39
- * Converts span
40
- * @param span
41
- * @param useHex - if ids should be kept as hex without converting to base64
42
- */
43
- export declare function toCollectorSpan(span: ReadableSpan, useHex?: boolean): opentelemetryProto.trace.v1.Span;
44
- /**
45
- * Converts status
46
- * @param status
47
- */
48
- export declare function toCollectorStatus(status: SpanStatus): opentelemetryProto.trace.v1.SpanStatus;
49
- /**
50
- * Converts resource
51
- * @param resource
52
- * @param additionalAttributes
53
- */
54
- export declare function toCollectorResource(resource?: Resource, additionalAttributes?: {
55
- [key: string]: unknown;
56
- }): opentelemetryProto.resource.v1.Resource;
57
- /**
58
- * Converts span kind
59
- * @param kind
60
- */
61
- export declare function toCollectorKind(kind: SpanKind): opentelemetryProto.trace.v1.Span.SpanKind;
62
- /**
63
- * Converts traceState
64
- * @param traceState
65
- */
66
- export declare function toCollectorTraceState(traceState?: TraceState): opentelemetryProto.trace.v1.Span.TraceState | undefined;
67
- /**
68
- * Prepares trace service request to be sent to collector
69
- * @param spans spans
70
- * @param collectorExporterBase
71
- * @param useHex - if ids should be kept as hex without converting to base64
72
- */
73
- export declare function toOTLPExportTraceServiceRequest<T extends OTLPExporterConfigBase>(spans: ReadableSpan[], collectorTraceExporterBase: OTLPExporterBase<T, ReadableSpan, opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>, useHex?: boolean): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest;
74
- /**
75
- * Takes an array of spans and groups them by resource and instrumentation
76
- * library
77
- * @param spans spans
78
- */
79
- export declare function groupSpansByResourceAndLibrary(spans: ReadableSpan[]): Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>;
80
- //# sourceMappingURL=transform.d.ts.map
@@ -1,282 +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.groupSpansByResourceAndLibrary = exports.toOTLPExportTraceServiceRequest = exports.toCollectorTraceState = exports.toCollectorKind = exports.toCollectorResource = exports.toCollectorStatus = exports.toCollectorSpan = exports.toCollectorEvents = exports.toCollectorAnyValue = exports.toCollectorAttributeKeyValue = exports.toCollectorKeyValueList = exports.toCollectorArrayValue = exports.toCollectorAttributes = void 0;
19
- const core = require("@opentelemetry/core");
20
- const types_1 = require("./types");
21
- const MAX_INTEGER_VALUE = 2147483647;
22
- const MIN_INTEGER_VALUE = -2147483648;
23
- /**
24
- * Converts attributes to KeyValue array
25
- * @param attributes
26
- */
27
- function toCollectorAttributes(attributes) {
28
- return Object.keys(attributes).map(key => {
29
- return toCollectorAttributeKeyValue(key, attributes[key]);
30
- });
31
- }
32
- exports.toCollectorAttributes = toCollectorAttributes;
33
- /**
34
- * Converts array of unknown value to ArrayValue
35
- * @param values
36
- */
37
- function toCollectorArrayValue(values) {
38
- return {
39
- values: values.map(value => toCollectorAnyValue(value)),
40
- };
41
- }
42
- exports.toCollectorArrayValue = toCollectorArrayValue;
43
- /**
44
- * Converts attributes to KeyValueList
45
- * @param attributes
46
- */
47
- function toCollectorKeyValueList(attributes) {
48
- return {
49
- values: toCollectorAttributes(attributes),
50
- };
51
- }
52
- exports.toCollectorKeyValueList = toCollectorKeyValueList;
53
- /**
54
- * Converts key and unknown value to KeyValue
55
- * @param value event value
56
- */
57
- function toCollectorAttributeKeyValue(key, value) {
58
- const anyValue = toCollectorAnyValue(value);
59
- return {
60
- key,
61
- value: anyValue,
62
- };
63
- }
64
- exports.toCollectorAttributeKeyValue = toCollectorAttributeKeyValue;
65
- /**
66
- * Converts unknown value to AnyValue
67
- * @param value
68
- */
69
- function toCollectorAnyValue(value) {
70
- const anyValue = {};
71
- if (typeof value === 'string') {
72
- anyValue.stringValue = value;
73
- }
74
- else if (typeof value === 'boolean') {
75
- anyValue.boolValue = value;
76
- }
77
- else if (typeof value === 'number' &&
78
- value <= MAX_INTEGER_VALUE &&
79
- value >= MIN_INTEGER_VALUE &&
80
- Number.isInteger(value)) {
81
- anyValue.intValue = value;
82
- }
83
- else if (typeof value === 'number') {
84
- anyValue.doubleValue = value;
85
- }
86
- else if (Array.isArray(value)) {
87
- anyValue.arrayValue = toCollectorArrayValue(value);
88
- }
89
- else if (value) {
90
- anyValue.kvlistValue = toCollectorKeyValueList(value);
91
- }
92
- return anyValue;
93
- }
94
- exports.toCollectorAnyValue = toCollectorAnyValue;
95
- /**
96
- *
97
- * Converts events
98
- * @param events array of events
99
- */
100
- function toCollectorEvents(timedEvents) {
101
- return timedEvents.map(timedEvent => {
102
- const timeUnixNano = core.hrTimeToNanoseconds(timedEvent.time);
103
- const name = timedEvent.name;
104
- const attributes = toCollectorAttributes(timedEvent.attributes || {});
105
- const droppedAttributesCount = 0;
106
- const protoEvent = {
107
- timeUnixNano,
108
- name,
109
- attributes,
110
- droppedAttributesCount,
111
- };
112
- return protoEvent;
113
- });
114
- }
115
- exports.toCollectorEvents = toCollectorEvents;
116
- /**
117
- * Converts links
118
- * @param span
119
- * @param useHex - if ids should be kept as hex without converting to base64
120
- */
121
- function toCollectorLinks(span, useHex) {
122
- return span.links.map((link) => {
123
- const protoLink = {
124
- traceId: useHex
125
- ? link.context.traceId
126
- : core.hexToBase64(link.context.traceId),
127
- spanId: useHex
128
- ? link.context.spanId
129
- : core.hexToBase64(link.context.spanId),
130
- attributes: toCollectorAttributes(link.attributes || {}),
131
- droppedAttributesCount: 0,
132
- };
133
- return protoLink;
134
- });
135
- }
136
- /**
137
- * Converts span
138
- * @param span
139
- * @param useHex - if ids should be kept as hex without converting to base64
140
- */
141
- function toCollectorSpan(span, useHex) {
142
- return {
143
- traceId: useHex
144
- ? span.spanContext().traceId
145
- : core.hexToBase64(span.spanContext().traceId),
146
- spanId: useHex
147
- ? span.spanContext().spanId
148
- : core.hexToBase64(span.spanContext().spanId),
149
- parentSpanId: span.parentSpanId
150
- ? useHex
151
- ? span.parentSpanId
152
- : core.hexToBase64(span.parentSpanId)
153
- : undefined,
154
- traceState: toCollectorTraceState(span.spanContext().traceState),
155
- name: span.name,
156
- kind: toCollectorKind(span.kind),
157
- startTimeUnixNano: core.hrTimeToNanoseconds(span.startTime),
158
- endTimeUnixNano: core.hrTimeToNanoseconds(span.endTime),
159
- attributes: toCollectorAttributes(span.attributes),
160
- droppedAttributesCount: 0,
161
- events: toCollectorEvents(span.events),
162
- droppedEventsCount: 0,
163
- status: toCollectorStatus(span.status),
164
- links: toCollectorLinks(span, useHex),
165
- droppedLinksCount: 0,
166
- };
167
- }
168
- exports.toCollectorSpan = toCollectorSpan;
169
- /**
170
- * Converts status
171
- * @param status
172
- */
173
- function toCollectorStatus(status) {
174
- const spanStatus = {
175
- code: status.code,
176
- };
177
- if (typeof status.message !== 'undefined') {
178
- spanStatus.message = status.message;
179
- }
180
- return spanStatus;
181
- }
182
- exports.toCollectorStatus = toCollectorStatus;
183
- /**
184
- * Converts resource
185
- * @param resource
186
- * @param additionalAttributes
187
- */
188
- function toCollectorResource(resource, additionalAttributes = {}) {
189
- const attr = Object.assign({}, additionalAttributes, resource ? resource.attributes : {});
190
- const resourceProto = {
191
- attributes: toCollectorAttributes(attr),
192
- droppedAttributesCount: 0,
193
- };
194
- return resourceProto;
195
- }
196
- exports.toCollectorResource = toCollectorResource;
197
- /**
198
- * Converts span kind
199
- * @param kind
200
- */
201
- function toCollectorKind(kind) {
202
- const collectorKind = types_1.OTLP_SPAN_KIND_MAPPING[kind];
203
- return typeof collectorKind === 'number'
204
- ? collectorKind
205
- : types_1.opentelemetryProto.trace.v1.Span.SpanKind.SPAN_KIND_UNSPECIFIED;
206
- }
207
- exports.toCollectorKind = toCollectorKind;
208
- /**
209
- * Converts traceState
210
- * @param traceState
211
- */
212
- function toCollectorTraceState(traceState) {
213
- if (!traceState)
214
- return undefined;
215
- return traceState.serialize();
216
- }
217
- exports.toCollectorTraceState = toCollectorTraceState;
218
- /**
219
- * Prepares trace service request to be sent to collector
220
- * @param spans spans
221
- * @param collectorExporterBase
222
- * @param useHex - if ids should be kept as hex without converting to base64
223
- */
224
- function toOTLPExportTraceServiceRequest(spans, collectorTraceExporterBase, useHex) {
225
- const groupedSpans = groupSpansByResourceAndLibrary(spans);
226
- const additionalAttributes = Object.assign({}, collectorTraceExporterBase.attributes);
227
- return {
228
- resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes, useHex),
229
- };
230
- }
231
- exports.toOTLPExportTraceServiceRequest = toOTLPExportTraceServiceRequest;
232
- /**
233
- * Takes an array of spans and groups them by resource and instrumentation
234
- * library
235
- * @param spans spans
236
- */
237
- function groupSpansByResourceAndLibrary(spans) {
238
- return spans.reduce((spanMap, span) => {
239
- //group by resource
240
- let resourceSpans = spanMap.get(span.resource);
241
- if (!resourceSpans) {
242
- resourceSpans = new Map();
243
- spanMap.set(span.resource, resourceSpans);
244
- }
245
- //group by instrumentation library
246
- let libSpans = resourceSpans.get(span.instrumentationLibrary);
247
- if (!libSpans) {
248
- libSpans = new Array();
249
- resourceSpans.set(span.instrumentationLibrary, libSpans);
250
- }
251
- libSpans.push(span);
252
- return spanMap;
253
- }, new Map());
254
- }
255
- exports.groupSpansByResourceAndLibrary = groupSpansByResourceAndLibrary;
256
- /**
257
- * Convert to InstrumentationLibrarySpans
258
- * @param instrumentationLibrary
259
- * @param spans
260
- * @param useHex - if ids should be kept as hex without converting to base64
261
- */
262
- function toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex) {
263
- return {
264
- spans: spans.map(span => toCollectorSpan(span, useHex)),
265
- instrumentationLibrary,
266
- };
267
- }
268
- /**
269
- * Returns a list of resource spans which will be exported to the collector
270
- * @param groupedSpans
271
- * @param baseAttributes
272
- * @param useHex - if ids should be kept as hex without converting to base64
273
- */
274
- function toCollectorResourceSpans(groupedSpans, baseAttributes, useHex) {
275
- return Array.from(groupedSpans, ([resource, libSpans]) => {
276
- return {
277
- resource: toCollectorResource(resource, baseAttributes),
278
- instrumentationLibrarySpans: Array.from(libSpans, ([instrumentationLibrary, spans]) => toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans, useHex)),
279
- };
280
- });
281
- }
282
- //# sourceMappingURL=transform.js.map