@opentelemetry/otlp-exporter-base 0.28.0 → 0.29.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.
Files changed (97) hide show
  1. package/build/esm/OTLPExporterBase.d.ts +40 -0
  2. package/build/esm/OTLPExporterBase.js +104 -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 +37 -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 +40 -0
  41. package/build/esnext/OTLPExporterBase.js +100 -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 +37 -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 -0
  80. package/build/src/OTLPExporterBase.js +2 -0
  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 -0
  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,40 @@
1
+ import { SpanAttributes } from '@opentelemetry/api';
2
+ import { ExportResult, BindOnceFuture } from '@opentelemetry/core';
3
+ import { OTLPExporterError, OTLPExporterConfigBase } from './types';
4
+ /**
5
+ * Collector Exporter abstract base class
6
+ */
7
+ export declare abstract class OTLPExporterBase<T extends OTLPExporterConfigBase, ExportItem, ServiceRequest> {
8
+ readonly url: string;
9
+ readonly hostname: string | undefined;
10
+ readonly attributes?: SpanAttributes;
11
+ readonly timeoutMillis: number;
12
+ protected _concurrencyLimit: number;
13
+ protected _sendingPromises: Promise<unknown>[];
14
+ protected _shutdownOnce: BindOnceFuture<void>;
15
+ /**
16
+ * @param config
17
+ */
18
+ constructor(config?: T);
19
+ /**
20
+ * Export items.
21
+ * @param items
22
+ * @param resultCallback
23
+ */
24
+ export(items: ExportItem[], resultCallback: (result: ExportResult) => void): void;
25
+ private _export;
26
+ /**
27
+ * Shutdown the exporter.
28
+ */
29
+ shutdown(): Promise<void>;
30
+ /**
31
+ * Called by _shutdownOnce with BindOnceFuture
32
+ */
33
+ private _shutdown;
34
+ abstract onShutdown(): void;
35
+ abstract onInit(config: T): void;
36
+ abstract send(items: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
37
+ abstract getDefaultUrl(config: T): string;
38
+ abstract convert(objects: ExportItem[]): ServiceRequest;
39
+ }
40
+ //# sourceMappingURL=OTLPExporterBase.d.ts.map
@@ -0,0 +1,104 @@
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
+ var OTLPExporterBase = /** @class */ (function () {
23
+ /**
24
+ * @param config
25
+ */
26
+ function OTLPExporterBase(config) {
27
+ if (config === void 0) { config = {}; }
28
+ this._sendingPromises = [];
29
+ this.url = this.getDefaultUrl(config);
30
+ if (typeof config.hostname === 'string') {
31
+ this.hostname = config.hostname;
32
+ }
33
+ this.attributes = config.attributes;
34
+ this.shutdown = this.shutdown.bind(this);
35
+ this._shutdownOnce = new BindOnceFuture(this._shutdown, this);
36
+ this._concurrencyLimit =
37
+ typeof config.concurrencyLimit === 'number'
38
+ ? config.concurrencyLimit
39
+ : Infinity;
40
+ this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);
41
+ // platform dependent
42
+ this.onInit(config);
43
+ }
44
+ /**
45
+ * Export items.
46
+ * @param items
47
+ * @param resultCallback
48
+ */
49
+ OTLPExporterBase.prototype.export = function (items, resultCallback) {
50
+ if (this._shutdownOnce.isCalled) {
51
+ resultCallback({
52
+ code: ExportResultCode.FAILED,
53
+ error: new Error('Exporter has been shutdown'),
54
+ });
55
+ return;
56
+ }
57
+ if (this._sendingPromises.length >= this._concurrencyLimit) {
58
+ resultCallback({
59
+ code: ExportResultCode.FAILED,
60
+ error: new Error('Concurrent export limit reached'),
61
+ });
62
+ return;
63
+ }
64
+ this._export(items)
65
+ .then(function () {
66
+ resultCallback({ code: ExportResultCode.SUCCESS });
67
+ })
68
+ .catch(function (error) {
69
+ resultCallback({ code: ExportResultCode.FAILED, error: error });
70
+ });
71
+ };
72
+ OTLPExporterBase.prototype._export = function (items) {
73
+ var _this = this;
74
+ return new Promise(function (resolve, reject) {
75
+ try {
76
+ diag.debug('items to be sent', items);
77
+ _this.send(items, resolve, reject);
78
+ }
79
+ catch (e) {
80
+ reject(e);
81
+ }
82
+ });
83
+ };
84
+ /**
85
+ * Shutdown the exporter.
86
+ */
87
+ OTLPExporterBase.prototype.shutdown = function () {
88
+ return this._shutdownOnce.call();
89
+ };
90
+ /**
91
+ * Called by _shutdownOnce with BindOnceFuture
92
+ */
93
+ OTLPExporterBase.prototype._shutdown = function () {
94
+ diag.debug('shutdown started');
95
+ this.onShutdown();
96
+ return Promise.all(this._sendingPromises)
97
+ .then(function () {
98
+ /** ignore resolved values */
99
+ });
100
+ };
101
+ return OTLPExporterBase;
102
+ }());
103
+ export { OTLPExporterBase };
104
+ //# sourceMappingURL=OTLPExporterBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/OTLPExporterBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OA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C,CAAC;IACP,CAAC;IAWH,uBAAC;AAAD,CAAC,AA5GD,IA4GC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SpanAttributes, diag } from '@opentelemetry/api';\nimport { ExportResult, ExportResultCode, BindOnceFuture } from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\nimport { configureExporterTimeout } from './util';\n\n/**\n * Collector Exporter abstract base class\n */\nexport abstract class OTLPExporterBase<\n T extends OTLPExporterConfigBase,\n ExportItem,\n ServiceRequest\n > {\n public readonly url: string;\n public readonly hostname: string | undefined;\n public readonly attributes?: SpanAttributes;\n public readonly timeoutMillis: number;\n protected _concurrencyLimit: number;\n protected _sendingPromises: Promise<unknown>[] = [];\n protected _shutdownOnce: BindOnceFuture<void>;\n\n /**\n * @param config\n */\n constructor(config: T = {} as T) {\n this.url = this.getDefaultUrl(config);\n if (typeof config.hostname === 'string') {\n this.hostname = config.hostname;\n }\n\n this.attributes = config.attributes;\n\n this.shutdown = this.shutdown.bind(this);\n this._shutdownOnce = new BindOnceFuture(this._shutdown, this);\n\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : Infinity;\n\n this.timeoutMillis = configureExporterTimeout(config.timeoutMillis);\n\n // platform dependent\n this.onInit(config);\n }\n\n /**\n * Export items.\n * @param items\n * @param resultCallback\n */\n export(items: ExportItem[], resultCallback: (result: ExportResult) => void): void {\n if (this._shutdownOnce.isCalled) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been shutdown'),\n });\n return;\n }\n\n if (this._sendingPromises.length >= this._concurrencyLimit) {\n resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Concurrent export limit reached'),\n });\n return;\n }\n\n this._export(items)\n .then(() => {\n resultCallback({ code: ExportResultCode.SUCCESS });\n })\n .catch((error: ExportServiceError) => {\n resultCallback({ code: ExportResultCode.FAILED, error });\n });\n }\n\n private _export(items: ExportItem[]): Promise<unknown> {\n return new Promise<void>((resolve, reject) => {\n try {\n diag.debug('items to be sent', items);\n this.send(items, resolve, reject);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n /**\n * Shutdown the exporter.\n */\n shutdown(): Promise<void> {\n return this._shutdownOnce.call();\n }\n\n /**\n * Called by _shutdownOnce with BindOnceFuture\n */\n private _shutdown(): Promise<void> {\n diag.debug('shutdown started');\n this.onShutdown();\n return Promise.all(this._sendingPromises)\n .then(() => {\n /** ignore resolved values */\n });\n }\n\n abstract onShutdown(): void;\n abstract onInit(config: T): void;\n abstract send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void;\n abstract getDefaultUrl(config: T): string;\n abstract convert(objects: ExportItem[]): ServiceRequest;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export * from './OTLPExporterBase';
2
+ export * from './platform';
3
+ export * from './types';
4
+ export * from './util';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './OTLPExporterBase';
17
+ export * from './platform';
18
+ export * from './types';
19
+ export * from './util';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './OTLPExporterBase';\nexport * from './platform';\nexport * from './types';\nexport * from './util';\n"]}
@@ -0,0 +1,18 @@
1
+ import { OTLPExporterBase } from '../../OTLPExporterBase';
2
+ import { OTLPExporterConfigBase } from '../../types';
3
+ import * as otlpTypes from '../../types';
4
+ /**
5
+ * Collector Metric Exporter abstract base class
6
+ */
7
+ export declare abstract class OTLPExporterBrowserBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPExporterConfigBase, ExportItem, ServiceRequest> {
8
+ protected _headers: Record<string, string>;
9
+ private _useXHR;
10
+ /**
11
+ * @param config
12
+ */
13
+ constructor(config?: OTLPExporterConfigBase);
14
+ onInit(): void;
15
+ onShutdown(): void;
16
+ send(items: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
17
+ }
18
+ //# sourceMappingURL=OTLPExporterBrowserBase.d.ts.map
@@ -0,0 +1,91 @@
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
+ import { OTLPExporterBase } from '../../OTLPExporterBase';
32
+ import { parseHeaders } from '../../util';
33
+ import { sendWithBeacon, sendWithXhr } from './util';
34
+ import { diag } from '@opentelemetry/api';
35
+ import { getEnv, baggageUtils } from '@opentelemetry/core';
36
+ /**
37
+ * Collector Metric Exporter abstract base class
38
+ */
39
+ var OTLPExporterBrowserBase = /** @class */ (function (_super) {
40
+ __extends(OTLPExporterBrowserBase, _super);
41
+ /**
42
+ * @param config
43
+ */
44
+ function OTLPExporterBrowserBase(config) {
45
+ if (config === void 0) { config = {}; }
46
+ var _this = _super.call(this, config) || this;
47
+ _this._useXHR = false;
48
+ _this._useXHR =
49
+ !!config.headers || typeof navigator.sendBeacon !== 'function';
50
+ if (_this._useXHR) {
51
+ _this._headers = Object.assign({}, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
52
+ }
53
+ else {
54
+ _this._headers = {};
55
+ }
56
+ return _this;
57
+ }
58
+ OTLPExporterBrowserBase.prototype.onInit = function () {
59
+ window.addEventListener('unload', this.shutdown);
60
+ };
61
+ OTLPExporterBrowserBase.prototype.onShutdown = function () {
62
+ window.removeEventListener('unload', this.shutdown);
63
+ };
64
+ OTLPExporterBrowserBase.prototype.send = function (items, onSuccess, onError) {
65
+ var _this = this;
66
+ if (this._shutdownOnce.isCalled) {
67
+ diag.debug('Shutdown already started. Cannot send objects');
68
+ return;
69
+ }
70
+ var serviceRequest = this.convert(items);
71
+ var body = JSON.stringify(serviceRequest);
72
+ var promise = new Promise(function (resolve, reject) {
73
+ if (_this._useXHR) {
74
+ sendWithXhr(body, _this.url, _this._headers, _this.timeoutMillis, resolve, reject);
75
+ }
76
+ else {
77
+ sendWithBeacon(body, _this.url, { type: 'application/json' }, resolve, reject);
78
+ }
79
+ })
80
+ .then(onSuccess, onError);
81
+ this._sendingPromises.push(promise);
82
+ var popPromise = function () {
83
+ var index = _this._sendingPromises.indexOf(promise);
84
+ _this._sendingPromises.splice(index, 1);
85
+ };
86
+ promise.then(popPromise, popPromise);
87
+ };
88
+ return OTLPExporterBrowserBase;
89
+ }(OTLPExporterBase));
90
+ export { OTLPExporterBrowserBase };
91
+ //# sourceMappingURL=OTLPExporterBrowserBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTLPExporterBrowserBase.js","sourceRoot":"","sources":["../../../../src/platform/browser/OTLPExporterBrowserBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM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AE;gBAChB,WAAW,CAAC,IAAI,EAAE,KAAI,CAAC,GAAG,EAAE,KAAI,CAAC,QAAQ,EAAE,KAAI,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aACjF;iBAAM;gBACL,cAAc,CAAC,IAAI,EAAE,KAAI,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aAC/E;QACH,CAAC,CAAC;aACC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,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;IACH,8BAAC;AAAD,CAAC,AAnED,CAGY,gBAAgB,GAgE3B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterConfigBase } from '../../types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { sendWithBeacon, sendWithXhr } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterBrowserBase<\n ExportItem,\n ServiceRequest\n > extends OTLPExporterBase<\n OTLPExporterConfigBase,\n ExportItem,\n ServiceRequest\n > {\n protected _headers: Record<string, string>;\n private _useXHR: boolean = false;\n\n /**\n * @param config\n */\n constructor(config: OTLPExporterConfigBase = {}) {\n super(config);\n this._useXHR =\n !!config.headers || typeof navigator.sendBeacon !== 'function';\n if (this._useXHR) {\n this._headers = Object.assign(\n {},\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n )\n );\n } else {\n this._headers = {};\n }\n }\n\n onInit(): void {\n window.addEventListener('unload', this.shutdown);\n }\n\n onShutdown(): void {\n window.removeEventListener('unload', this.shutdown);\n }\n\n send(\n items: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n const serviceRequest = this.convert(items);\n const body = JSON.stringify(serviceRequest);\n\n const promise = new Promise<void>((resolve, reject) => {\n if (this._useXHR) {\n sendWithXhr(body, this.url, this._headers, this.timeoutMillis, resolve, reject);\n } else {\n sendWithBeacon(body, this.url, { type: 'application/json' }, resolve, reject);\n }\n })\n .then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n };\n promise.then(popPromise, popPromise);\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './OTLPExporterBrowserBase';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './OTLPExporterBrowserBase';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,2BAA2B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './OTLPExporterBrowserBase';\n"]}
@@ -0,0 +1,21 @@
1
+ import { OTLPExporterError } from '../../types';
2
+ /**
3
+ * Send metrics/spans using browser navigator.sendBeacon
4
+ * @param body
5
+ * @param url
6
+ * @param blobPropertyBag
7
+ * @param onSuccess
8
+ * @param onError
9
+ */
10
+ export declare function sendWithBeacon(body: string, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
11
+ /**
12
+ * function to send metrics/spans using browser XMLHttpRequest
13
+ * used when navigator.sendBeacon is not available
14
+ * @param body
15
+ * @param url
16
+ * @param headers
17
+ * @param onSuccess
18
+ * @param onError
19
+ */
20
+ export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, exporterTimeout: number, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
21
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,108 @@
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
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ /*
29
+ * Copyright The OpenTelemetry Authors
30
+ *
31
+ * Licensed under the Apache License, Version 2.0 (the "License");
32
+ * you may not use this file except in compliance with the License.
33
+ * You may obtain a copy of the License at
34
+ *
35
+ * https://www.apache.org/licenses/LICENSE-2.0
36
+ *
37
+ * Unless required by applicable law or agreed to in writing, software
38
+ * distributed under the License is distributed on an "AS IS" BASIS,
39
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ * See the License for the specific language governing permissions and
41
+ * limitations under the License.
42
+ */
43
+ import { diag } from '@opentelemetry/api';
44
+ import { OTLPExporterError } from '../../types';
45
+ /**
46
+ * Send metrics/spans using browser navigator.sendBeacon
47
+ * @param body
48
+ * @param url
49
+ * @param blobPropertyBag
50
+ * @param onSuccess
51
+ * @param onError
52
+ */
53
+ export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
54
+ if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
55
+ diag.debug('sendBeacon - can send', body);
56
+ onSuccess();
57
+ }
58
+ else {
59
+ var error = new OTLPExporterError("sendBeacon - cannot send " + body);
60
+ onError(error);
61
+ }
62
+ }
63
+ /**
64
+ * function to send metrics/spans using browser XMLHttpRequest
65
+ * used when navigator.sendBeacon is not available
66
+ * @param body
67
+ * @param url
68
+ * @param headers
69
+ * @param onSuccess
70
+ * @param onError
71
+ */
72
+ export function sendWithXhr(body, url, headers, exporterTimeout, onSuccess, onError) {
73
+ var reqIsDestroyed;
74
+ var exporterTimer = setTimeout(function () {
75
+ reqIsDestroyed = true;
76
+ xhr.abort();
77
+ }, exporterTimeout);
78
+ var xhr = new XMLHttpRequest();
79
+ xhr.open('POST', url);
80
+ var defaultHeaders = {
81
+ 'Accept': 'application/json',
82
+ 'Content-Type': 'application/json',
83
+ };
84
+ Object.entries(__assign(__assign({}, defaultHeaders), headers)).forEach(function (_a) {
85
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
86
+ xhr.setRequestHeader(k, v);
87
+ });
88
+ xhr.send(body);
89
+ xhr.onreadystatechange = function () {
90
+ if (xhr.readyState === XMLHttpRequest.DONE) {
91
+ if (xhr.status >= 200 && xhr.status <= 299) {
92
+ clearTimeout(exporterTimer);
93
+ diag.debug('xhr success', body);
94
+ onSuccess();
95
+ }
96
+ else if (reqIsDestroyed) {
97
+ var error = new OTLPExporterError('Request Timeout', xhr.status);
98
+ onError(error);
99
+ }
100
+ else {
101
+ var error = new OTLPExporterError("Failed to export with XHR (status: " + xhr.status + ")", xhr.status);
102
+ clearTimeout(exporterTimer);
103
+ onError(error);
104
+ }
105
+ }
106
+ };
107
+ }
108
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,IAA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,EAAE;YAC1C,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;gBAC1C,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBAChC,SAAS,EAAE,CAAC;aACb;iBAAM,IAAI,cAAc,EAAE;gBACzB,IAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAC9B,CAAC;gBACF,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;iBAAM;gBACL,IAAM,KAAK,GAAG,IAAI,iBAAiB,CACjC,wCAAsC,GAAG,CAAC,MAAM,MAAG,EACnD,GAAG,CAAC,MAAM,CACX,CAAC;gBACF,YAAY,CAAC,aAAa,CAAC,CAAC;gBAC5B,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Send metrics/spans using browser navigator.sendBeacon\n * @param body\n * @param url\n * @param blobPropertyBag\n * @param onSuccess\n * @param onError\n */\nexport function sendWithBeacon(\n body: string,\n url: string,\n blobPropertyBag: BlobPropertyBag,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {\n diag.debug('sendBeacon - can send', body);\n onSuccess();\n } else {\n const error = new OTLPExporterError(\n `sendBeacon - cannot send ${body}`\n );\n onError(error);\n }\n}\n\n/**\n * function to send metrics/spans using browser XMLHttpRequest\n * used when navigator.sendBeacon is not available\n * @param body\n * @param url\n * @param headers\n * @param onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string,\n url: string,\n headers: Record<string, string>,\n exporterTimeout: number,\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n): void {\n let reqIsDestroyed: boolean;\n\n const exporterTimer = setTimeout(() => {\n reqIsDestroyed = true;\n xhr.abort();\n }, exporterTimeout);\n\n const xhr = new XMLHttpRequest();\n xhr.open('POST', url);\n\n const defaultHeaders = {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json',\n };\n\n Object.entries({\n ...defaultHeaders,\n ...headers,\n }).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.send(body);\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n if (xhr.status >= 200 && xhr.status <= 299) {\n clearTimeout(exporterTimer);\n diag.debug('xhr success', body);\n onSuccess();\n } else if (reqIsDestroyed) {\n const error = new OTLPExporterError(\n 'Request Timeout', xhr.status\n );\n onError(error);\n } else {\n const error = new OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n clearTimeout(exporterTimer);\n onError(error);\n }\n }\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './node';
2
+ export { OTLPExporterBrowserBase } from './browser';
3
+ //# sourceMappingURL=index.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
+ export * from './node';
17
+ export { OTLPExporterBrowserBase } from './browser';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport * from './node';\nexport { OTLPExporterBrowserBase } from './browser';\n"]}
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import type * as http from 'http';
3
+ import type * as https from 'https';
4
+ import { OTLPExporterBase } from '../../OTLPExporterBase';
5
+ import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
6
+ import * as otlpTypes from '../../types';
7
+ /**
8
+ * Collector Metric Exporter abstract base class
9
+ */
10
+ export declare abstract class OTLPExporterNodeBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem, ServiceRequest> {
11
+ DEFAULT_HEADERS: Record<string, string>;
12
+ headers: Record<string, string>;
13
+ agent: http.Agent | https.Agent | undefined;
14
+ compression: CompressionAlgorithm;
15
+ constructor(config?: OTLPExporterNodeConfigBase);
16
+ onInit(_config: OTLPExporterNodeConfigBase): void;
17
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
18
+ onShutdown(): void;
19
+ }
20
+ //# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
@@ -0,0 +1,79 @@
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
+ import { OTLPExporterBase } from '../../OTLPExporterBase';
32
+ import { parseHeaders } from '../../util';
33
+ import { createHttpAgent, sendWithHttp, configureCompression } from './util';
34
+ import { diag } from '@opentelemetry/api';
35
+ import { getEnv, baggageUtils } from '@opentelemetry/core';
36
+ /**
37
+ * Collector Metric Exporter abstract base class
38
+ */
39
+ var OTLPExporterNodeBase = /** @class */ (function (_super) {
40
+ __extends(OTLPExporterNodeBase, _super);
41
+ function OTLPExporterNodeBase(config) {
42
+ if (config === void 0) { config = {}; }
43
+ var _this = _super.call(this, config) || this;
44
+ _this.DEFAULT_HEADERS = {};
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ if (config.metadata) {
47
+ diag.warn('Metadata cannot be set when using http');
48
+ }
49
+ _this.headers = Object.assign(_this.DEFAULT_HEADERS, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
50
+ _this.agent = createHttpAgent(config);
51
+ _this.compression = configureCompression(config.compression);
52
+ return _this;
53
+ }
54
+ OTLPExporterNodeBase.prototype.onInit = function (_config) { };
55
+ OTLPExporterNodeBase.prototype.send = function (objects, onSuccess, onError) {
56
+ var _this = this;
57
+ if (this._shutdownOnce.isCalled) {
58
+ diag.debug('Shutdown already started. Cannot send objects');
59
+ return;
60
+ }
61
+ var serviceRequest = this.convert(objects);
62
+ var promise = new Promise(function (resolve, reject) {
63
+ sendWithHttp(_this, JSON.stringify(serviceRequest), 'application/json', resolve, reject);
64
+ })
65
+ .then(onSuccess, onError);
66
+ this._sendingPromises.push(promise);
67
+ var popPromise = function () {
68
+ var index = _this._sendingPromises.indexOf(promise);
69
+ _this._sendingPromises.splice(index, 1);
70
+ };
71
+ promise.then(popPromise, popPromise);
72
+ };
73
+ // TODO: end gzip stream from util.ts if not undefined
74
+ // It should perhaps be a class member here instead of a variable in util.ts
75
+ OTLPExporterNodeBase.prototype.onShutdown = function () { };
76
+ return OTLPExporterNodeBase;
77
+ }(OTLPExporterBase));
78
+ export { OTLPExporterNodeBase };
79
+ //# sourceMappingURL=OTLPExporterNodeBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE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,CAAC,CAAC;aACC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG;YACjB,IAAM,KAAK,GAAG,KAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrD,KAAI,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,yCAAU,GAAV,cAAoB,CAAC;IACvB,2BAAC;AAAD,CAAC,AA/DD,CAGU,gBAAgB,GA4DzB","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,4 @@
1
+ export * from './OTLPExporterNodeBase';
2
+ export * from './util';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map