@opentelemetry/otlp-exporter-base 0.28.0 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/build/esm/OTLPExporterBase.d.ts +38 -0
  2. package/build/esm/OTLPExporterBase.js +103 -0
  3. package/build/esm/OTLPExporterBase.js.map +1 -0
  4. package/build/esm/index.d.ts +5 -0
  5. package/build/esm/index.js +20 -0
  6. package/build/esm/index.js.map +1 -0
  7. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +18 -0
  8. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +91 -0
  9. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -0
  10. package/build/esm/platform/browser/index.d.ts +2 -0
  11. package/build/esm/platform/browser/index.js +17 -0
  12. package/build/esm/platform/browser/index.js.map +1 -0
  13. package/build/esm/platform/browser/util.d.ts +21 -0
  14. package/build/esm/platform/browser/util.js +108 -0
  15. package/build/esm/platform/browser/util.js.map +1 -0
  16. package/build/esm/platform/index.d.ts +3 -0
  17. package/build/esm/platform/index.js +18 -0
  18. package/build/esm/platform/index.js.map +1 -0
  19. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +20 -0
  20. package/build/esm/platform/node/OTLPExporterNodeBase.js +79 -0
  21. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -0
  22. package/build/esm/platform/node/index.d.ts +4 -0
  23. package/build/esm/platform/node/index.js +19 -0
  24. package/build/esm/platform/node/index.js.map +1 -0
  25. package/build/esm/platform/node/types.d.ts +17 -0
  26. package/build/esm/platform/node/types.js +6 -0
  27. package/build/esm/platform/node/types.js.map +1 -0
  28. package/build/esm/platform/node/util.d.ts +19 -0
  29. package/build/esm/platform/node/util.js +151 -0
  30. package/build/esm/platform/node/util.js.map +1 -0
  31. package/build/esm/types.d.ts +35 -0
  32. package/build/esm/types.js +46 -0
  33. package/build/esm/types.js.map +1 -0
  34. package/build/esm/util.d.ts +27 -0
  35. package/build/esm/util.js +110 -0
  36. package/build/esm/util.js.map +1 -0
  37. package/build/esm/version.d.ts +2 -0
  38. package/build/esm/version.js +18 -0
  39. package/build/esm/version.js.map +1 -0
  40. package/build/esnext/OTLPExporterBase.d.ts +38 -0
  41. package/build/esnext/OTLPExporterBase.js +99 -0
  42. package/build/esnext/OTLPExporterBase.js.map +1 -0
  43. package/build/esnext/index.d.ts +5 -0
  44. package/build/esnext/index.js +20 -0
  45. package/build/esnext/index.js.map +1 -0
  46. package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +18 -0
  47. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +70 -0
  48. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -0
  49. package/build/esnext/platform/browser/index.d.ts +2 -0
  50. package/build/esnext/platform/browser/index.js +17 -0
  51. package/build/esnext/platform/browser/index.js.map +1 -0
  52. package/build/esnext/platform/browser/util.d.ts +21 -0
  53. package/build/esnext/platform/browser/util.js +80 -0
  54. package/build/esnext/platform/browser/util.js.map +1 -0
  55. package/build/esnext/platform/index.d.ts +3 -0
  56. package/build/esnext/platform/index.js +18 -0
  57. package/build/esnext/platform/index.js.map +1 -0
  58. package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +20 -0
  59. package/build/esnext/platform/node/OTLPExporterNodeBase.js +58 -0
  60. package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -0
  61. package/build/esnext/platform/node/index.d.ts +4 -0
  62. package/build/esnext/platform/node/index.js +19 -0
  63. package/build/esnext/platform/node/index.js.map +1 -0
  64. package/build/esnext/platform/node/types.d.ts +17 -0
  65. package/build/esnext/platform/node/types.js +6 -0
  66. package/build/esnext/platform/node/types.js.map +1 -0
  67. package/build/esnext/platform/node/util.d.ts +19 -0
  68. package/build/esnext/platform/node/util.js +140 -0
  69. package/build/esnext/platform/node/util.js.map +1 -0
  70. package/build/esnext/types.d.ts +35 -0
  71. package/build/esnext/types.js +27 -0
  72. package/build/esnext/types.js.map +1 -0
  73. package/build/esnext/util.d.ts +27 -0
  74. package/build/esnext/util.js +92 -0
  75. package/build/esnext/util.js.map +1 -0
  76. package/build/esnext/version.d.ts +2 -0
  77. package/build/esnext/version.js +18 -0
  78. package/build/esnext/version.js.map +1 -0
  79. package/build/src/OTLPExporterBase.d.ts +1 -2
  80. package/build/src/OTLPExporterBase.js +2 -1
  81. package/build/src/OTLPExporterBase.js.map +1 -1
  82. package/build/src/platform/browser/OTLPExporterBrowserBase.js +1 -1
  83. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  84. package/build/src/platform/browser/util.d.ts +1 -1
  85. package/build/src/platform/browser/util.js +12 -1
  86. package/build/src/platform/browser/util.js.map +1 -1
  87. package/build/src/platform/node/util.js +37 -8
  88. package/build/src/platform/node/util.js.map +1 -1
  89. package/build/src/types.d.ts +3 -2
  90. package/build/src/types.js.map +1 -1
  91. package/build/src/util.d.ts +21 -1
  92. package/build/src/util.js +62 -5
  93. package/build/src/util.js.map +1 -1
  94. package/build/src/version.d.ts +1 -1
  95. package/build/src/version.js +1 -1
  96. package/build/src/version.js.map +1 -1
  97. package/package.json +10 -4
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './OTLPExporterNodeBase';
17
+ export * from './util';
18
+ export * from './types';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './OTLPExporterNodeBase';\nexport * from './util';\nexport * from './types';\n"]}
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import type * as http from 'http';
3
+ import type * as https from 'https';
4
+ import { OTLPExporterConfigBase } from '../../types';
5
+ /**
6
+ * Collector Exporter node base config
7
+ */
8
+ export interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {
9
+ keepAlive?: boolean;
10
+ compression?: CompressionAlgorithm;
11
+ httpAgentOptions?: http.AgentOptions | https.AgentOptions;
12
+ }
13
+ export declare enum CompressionAlgorithm {
14
+ NONE = "none",
15
+ GZIP = "gzip"
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,6 @@
1
+ export var CompressionAlgorithm;
2
+ (function (CompressionAlgorithm) {
3
+ CompressionAlgorithm["NONE"] = "none";
4
+ CompressionAlgorithm["GZIP"] = "gzip";
5
+ })(CompressionAlgorithm || (CompressionAlgorithm = {}));
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/platform/node/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type * as http from 'http';\nimport type * as https from 'https';\n\nimport { OTLPExporterConfigBase } from '../../types';\n\n/**\n * Collector Exporter node base config\n */\nexport interface OTLPExporterNodeConfigBase\n extends OTLPExporterConfigBase {\n keepAlive?: boolean;\n compression?: CompressionAlgorithm;\n httpAgentOptions?: http.AgentOptions | https.AgentOptions;\n}\n\nexport enum CompressionAlgorithm {\n NONE = 'none',\n GZIP = 'gzip'\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import * as https from 'https';
4
+ import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
5
+ import { OTLPExporterNodeConfigBase } from '.';
6
+ import { CompressionAlgorithm } from './types';
7
+ import { OTLPExporterError } from '../../types';
8
+ /**
9
+ * Sends data using http
10
+ * @param collector
11
+ * @param data
12
+ * @param contentType
13
+ * @param onSuccess
14
+ * @param onError
15
+ */
16
+ export declare function sendWithHttp<ExportItem, ServiceRequest>(collector: OTLPExporterNodeBase<ExportItem, ServiceRequest>, data: string | Buffer, contentType: string, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
17
+ export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
18
+ export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
19
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,151 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ /*
13
+ * Copyright The OpenTelemetry Authors
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * https://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ import * as url from 'url';
28
+ import * as http from 'http';
29
+ import * as https from 'https';
30
+ import * as zlib from 'zlib';
31
+ import { Readable } from 'stream';
32
+ import { diag } from '@opentelemetry/api';
33
+ import { CompressionAlgorithm } from './types';
34
+ import { getEnv } from '@opentelemetry/core';
35
+ import { OTLPExporterError } from '../../types';
36
+ var gzip;
37
+ /**
38
+ * Sends data using http
39
+ * @param collector
40
+ * @param data
41
+ * @param contentType
42
+ * @param onSuccess
43
+ * @param onError
44
+ */
45
+ export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
46
+ var exporterTimeout = collector.timeoutMillis;
47
+ var parsedUrl = new url.URL(collector.url);
48
+ var reqIsDestroyed;
49
+ var nodeVersion = Number(process.versions.node.split('.')[0]);
50
+ var exporterTimer = setTimeout(function () {
51
+ reqIsDestroyed = true;
52
+ // req.abort() was deprecated since v14
53
+ if (nodeVersion >= 14) {
54
+ req.destroy();
55
+ }
56
+ else {
57
+ req.abort();
58
+ }
59
+ }, exporterTimeout);
60
+ var options = {
61
+ hostname: parsedUrl.hostname,
62
+ port: parsedUrl.port,
63
+ path: parsedUrl.pathname,
64
+ method: 'POST',
65
+ headers: __assign({ 'Content-Type': contentType }, collector.headers),
66
+ agent: collector.agent,
67
+ };
68
+ var request = parsedUrl.protocol === 'http:' ? http.request : https.request;
69
+ var req = request(options, function (res) {
70
+ var responseData = '';
71
+ res.on('data', function (chunk) { return (responseData += chunk); });
72
+ res.on('aborted', function () {
73
+ if (reqIsDestroyed) {
74
+ var err = new OTLPExporterError('Request Timeout');
75
+ onError(err);
76
+ }
77
+ });
78
+ res.on('end', function () {
79
+ if (!reqIsDestroyed) {
80
+ if (res.statusCode && res.statusCode < 299) {
81
+ diag.debug("statusCode: " + res.statusCode, responseData);
82
+ onSuccess();
83
+ }
84
+ else {
85
+ var error = new OTLPExporterError(res.statusMessage, res.statusCode, responseData);
86
+ onError(error);
87
+ }
88
+ clearTimeout(exporterTimer);
89
+ }
90
+ });
91
+ });
92
+ req.on('error', function (error) {
93
+ if (reqIsDestroyed) {
94
+ var err = new OTLPExporterError('Request Timeout', error.code);
95
+ onError(err);
96
+ }
97
+ else {
98
+ clearTimeout(exporterTimer);
99
+ onError(error);
100
+ }
101
+ });
102
+ switch (collector.compression) {
103
+ case CompressionAlgorithm.GZIP: {
104
+ if (!gzip) {
105
+ gzip = zlib.createGzip();
106
+ }
107
+ req.setHeader('Content-Encoding', 'gzip');
108
+ var dataStream = readableFromBuffer(data);
109
+ dataStream.on('error', onError)
110
+ .pipe(gzip).on('error', onError)
111
+ .pipe(req);
112
+ break;
113
+ }
114
+ default:
115
+ req.end(data);
116
+ break;
117
+ }
118
+ }
119
+ function readableFromBuffer(buff) {
120
+ var readable = new Readable();
121
+ readable.push(buff);
122
+ readable.push(null);
123
+ return readable;
124
+ }
125
+ export function createHttpAgent(config) {
126
+ if (config.httpAgentOptions && config.keepAlive === false) {
127
+ diag.warn('httpAgentOptions is used only when keepAlive is true');
128
+ return undefined;
129
+ }
130
+ if (config.keepAlive === false || !config.url)
131
+ return undefined;
132
+ try {
133
+ var parsedUrl = new url.URL(config.url);
134
+ var Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
135
+ return new Agent(__assign({ keepAlive: true }, config.httpAgentOptions));
136
+ }
137
+ catch (err) {
138
+ diag.error("collector exporter failed to create http agent. err: " + err.message);
139
+ return undefined;
140
+ }
141
+ }
142
+ export function configureCompression(compression) {
143
+ if (compression) {
144
+ return compression;
145
+ }
146
+ else {
147
+ var definedCompression = getEnv().OTEL_EXPORTER_OTLP_TRACES_COMPRESSION || getEnv().OTEL_EXPORTER_OTLP_COMPRESSION;
148
+ return definedCompression === CompressionAlgorithm.GZIP ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE;
149
+ }
150
+ }
151
+ //# 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,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,IAAI,IAA2B,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAA2C;IAE3C,IAAM,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAChD,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7C,IA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qCAAqC,IAAI,MAAM,EAAE,CAAC,8BAA8B,CAAC;QACrH,OAAO,kBAAkB,KAAK,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC;KACjH;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * 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 exporterTimeout = collector.timeoutMillis;\n const parsedUrl = new url.URL(collector.url);\n let reqIsDestroyed: boolean;\n const nodeVersion = Number(process.versions.node.split('.')[0]);\n\n const exporterTimer = setTimeout(() => {\n reqIsDestroyed = true;\n // req.abort() was deprecated since v14\n if (nodeVersion >= 14) {\n req.destroy();\n } else {\n req.abort();\n }\n }, exporterTimeout);\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\n res.on('aborted', () => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError(\n 'Request Timeout'\n );\n onError(err);\n }\n });\n\n res.on('end', () => {\n if (!reqIsDestroyed) {\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 clearTimeout(exporterTimer);\n }\n });\n });\n\n req.on('error', (error: Error | any) => {\n if (reqIsDestroyed) {\n const err = new OTLPExporterError(\n 'Request Timeout', error.code\n );\n onError(err);\n } else {\n clearTimeout(exporterTimer);\n onError(error);\n }\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,35 @@
1
+ /**
2
+ * Interface for handling error
3
+ */
4
+ export declare class OTLPExporterError extends Error {
5
+ readonly code?: number;
6
+ readonly name: string;
7
+ readonly data?: string;
8
+ constructor(message?: string, code?: number, data?: string);
9
+ }
10
+ /**
11
+ * Interface for handling export service errors
12
+ */
13
+ export interface ExportServiceError {
14
+ name: string;
15
+ code: number;
16
+ details: string;
17
+ metadata: {
18
+ [key: string]: unknown;
19
+ };
20
+ message: string;
21
+ stack: string;
22
+ }
23
+ /**
24
+ * Collector Exporter base config
25
+ */
26
+ export interface OTLPExporterConfigBase {
27
+ headers?: Partial<Record<string, unknown>>;
28
+ hostname?: string;
29
+ url?: string;
30
+ concurrencyLimit?: number;
31
+ /** Maximum time the OTLP exporter will wait for each batch export.
32
+ * The default value is 10000ms. */
33
+ timeoutMillis?: number;
34
+ }
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __extends = (this && this.__extends) || (function () {
17
+ var extendStatics = function (d, b) {
18
+ extendStatics = Object.setPrototypeOf ||
19
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
21
+ return extendStatics(d, b);
22
+ };
23
+ return function (d, b) {
24
+ if (typeof b !== "function" && b !== null)
25
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26
+ extendStatics(d, b);
27
+ function __() { this.constructor = d; }
28
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
+ };
30
+ })();
31
+ /**
32
+ * Interface for handling error
33
+ */
34
+ var OTLPExporterError = /** @class */ (function (_super) {
35
+ __extends(OTLPExporterError, _super);
36
+ function OTLPExporterError(message, code, data) {
37
+ var _this = _super.call(this, message) || this;
38
+ _this.name = 'OTLPExporterError';
39
+ _this.data = data;
40
+ _this.code = code;
41
+ return _this;
42
+ }
43
+ return OTLPExporterError;
44
+ }(Error));
45
+ export { OTLPExporterError };
46
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH;;GAEG;AACH;IAAuC,qCAAK;IAK1C,2BAAY,OAAgB,EAAE,IAAa,EAAE,IAAa;QAA1D,YACE,kBAAM,OAAO,CAAC,SAGf;QAPiB,UAAI,GAAW,mBAAmB,CAAC;QAKnD,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;;IACnB,CAAC;IACH,wBAAC;AAAD,CAAC,AAVD,CAAuC,KAAK,GAU3C","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/**\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 url?: string;\n concurrencyLimit?: number;\n /** Maximum time the OTLP exporter will wait for each batch export.\n * The default value is 10000ms. */\n timeoutMillis?: number;\n}\n"]}
@@ -0,0 +1,27 @@
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
+ /**
7
+ * Adds path (version + signal) to a no per-signal endpoint
8
+ * @param url
9
+ * @param path
10
+ * @returns url + path
11
+ */
12
+ export declare function appendResourcePathToUrl(url: string, path: string): string;
13
+ /**
14
+ * Adds root path to signal specific endpoint when endpoint contains no path part and no root path
15
+ * @param url
16
+ * @param path
17
+ * @returns url
18
+ */
19
+ export declare function appendRootPathToUrlIfNeeded(url: string, path: string): string;
20
+ /**
21
+ * Configure exporter trace timeout value from passed in value or environment variables
22
+ * @param timeoutMillis
23
+ * @returns timeout value in milliseconds
24
+ */
25
+ export declare function configureExporterTimeout(timeoutMillis: number | undefined): number;
26
+ export declare function invalidTimeout(timeout: number, defaultTimeout: number): number;
27
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __read = (this && this.__read) || function (o, n) {
17
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
18
+ if (!m) return o;
19
+ var i = m.call(o), r, ar = [], e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ }
23
+ catch (error) { e = { error: error }; }
24
+ finally {
25
+ try {
26
+ if (r && !r.done && (m = i["return"])) m.call(i);
27
+ }
28
+ finally { if (e) throw e.error; }
29
+ }
30
+ return ar;
31
+ };
32
+ import { diag } from '@opentelemetry/api';
33
+ import { getEnv } from '@opentelemetry/core';
34
+ var DEFAULT_TRACE_TIMEOUT = 10000;
35
+ /**
36
+ * Parses headers from config leaving only those that have defined values
37
+ * @param partialHeaders
38
+ */
39
+ export function parseHeaders(partialHeaders) {
40
+ if (partialHeaders === void 0) { partialHeaders = {}; }
41
+ var headers = {};
42
+ Object.entries(partialHeaders).forEach(function (_a) {
43
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
44
+ if (typeof value !== 'undefined') {
45
+ headers[key] = String(value);
46
+ }
47
+ else {
48
+ diag.warn("Header \"" + key + "\" has wrong value and will be ignored");
49
+ }
50
+ });
51
+ return headers;
52
+ }
53
+ /**
54
+ * Adds path (version + signal) to a no per-signal endpoint
55
+ * @param url
56
+ * @param path
57
+ * @returns url + path
58
+ */
59
+ export function appendResourcePathToUrl(url, path) {
60
+ if (!url.endsWith('/')) {
61
+ url = url + '/';
62
+ }
63
+ return url + path;
64
+ }
65
+ /**
66
+ * Adds root path to signal specific endpoint when endpoint contains no path part and no root path
67
+ * @param url
68
+ * @param path
69
+ * @returns url
70
+ */
71
+ export function appendRootPathToUrlIfNeeded(url, path) {
72
+ if (!url.includes(path) && !url.endsWith('/')) {
73
+ url = url + '/';
74
+ }
75
+ return url;
76
+ }
77
+ /**
78
+ * Configure exporter trace timeout value from passed in value or environment variables
79
+ * @param timeoutMillis
80
+ * @returns timeout value in milliseconds
81
+ */
82
+ export function configureExporterTimeout(timeoutMillis) {
83
+ if (typeof timeoutMillis === 'number') {
84
+ if (timeoutMillis <= 0) {
85
+ // OTLP exporter configured timeout - using default value of 10000ms
86
+ return invalidTimeout(timeoutMillis, DEFAULT_TRACE_TIMEOUT);
87
+ }
88
+ return timeoutMillis;
89
+ }
90
+ else {
91
+ return getExporterTimeoutFromEnv();
92
+ }
93
+ }
94
+ function getExporterTimeoutFromEnv() {
95
+ var _a;
96
+ var definedTimeout = Number((_a = getEnv().OTEL_EXPORTER_OTLP_TRACES_TIMEOUT) !== null && _a !== void 0 ? _a : getEnv().OTEL_EXPORTER_OTLP_TIMEOUT);
97
+ if (definedTimeout <= 0) {
98
+ // OTLP exporter configured timeout - using default value of 10000ms
99
+ return invalidTimeout(definedTimeout, DEFAULT_TRACE_TIMEOUT);
100
+ }
101
+ else {
102
+ return definedTimeout;
103
+ }
104
+ }
105
+ // OTLP exporter configured timeout - using default value of 10000ms
106
+ export function invalidTimeout(timeout, defaultTimeout) {
107
+ diag.warn('Timeout must be greater than 0', timeout);
108
+ return defaultTimeout;
109
+ }
110
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE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,CAAC;SAC7D;QACD,OAAO,aAAa,CAAC;KACtB;SAAM;QACL,OAAO,yBAAyB,EAAE,CAAC;KACpC;AACH,CAAC;AAED,SAAS,yBAAyB;;IAChC,IAAM,cAAc,GAClB,MAAM,CAAC,MAAA,MAAM,EAAE,CAAC,iCAAiC,mCACjD,MAAM,EAAE,CAAC,0BAA0B,CAAC,CAAC;IAEvC,IAAI,cAAc,IAAI,CAAC,EAAE;QACvB,oEAAoE;QACpE,OAAO,cAAc,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;KAC9D;SAAM;QACL,OAAO,cAAc,CAAC;KACvB;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,cAAsB;IACpE,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,cAAc,CAAC;AACxB,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\nimport { diag } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\n\nconst DEFAULT_TRACE_TIMEOUT = 10000;\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\n/**\n * Adds path (version + signal) to a no per-signal endpoint\n * @param url\n * @param path\n * @returns url + path\n */\nexport function appendResourcePathToUrl(url: string, path: string): string {\n if (!url.endsWith('/')) {\n url = url + '/';\n }\n return url + path;\n}\n\n/**\n * Adds root path to signal specific endpoint when endpoint contains no path part and no root path\n * @param url\n * @param path\n * @returns url\n */\nexport function appendRootPathToUrlIfNeeded(url: string, path: string): string {\n if (!url.includes(path) && !url.endsWith('/')) {\n url = url + '/';\n }\n return url;\n}\n\n/**\n * Configure exporter trace timeout value from passed in value or environment variables\n * @param timeoutMillis\n * @returns timeout value in milliseconds\n */\nexport function configureExporterTimeout(timeoutMillis: number | undefined): number {\n if (typeof timeoutMillis === 'number') {\n if (timeoutMillis <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(timeoutMillis, DEFAULT_TRACE_TIMEOUT);\n }\n return timeoutMillis;\n } else {\n return getExporterTimeoutFromEnv();\n }\n}\n\nfunction getExporterTimeoutFromEnv(): number {\n const definedTimeout =\n Number(getEnv().OTEL_EXPORTER_OTLP_TRACES_TIMEOUT ??\n getEnv().OTEL_EXPORTER_OTLP_TIMEOUT);\n\n if (definedTimeout <= 0) {\n // OTLP exporter configured timeout - using default value of 10000ms\n return invalidTimeout(definedTimeout, DEFAULT_TRACE_TIMEOUT);\n } else {\n return definedTimeout;\n }\n}\n\n// OTLP exporter configured timeout - using default value of 10000ms\nexport function invalidTimeout(timeout: number, defaultTimeout: number): number {\n diag.warn('Timeout must be greater than 0', timeout);\n\n return defaultTimeout;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "0.29.2";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // this is autogenerated file, see scripts/version-update.js
17
+ export var VERSION = '0.29.2';
18
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,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.29.2';\n"]}
@@ -0,0 +1,38 @@
1
+ import { ExportResult, BindOnceFuture } from '@opentelemetry/core';
2
+ import { OTLPExporterError, OTLPExporterConfigBase } from './types';
3
+ /**
4
+ * Collector Exporter abstract base class
5
+ */
6
+ export declare abstract class OTLPExporterBase<T extends OTLPExporterConfigBase, ExportItem, ServiceRequest> {
7
+ readonly url: string;
8
+ readonly hostname: string | undefined;
9
+ readonly timeoutMillis: number;
10
+ protected _concurrencyLimit: number;
11
+ protected _sendingPromises: Promise<unknown>[];
12
+ protected _shutdownOnce: BindOnceFuture<void>;
13
+ /**
14
+ * @param config
15
+ */
16
+ constructor(config?: T);
17
+ /**
18
+ * Export items.
19
+ * @param items
20
+ * @param resultCallback
21
+ */
22
+ export(items: ExportItem[], resultCallback: (result: ExportResult) => void): void;
23
+ private _export;
24
+ /**
25
+ * Shutdown the exporter.
26
+ */
27
+ shutdown(): Promise<void>;
28
+ /**
29
+ * Called by _shutdownOnce with BindOnceFuture
30
+ */
31
+ private _shutdown;
32
+ abstract onShutdown(): void;
33
+ abstract onInit(config: T): void;
34
+ abstract send(items: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
35
+ abstract getDefaultUrl(config: T): string;
36
+ abstract convert(objects: ExportItem[]): ServiceRequest;
37
+ }
38
+ //# sourceMappingURL=OTLPExporterBase.d.ts.map
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { diag } from '@opentelemetry/api';
17
+ import { ExportResultCode, BindOnceFuture } from '@opentelemetry/core';
18
+ import { configureExporterTimeout } from './util';
19
+ /**
20
+ * Collector Exporter abstract base class
21
+ */
22
+ export class OTLPExporterBase {
23
+ /**
24
+ * @param config
25
+ */
26
+ constructor(config = {}) {
27
+ this._sendingPromises = [];
28
+ this.url = this.getDefaultUrl(config);
29
+ if (typeof config.hostname === 'string') {
30
+ this.hostname = config.hostname;
31
+ }
32
+ this.shutdown = this.shutdown.bind(this);
33
+ this._shutdownOnce = new BindOnceFuture(this._shutdown, this);
34
+ this._concurrencyLimit =
35
+ typeof config.concurrencyLimit === 'number'
36
+ ? config.concurrencyLimit
37
+ : Infinity;
38
+ this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);
39
+ // platform dependent
40
+ this.onInit(config);
41
+ }
42
+ /**
43
+ * Export items.
44
+ * @param items
45
+ * @param resultCallback
46
+ */
47
+ export(items, resultCallback) {
48
+ if (this._shutdownOnce.isCalled) {
49
+ resultCallback({
50
+ code: ExportResultCode.FAILED,
51
+ error: new Error('Exporter has been shutdown'),
52
+ });
53
+ return;
54
+ }
55
+ if (this._sendingPromises.length >= this._concurrencyLimit) {
56
+ resultCallback({
57
+ code: ExportResultCode.FAILED,
58
+ error: new Error('Concurrent export limit reached'),
59
+ });
60
+ return;
61
+ }
62
+ this._export(items)
63
+ .then(() => {
64
+ resultCallback({ code: ExportResultCode.SUCCESS });
65
+ })
66
+ .catch((error) => {
67
+ resultCallback({ code: ExportResultCode.FAILED, error });
68
+ });
69
+ }
70
+ _export(items) {
71
+ return new Promise((resolve, reject) => {
72
+ try {
73
+ diag.debug('items to be sent', items);
74
+ this.send(items, resolve, reject);
75
+ }
76
+ catch (e) {
77
+ reject(e);
78
+ }
79
+ });
80
+ }
81
+ /**
82
+ * Shutdown the exporter.
83
+ */
84
+ shutdown() {
85
+ return this._shutdownOnce.call();
86
+ }
87
+ /**
88
+ * Called by _shutdownOnce with BindOnceFuture
89
+ */
90
+ _shutdown() {
91
+ diag.debug('shutdown started');
92
+ this.onShutdown();
93
+ return Promise.all(this._sendingPromises)
94
+ .then(() => {
95
+ /** ignore resolved values */
96
+ });
97
+ }
98
+ }
99
+ //# sourceMappingURL=OTLPExporterBase.js.map