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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +3 -9
  2. package/build/esm/index.d.ts +0 -2
  3. package/build/esm/index.js +0 -2
  4. package/build/esm/index.js.map +1 -1
  5. package/build/esm/platform/browser/OTLPTraceExporter.d.ts +2 -2
  6. package/build/esm/platform/browser/OTLPTraceExporter.js +2 -3
  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 +2 -2
  15. package/build/esm/platform/node/OTLPTraceExporter.js +3 -3
  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/transform.d.ts +2 -2
  21. package/build/esm/transform.js +18 -2
  22. package/build/esm/transform.js.map +1 -1
  23. package/build/esm/types.d.ts +1 -33
  24. package/build/esm/types.js +0 -30
  25. package/build/esm/types.js.map +1 -1
  26. package/build/esm/version.d.ts +1 -1
  27. package/build/esm/version.js +1 -1
  28. package/build/esm/version.js.map +1 -1
  29. package/build/esnext/index.d.ts +4 -0
  30. package/build/esnext/index.js +19 -0
  31. package/build/esnext/index.js.map +1 -0
  32. package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +13 -0
  33. package/build/esnext/platform/browser/OTLPTraceExporter.js +42 -0
  34. package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -0
  35. package/build/esnext/platform/browser/index.d.ts +2 -0
  36. package/build/esnext/platform/browser/index.js +17 -0
  37. package/build/esnext/platform/browser/index.js.map +1 -0
  38. package/build/esnext/platform/index.d.ts +2 -0
  39. package/build/esnext/platform/index.js +17 -0
  40. package/build/esnext/platform/index.js.map +1 -0
  41. package/build/esnext/platform/node/OTLPTraceExporter.d.ts +13 -0
  42. package/build/esnext/platform/node/OTLPTraceExporter.js +43 -0
  43. package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -0
  44. package/build/esnext/platform/node/index.d.ts +2 -0
  45. package/build/esnext/platform/node/index.js +17 -0
  46. package/build/esnext/platform/node/index.js.map +1 -0
  47. package/build/esnext/transform.d.ts +80 -0
  48. package/build/esnext/transform.js +266 -0
  49. package/build/esnext/transform.js.map +1 -0
  50. package/build/esnext/types.d.ts +209 -0
  51. package/build/esnext/types.js +145 -0
  52. package/build/esnext/types.js.map +1 -0
  53. package/build/esnext/version.d.ts +2 -0
  54. package/build/esnext/version.js +18 -0
  55. package/build/esnext/version.js.map +1 -0
  56. package/build/src/index.d.ts +0 -2
  57. package/build/src/index.js +1 -4
  58. package/build/src/index.js.map +1 -1
  59. package/build/src/platform/browser/OTLPTraceExporter.d.ts +2 -2
  60. package/build/src/platform/browser/OTLPTraceExporter.js +9 -10
  61. package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
  62. package/build/src/platform/browser/index.d.ts +0 -1
  63. package/build/src/platform/browser/index.js +0 -1
  64. package/build/src/platform/browser/index.js.map +1 -1
  65. package/build/src/platform/index.d.ts +0 -1
  66. package/build/src/platform/index.js +0 -3
  67. package/build/src/platform/index.js.map +1 -1
  68. package/build/src/platform/node/OTLPTraceExporter.d.ts +2 -2
  69. package/build/src/platform/node/OTLPTraceExporter.js +10 -10
  70. package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
  71. package/build/src/platform/node/index.d.ts +0 -3
  72. package/build/src/platform/node/index.js +0 -3
  73. package/build/src/platform/node/index.js.map +1 -1
  74. package/build/src/transform.d.ts +2 -2
  75. package/build/src/transform.js.map +1 -1
  76. package/build/src/types.d.ts +1 -33
  77. package/build/src/types.js +1 -13
  78. package/build/src/types.js.map +1 -1
  79. package/build/src/version.d.ts +1 -1
  80. package/build/src/version.js +1 -1
  81. package/build/src/version.js.map +1 -1
  82. package/package.json +30 -21
  83. package/build/esm/OTLPExporterBase.d.ts +0 -36
  84. package/build/esm/OTLPExporterBase.js +0 -114
  85. package/build/esm/OTLPExporterBase.js.map +0 -1
  86. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  87. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +0 -91
  88. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  89. package/build/esm/platform/browser/util.d.ts +0 -17
  90. package/build/esm/platform/browser/util.js +0 -77
  91. package/build/esm/platform/browser/util.js.map +0 -1
  92. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  93. package/build/esm/platform/node/OTLPExporterNodeBase.js +0 -82
  94. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +0 -1
  95. package/build/esm/platform/node/types.d.ts +0 -17
  96. package/build/esm/platform/node/types.js +0 -6
  97. package/build/esm/platform/node/types.js.map +0 -1
  98. package/build/esm/platform/node/util.d.ts +0 -17
  99. package/build/esm/platform/node/util.js +0 -113
  100. package/build/esm/platform/node/util.js.map +0 -1
  101. package/build/esm/util.d.ts +0 -7
  102. package/build/esm/util.js +0 -40
  103. package/build/esm/util.js.map +0 -1
  104. package/build/src/OTLPExporterBase.d.ts +0 -36
  105. package/build/src/OTLPExporterBase.js +0 -113
  106. package/build/src/OTLPExporterBase.js.map +0 -1
  107. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  108. package/build/src/platform/browser/OTLPExporterBrowserBase.js +0 -74
  109. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  110. package/build/src/platform/browser/util.d.ts +0 -17
  111. package/build/src/platform/browser/util.js +0 -70
  112. package/build/src/platform/browser/util.js.map +0 -1
  113. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  114. package/build/src/platform/node/OTLPExporterNodeBase.js +0 -65
  115. package/build/src/platform/node/OTLPExporterNodeBase.js.map +0 -1
  116. package/build/src/platform/node/types.d.ts +0 -17
  117. package/build/src/platform/node/types.js +0 -9
  118. package/build/src/platform/node/types.js.map +0 -1
  119. package/build/src/platform/node/util.d.ts +0 -17
  120. package/build/src/platform/node/util.js +0 -107
  121. package/build/src/platform/node/util.js.map +0 -1
  122. package/build/src/util.d.ts +0 -7
  123. package/build/src/util.js +0 -43
  124. package/build/src/util.js.map +0 -1
@@ -1,91 +0,0 @@
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._isShutdown) {
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, 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
@@ -1 +0,0 @@
1
- {"version":3,"file":"OTLPExporterBrowserBase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;QAtBC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QACD,IAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAE5C,IAAM,OAAO,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;YAChD,IAAI,KAAI,CAAC,OAAO,EAAE;gBAChB,WAAW,CAAC,IAAI,EAAE,KAAI,CAAC,GAAG,EAAE,KAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aAC7D;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,CAAA;QACD,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._isShutdown) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n const serviceRequest = this.convert(items);\n const body = JSON.stringify(serviceRequest);\n\n const promise = new Promise<void>((resolve, reject) => {\n if (this._useXHR) {\n sendWithXhr(body, this.url, this._headers, resolve, reject);\n } else {\n sendWithBeacon(body, this.url, { type: 'application/json' }, resolve, reject);\n }\n })\n .then(onSuccess, onError);\n\n this._sendingPromises.push(promise);\n const popPromise = () => {\n const index = this._sendingPromises.indexOf(promise);\n this._sendingPromises.splice(index, 1);\n }\n promise.then(popPromise, popPromise);\n }\n}\n"]}
@@ -1,17 +0,0 @@
1
- import * as otlpTypes from '../../types';
2
- /**
3
- * Send metrics/spans using browser navigator.sendBeacon
4
- * @param body
5
- * @param onSuccess
6
- * @param onError
7
- */
8
- export declare function sendWithBeacon(body: string, url: string, blobPropertyBag: BlobPropertyBag, onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
9
- /**
10
- * function to send metrics/spans using browser XMLHttpRequest
11
- * used when navigator.sendBeacon is not available
12
- * @param body
13
- * @param onSuccess
14
- * @param onError
15
- */
16
- export declare function sendWithXhr(body: string, url: string, headers: Record<string, string>, onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
17
- //# sourceMappingURL=util.d.ts.map
@@ -1,77 +0,0 @@
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 { diag } from '@opentelemetry/api';
28
- import * as otlpTypes from '../../types';
29
- /**
30
- * Send metrics/spans using browser navigator.sendBeacon
31
- * @param body
32
- * @param onSuccess
33
- * @param onError
34
- */
35
- export function sendWithBeacon(body, url, blobPropertyBag, onSuccess, onError) {
36
- if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {
37
- diag.debug('sendBeacon - can send', body);
38
- onSuccess();
39
- }
40
- else {
41
- var error = new otlpTypes.OTLPExporterError("sendBeacon - cannot send " + body);
42
- onError(error);
43
- }
44
- }
45
- /**
46
- * function to send metrics/spans using browser XMLHttpRequest
47
- * used when navigator.sendBeacon is not available
48
- * @param body
49
- * @param onSuccess
50
- * @param onError
51
- */
52
- export function sendWithXhr(body, url, headers, onSuccess, onError) {
53
- var xhr = new XMLHttpRequest();
54
- xhr.open('POST', url);
55
- var defaultHeaders = {
56
- 'Accept': 'application/json',
57
- 'Content-Type': 'application/json',
58
- };
59
- Object.entries(__assign(__assign({}, defaultHeaders), headers)).forEach(function (_a) {
60
- var k = _a[0], v = _a[1];
61
- xhr.setRequestHeader(k, v);
62
- });
63
- xhr.send(body);
64
- xhr.onreadystatechange = function () {
65
- if (xhr.readyState === XMLHttpRequest.DONE) {
66
- if (xhr.status >= 200 && xhr.status <= 299) {
67
- diag.debug('xhr success', body);
68
- onSuccess();
69
- }
70
- else {
71
- var error = new otlpTypes.OTLPExporterError("Failed to export with XHR (status: " + xhr.status + ")", xhr.status);
72
- onError(error);
73
- }
74
- }
75
- };
76
- }
77
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/platform/browser/util.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,GAAW,EACX,eAAgC,EAChC,SAAqB,EACrB,OAAqD;IAErD,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE;QAChE,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,IAAI,C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n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { diag } from '@opentelemetry/api';\nimport * as otlpTypes from '../../types';\n\n/**\n * Send metrics/spans using browser navigator.sendBeacon\n * @param body\n * @param onSuccess\n * @param onError\n */\nexport function sendWithBeacon(\n body: string,\n url: string,\n blobPropertyBag: BlobPropertyBag,\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n): void {\n if (navigator.sendBeacon(url, new Blob([body], blobPropertyBag))) {\n diag.debug('sendBeacon - can send', body);\n onSuccess();\n } else {\n const error = new otlpTypes.OTLPExporterError(\n `sendBeacon - cannot send ${body}`\n );\n onError(error);\n }\n}\n\n/**\n * function to send metrics/spans using browser XMLHttpRequest\n * used when navigator.sendBeacon is not available\n * @param body\n * @param onSuccess\n * @param onError\n */\nexport function sendWithXhr(\n body: string,\n url: string,\n headers: Record<string, string>,\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n): void {\n const xhr = new XMLHttpRequest();\n xhr.open('POST', url);\n\n const defaultHeaders = {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json',\n };\n\n Object.entries({\n ...defaultHeaders,\n ...headers,\n }).forEach(([k, v]) => {\n xhr.setRequestHeader(k, v);\n });\n\n xhr.send(body);\n\n xhr.onreadystatechange = () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n if (xhr.status >= 200 && xhr.status <= 299) {\n diag.debug('xhr success', body);\n onSuccess();\n } else {\n const error = new otlpTypes.OTLPExporterError(\n `Failed to export with XHR (status: ${xhr.status})`,\n xhr.status\n );\n\n onError(error);\n }\n }\n };\n}\n"]}
@@ -1,20 +0,0 @@
1
- /// <reference types="node" />
2
- import type * as http from 'http';
3
- import type * as https from 'https';
4
- import { OTLPExporterBase } from '../../OTLPExporterBase';
5
- import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
6
- import * as otlpTypes from '../../types';
7
- /**
8
- * Collector Metric Exporter abstract base class
9
- */
10
- export declare abstract class OTLPExporterNodeBase<ExportItem, ServiceRequest> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem, ServiceRequest> {
11
- DEFAULT_HEADERS: Record<string, string>;
12
- headers: Record<string, string>;
13
- agent: http.Agent | https.Agent | undefined;
14
- compression: CompressionAlgorithm;
15
- constructor(config?: OTLPExporterNodeConfigBase);
16
- onInit(_config: OTLPExporterNodeConfigBase): void;
17
- send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
18
- onShutdown(): void;
19
- }
20
- //# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
@@ -1,82 +0,0 @@
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 { CompressionAlgorithm } from './types';
33
- import { parseHeaders } from '../../util';
34
- import { createHttpAgent, sendWithHttp } from './util';
35
- import { diag } from '@opentelemetry/api';
36
- import { getEnv, baggageUtils } from '@opentelemetry/core';
37
- /**
38
- * Collector Metric Exporter abstract base class
39
- */
40
- var OTLPExporterNodeBase = /** @class */ (function (_super) {
41
- __extends(OTLPExporterNodeBase, _super);
42
- function OTLPExporterNodeBase(config) {
43
- if (config === void 0) { config = {}; }
44
- var _this = _super.call(this, config) || this;
45
- _this.DEFAULT_HEADERS = {};
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- if (config.metadata) {
48
- diag.warn('Metadata cannot be set when using http');
49
- }
50
- _this.headers = Object.assign(_this.DEFAULT_HEADERS, parseHeaders(config.headers), baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS));
51
- _this.agent = createHttpAgent(config);
52
- _this.compression = config.compression || CompressionAlgorithm.NONE;
53
- return _this;
54
- }
55
- OTLPExporterNodeBase.prototype.onInit = function (_config) {
56
- this._isShutdown = false;
57
- };
58
- OTLPExporterNodeBase.prototype.send = function (objects, onSuccess, onError) {
59
- var _this = this;
60
- if (this._isShutdown) {
61
- diag.debug('Shutdown already started. Cannot send objects');
62
- return;
63
- }
64
- var serviceRequest = this.convert(objects);
65
- var promise = new Promise(function (resolve, reject) {
66
- sendWithHttp(_this, JSON.stringify(serviceRequest), 'application/json', resolve, reject);
67
- })
68
- .then(onSuccess, onError);
69
- this._sendingPromises.push(promise);
70
- var popPromise = function () {
71
- var index = _this._sendingPromises.indexOf(promise);
72
- _this._sendingPromises.splice(index, 1);
73
- };
74
- promise.then(popPromise, popPromise);
75
- };
76
- // TODO: end gzip stream from util.ts if not undefined
77
- // It should perhaps be a class member here instead of a variable in util.ts
78
- OTLPExporterNodeBase.prototype.onShutdown = function () { };
79
- return OTLPExporterNodeBase;
80
- }(OTLPExporterBase));
81
- export { OTLPExporterNodeBase };
82
- //# sourceMappingURL=OTLPExporterNodeBase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAA8B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;GAEG;AACH;IAGU,wCAIT;IAMC,8BAAY,MAAuC;QAAvC,uBAAA,EAAA,WAAuC;QAAnD,YACE,kBAAM,MAAM,CAAC,SAYd;QAlBD,qBAAe,GAA2B,EAAE,CAAC;QAO3C,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;SACrD;QACD,KAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B,KAAI,CAAC,eAAe,EACpB,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,0BAA0B,CAAC,CAC1E,CAAC;QACF,KAAI,CAAC,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACrC,KAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,oBAAoB,CAAC,IAAI,CAAC;;IACrE,CAAC;IAED,qCAAM,GAAN,UAAO,OAAmC;QACxC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,mCAAI,GAAJ,UACE,OAAqB,EACrB,SAAqB,EACrB,OAAqD;QAHvD,iBA4BC;QAvBC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC5D,OAAO;SACR;QACD,IAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAM,OAAO,GAAG,IAAI,OAAO,CAAO,UAAC,OAAO,EAAE,MAAM;YAChD,YAAY,CACV,KAAI,EACJ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAC9B,kBAAkB,EAClB,OAAO,EACP,MAAM,CACP,CAAC;QACJ,CAAC,CAAC;aACC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,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,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,sDAAsD;IACtD,4EAA4E;IAC5E,yCAAU,GAAV,cAAoB,CAAC;IACvB,2BAAC;AAAD,CAAC,AAjED,CAGU,gBAAgB,GA8DzB","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,6 +0,0 @@
1
- export var CompressionAlgorithm;
2
- (function (CompressionAlgorithm) {
3
- CompressionAlgorithm["NONE"] = "none";
4
- CompressionAlgorithm["GZIP"] = "gzip";
5
- })(CompressionAlgorithm || (CompressionAlgorithm = {}));
6
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
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"]}
@@ -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,113 +0,0 @@
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 * as otlpTypes from '../../types';
33
- import { diag } from '@opentelemetry/api';
34
- import { CompressionAlgorithm } from './types';
35
- var gzip;
36
- /**
37
- * Sends data using http
38
- * @param collector
39
- * @param data
40
- * @param contentType
41
- * @param onSuccess
42
- * @param onError
43
- */
44
- export function sendWithHttp(collector, data, contentType, onSuccess, onError) {
45
- var parsedUrl = new url.URL(collector.url);
46
- var options = {
47
- hostname: parsedUrl.hostname,
48
- port: parsedUrl.port,
49
- path: parsedUrl.pathname,
50
- method: 'POST',
51
- headers: __assign({ 'Content-Length': Buffer.byteLength(data), 'Content-Type': contentType }, collector.headers),
52
- agent: collector.agent,
53
- };
54
- var request = parsedUrl.protocol === 'http:' ? http.request : https.request;
55
- var req = request(options, function (res) {
56
- var responseData = '';
57
- res.on('data', function (chunk) { return (responseData += chunk); });
58
- res.on('end', function () {
59
- if (res.statusCode && res.statusCode < 299) {
60
- diag.debug("statusCode: " + res.statusCode, responseData);
61
- onSuccess();
62
- }
63
- else {
64
- var error = new otlpTypes.OTLPExporterError(res.statusMessage, res.statusCode, responseData);
65
- onError(error);
66
- }
67
- });
68
- });
69
- req.on('error', function (error) {
70
- onError(error);
71
- });
72
- switch (collector.compression) {
73
- case CompressionAlgorithm.GZIP: {
74
- if (!gzip) {
75
- gzip = zlib.createGzip();
76
- }
77
- req.setHeader('Content-Encoding', 'gzip');
78
- var dataStream = readableFromBuffer(data);
79
- dataStream.on('error', onError)
80
- .pipe(gzip).on('error', onError)
81
- .pipe(req);
82
- break;
83
- }
84
- default:
85
- req.write(data);
86
- req.end();
87
- break;
88
- }
89
- }
90
- function readableFromBuffer(buff) {
91
- var readable = new Readable();
92
- readable.push(buff);
93
- readable.push(null);
94
- return readable;
95
- }
96
- export function createHttpAgent(config) {
97
- if (config.httpAgentOptions && config.keepAlive === false) {
98
- diag.warn('httpAgentOptions is used only when keepAlive is true');
99
- return undefined;
100
- }
101
- if (config.keepAlive === false || !config.url)
102
- return undefined;
103
- try {
104
- var parsedUrl = new url.URL(config.url);
105
- var Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
106
- return new Agent(__assign({ keepAlive: true }, config.httpAgentOptions));
107
- }
108
- catch (err) {
109
- diag.error("collector exporter failed to create http agent. err: " + err.message);
110
- return undefined;
111
- }
112
- }
113
- //# 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,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;AAClC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,IAAI,IAA2B,CAAC;AAEhC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA2D,EAC3D,IAAqB,EACrB,WAAmB,EACnB,SAAqB,EACrB,OAAqD;IAErD,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE7C,IAAM,OAAO,GAA+C;QAC1D,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,QAAQ;QACxB,MAAM,EAAE,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IAAK,MAAM,CAAC,gBAAgB,EAAG,CAAC;KACnE;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,CAAC,KAAK,CACR,0DAAwD,GAAG,CAAC,OAAS,CACtE,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;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 * 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,7 +0,0 @@
1
- /**
2
- * Parses headers from config leaving only those that have defined values
3
- * @param partialHeaders
4
- */
5
- export declare function parseHeaders(partialHeaders?: Partial<Record<string, unknown>>): Record<string, string>;
6
- export declare function appendResourcePathToUrlIfNotPresent(url: string, path: string): string;
7
- //# sourceMappingURL=util.d.ts.map
package/build/esm/util.js DELETED
@@ -1,40 +0,0 @@
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
- /**
18
- * Parses headers from config leaving only those that have defined values
19
- * @param partialHeaders
20
- */
21
- export function parseHeaders(partialHeaders) {
22
- if (partialHeaders === void 0) { partialHeaders = {}; }
23
- var headers = {};
24
- Object.entries(partialHeaders).forEach(function (_a) {
25
- var key = _a[0], value = _a[1];
26
- if (typeof value !== 'undefined') {
27
- headers[key] = String(value);
28
- }
29
- else {
30
- diag.warn("Header \"" + key + "\" has wrong value and will be ignored");
31
- }
32
- });
33
- return headers;
34
- }
35
- export function appendResourcePathToUrlIfNotPresent(url, path) {
36
- if (url.match(/v\d\/(traces|metrics)$/))
37
- return url;
38
- return url + path;
39
- }
40
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,cAAqD;IAArD,+BAAA,EAAA,mBAAqD;IAErD,IAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,UAAC,EAAY;YAAX,GAAG,QAAA,EAAE,KAAK,QAAA;QACjD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;SAC9B;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,cAAW,GAAG,2CAAuC,CAAC,CAAC;SAClE;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,mCAAmC,CAAC,GAAW,EAAE,IAAY;IAC3E,IAAI,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC;QAAE,OAAO,GAAG,CAAC;IAEpD,OAAO,GAAG,GAAG,IAAI,CAAC;AACpB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag } from '@opentelemetry/api';\n\n/**\n * Parses headers from config leaving only those that have defined values\n * @param partialHeaders\n */\nexport function parseHeaders(\n partialHeaders: Partial<Record<string, unknown>> = {}\n): Record<string, string> {\n const headers: Record<string, string> = {};\n Object.entries(partialHeaders).forEach(([key, value]) => {\n if (typeof value !== 'undefined') {\n headers[key] = String(value);\n } else {\n diag.warn(`Header \"${key}\" has wrong value and will be ignored`);\n }\n });\n return headers;\n}\n\nexport function appendResourcePathToUrlIfNotPresent(url: string, path: string): string {\n if (url.match(/v\\d\\/(traces|metrics)$/)) return url;\n\n return url + path;\n}\n"]}
@@ -1,36 +0,0 @@
1
- import { SpanAttributes } from '@opentelemetry/api';
2
- import { ExportResult } 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
- protected _concurrencyLimit: number;
12
- protected _isShutdown: boolean;
13
- private _shuttingDownPromise;
14
- protected _sendingPromises: Promise<unknown>[];
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
- abstract onShutdown(): void;
31
- abstract onInit(config: T): void;
32
- abstract send(items: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
33
- abstract getDefaultUrl(config: T): string;
34
- abstract convert(objects: ExportItem[]): ServiceRequest;
35
- }
36
- //# sourceMappingURL=OTLPExporterBase.d.ts.map