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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +47 -21
  2. package/build/esm/index.d.ts +0 -4
  3. package/build/esm/index.js +0 -5
  4. package/build/esm/index.js.map +1 -1
  5. package/build/esm/platform/browser/OTLPTraceExporter.d.ts +4 -5
  6. package/build/esm/platform/browser/OTLPTraceExporter.js +7 -8
  7. package/build/esm/platform/browser/OTLPTraceExporter.js.map +1 -1
  8. package/build/esm/platform/browser/index.d.ts +0 -1
  9. package/build/esm/platform/browser/index.js +0 -1
  10. package/build/esm/platform/browser/index.js.map +1 -1
  11. package/build/esm/platform/index.d.ts +0 -1
  12. package/build/esm/platform/index.js +0 -1
  13. package/build/esm/platform/index.js.map +1 -1
  14. package/build/esm/platform/node/OTLPTraceExporter.d.ts +5 -5
  15. package/build/esm/platform/node/OTLPTraceExporter.js +8 -8
  16. package/build/esm/platform/node/OTLPTraceExporter.js.map +1 -1
  17. package/build/esm/platform/node/index.d.ts +0 -3
  18. package/build/esm/platform/node/index.js +0 -3
  19. package/build/esm/platform/node/index.js.map +1 -1
  20. package/build/esm/version.d.ts +1 -1
  21. package/build/esm/version.js +1 -1
  22. package/build/esm/version.js.map +1 -1
  23. package/build/esnext/index.d.ts +2 -0
  24. package/build/esnext/index.js +17 -0
  25. package/build/esnext/index.js.map +1 -0
  26. package/build/esnext/platform/browser/OTLPTraceExporter.d.ts +12 -0
  27. package/build/esnext/platform/browser/OTLPTraceExporter.js +42 -0
  28. package/build/esnext/platform/browser/OTLPTraceExporter.js.map +1 -0
  29. package/build/esnext/platform/browser/index.d.ts +2 -0
  30. package/build/esnext/platform/browser/index.js +17 -0
  31. package/build/esnext/platform/browser/index.js.map +1 -0
  32. package/build/esnext/platform/index.d.ts +2 -0
  33. package/build/esnext/platform/index.js +17 -0
  34. package/build/esnext/platform/index.js.map +1 -0
  35. package/build/esnext/platform/node/OTLPTraceExporter.d.ts +13 -0
  36. package/build/esnext/platform/node/OTLPTraceExporter.js +43 -0
  37. package/build/esnext/platform/node/OTLPTraceExporter.js.map +1 -0
  38. package/build/esnext/platform/node/index.d.ts +2 -0
  39. package/build/esnext/platform/node/index.js +17 -0
  40. package/build/esnext/platform/node/index.js.map +1 -0
  41. package/build/esnext/version.d.ts +2 -0
  42. package/build/esnext/version.js +18 -0
  43. package/build/esnext/version.js.map +1 -0
  44. package/build/src/index.d.ts +0 -4
  45. package/build/src/index.js +0 -8
  46. package/build/src/index.js.map +1 -1
  47. package/build/src/platform/browser/OTLPTraceExporter.d.ts +4 -5
  48. package/build/src/platform/browser/OTLPTraceExporter.js +11 -12
  49. package/build/src/platform/browser/OTLPTraceExporter.js.map +1 -1
  50. package/build/src/platform/browser/index.d.ts +0 -1
  51. package/build/src/platform/browser/index.js +0 -1
  52. package/build/src/platform/browser/index.js.map +1 -1
  53. package/build/src/platform/index.d.ts +0 -1
  54. package/build/src/platform/index.js +0 -3
  55. package/build/src/platform/index.js.map +1 -1
  56. package/build/src/platform/node/OTLPTraceExporter.d.ts +5 -5
  57. package/build/src/platform/node/OTLPTraceExporter.js +12 -12
  58. package/build/src/platform/node/OTLPTraceExporter.js.map +1 -1
  59. package/build/src/platform/node/index.d.ts +0 -3
  60. package/build/src/platform/node/index.js +0 -3
  61. package/build/src/platform/node/index.js.map +1 -1
  62. package/build/src/version.d.ts +1 -1
  63. package/build/src/version.js +1 -1
  64. package/build/src/version.js.map +1 -1
  65. package/package.json +32 -22
  66. package/build/esm/OTLPExporterBase.d.ts +0 -36
  67. package/build/esm/OTLPExporterBase.js +0 -114
  68. package/build/esm/OTLPExporterBase.js.map +0 -1
  69. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  70. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +0 -91
  71. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  72. package/build/esm/platform/browser/util.d.ts +0 -17
  73. package/build/esm/platform/browser/util.js +0 -77
  74. package/build/esm/platform/browser/util.js.map +0 -1
  75. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  76. package/build/esm/platform/node/OTLPExporterNodeBase.js +0 -82
  77. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +0 -1
  78. package/build/esm/platform/node/types.d.ts +0 -17
  79. package/build/esm/platform/node/types.js +0 -6
  80. package/build/esm/platform/node/types.js.map +0 -1
  81. package/build/esm/platform/node/util.d.ts +0 -17
  82. package/build/esm/platform/node/util.js +0 -113
  83. package/build/esm/platform/node/util.js.map +0 -1
  84. package/build/esm/transform.d.ts +0 -80
  85. package/build/esm/transform.js +0 -271
  86. package/build/esm/transform.js.map +0 -1
  87. package/build/esm/types.d.ts +0 -241
  88. package/build/esm/types.js +0 -176
  89. package/build/esm/types.js.map +0 -1
  90. package/build/esm/util.d.ts +0 -7
  91. package/build/esm/util.js +0 -40
  92. package/build/esm/util.js.map +0 -1
  93. package/build/src/OTLPExporterBase.d.ts +0 -36
  94. package/build/src/OTLPExporterBase.js +0 -113
  95. package/build/src/OTLPExporterBase.js.map +0 -1
  96. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +0 -18
  97. package/build/src/platform/browser/OTLPExporterBrowserBase.js +0 -74
  98. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +0 -1
  99. package/build/src/platform/browser/util.d.ts +0 -17
  100. package/build/src/platform/browser/util.js +0 -70
  101. package/build/src/platform/browser/util.js.map +0 -1
  102. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +0 -20
  103. package/build/src/platform/node/OTLPExporterNodeBase.js +0 -65
  104. package/build/src/platform/node/OTLPExporterNodeBase.js.map +0 -1
  105. package/build/src/platform/node/types.d.ts +0 -17
  106. package/build/src/platform/node/types.js +0 -9
  107. package/build/src/platform/node/types.js.map +0 -1
  108. package/build/src/platform/node/util.d.ts +0 -17
  109. package/build/src/platform/node/util.js +0 -107
  110. package/build/src/platform/node/util.js.map +0 -1
  111. package/build/src/transform.d.ts +0 -80
  112. package/build/src/transform.js +0 -282
  113. package/build/src/transform.js.map +0 -1
  114. package/build/src/types.d.ts +0 -241
  115. package/build/src/types.js +0 -160
  116. package/build/src/types.js.map +0 -1
  117. package/build/src/util.d.ts +0 -7
  118. package/build/src/util.js +0 -43
  119. package/build/src/util.js.map +0 -1
@@ -1,114 +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
- import { ExportResultCode } from '@opentelemetry/core';
18
- /**
19
- * Collector Exporter abstract base class
20
- */
21
- var OTLPExporterBase = /** @class */ (function () {
22
- /**
23
- * @param config
24
- */
25
- function OTLPExporterBase(config) {
26
- if (config === void 0) { config = {}; }
27
- this._isShutdown = false;
28
- this._shuttingDownPromise = Promise.resolve();
29
- this._sendingPromises = [];
30
- this.url = this.getDefaultUrl(config);
31
- if (typeof config.hostname === 'string') {
32
- this.hostname = config.hostname;
33
- }
34
- this.attributes = config.attributes;
35
- this.shutdown = this.shutdown.bind(this);
36
- this._concurrencyLimit =
37
- typeof config.concurrencyLimit === 'number'
38
- ? config.concurrencyLimit
39
- : Infinity;
40
- // platform dependent
41
- this.onInit(config);
42
- }
43
- /**
44
- * Export items.
45
- * @param items
46
- * @param resultCallback
47
- */
48
- OTLPExporterBase.prototype.export = function (items, resultCallback) {
49
- if (this._isShutdown) {
50
- resultCallback({
51
- code: ExportResultCode.FAILED,
52
- error: new Error('Exporter has been shutdown'),
53
- });
54
- return;
55
- }
56
- if (this._sendingPromises.length >= this._concurrencyLimit) {
57
- resultCallback({
58
- code: ExportResultCode.FAILED,
59
- error: new Error('Concurrent export limit reached'),
60
- });
61
- return;
62
- }
63
- this._export(items)
64
- .then(function () {
65
- resultCallback({ code: ExportResultCode.SUCCESS });
66
- })
67
- .catch(function (error) {
68
- resultCallback({ code: ExportResultCode.FAILED, error: error });
69
- });
70
- };
71
- OTLPExporterBase.prototype._export = function (items) {
72
- var _this = this;
73
- return new Promise(function (resolve, reject) {
74
- try {
75
- diag.debug('items to be sent', items);
76
- _this.send(items, resolve, reject);
77
- }
78
- catch (e) {
79
- reject(e);
80
- }
81
- });
82
- };
83
- /**
84
- * Shutdown the exporter.
85
- */
86
- OTLPExporterBase.prototype.shutdown = function () {
87
- var _this = this;
88
- if (this._isShutdown) {
89
- diag.debug('shutdown already started');
90
- return this._shuttingDownPromise;
91
- }
92
- this._isShutdown = true;
93
- diag.debug('shutdown started');
94
- this._shuttingDownPromise = new Promise(function (resolve, reject) {
95
- Promise.resolve()
96
- .then(function () {
97
- return _this.onShutdown();
98
- })
99
- .then(function () {
100
- return Promise.all(_this._sendingPromises);
101
- })
102
- .then(function () {
103
- resolve();
104
- })
105
- .catch(function (e) {
106
- reject(e);
107
- });
108
- });
109
- return this._shuttingDownPromise;
110
- };
111
- return OTLPExporterBase;
112
- }());
113
- export { OTLPExporterBase };
114
- //# sourceMappingURL=OTLPExporterBase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OTLPExporterBase.js","sourceRoot":"","sources":["../../src/OTLPExporterBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAkB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAOrE;;GAEG;AACH;IAaE;;OAEG;IACH,0BAAY,MAAmB;QAAnB,uBAAA,EAAA,SAAY,EAAO;QAPrB,gBAAW,GA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CAAC;YACZ,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAWH,uBAAC;AAAD,CAAC,AAlHD,IAkHC","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 } from '@opentelemetry/core';\nimport {\n OTLPExporterError,\n OTLPExporterConfigBase,\n ExportServiceError,\n} from './types';\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 protected _concurrencyLimit: number;\n protected _isShutdown: boolean = false;\n private _shuttingDownPromise: Promise<void> = Promise.resolve();\n protected _sendingPromises: Promise<unknown>[] = [];\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\n this._concurrencyLimit =\n typeof config.concurrencyLimit === 'number'\n ? config.concurrencyLimit\n : Infinity;\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._isShutdown) {\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 if (this._isShutdown) {\n diag.debug('shutdown already started');\n return this._shuttingDownPromise;\n }\n this._isShutdown = true;\n diag.debug('shutdown started');\n this._shuttingDownPromise = new Promise((resolve, reject) => {\n Promise.resolve()\n .then(() => {\n return this.onShutdown();\n })\n .then(() => {\n return Promise.all(this._sendingPromises);\n })\n .then(() => {\n resolve();\n })\n .catch(e => {\n reject(e);\n });\n });\n return this._shuttingDownPromise;\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"]}
@@ -1,18 +0,0 @@
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
@@ -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.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,C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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,CAAC,CAAC;QAC1C,SAAS,EAAE,CAAC;KACb;SAAM;QACL,IAAM,KAAK,GAAG,IAAI,SAAS,CAAC,iBAAiB,CAC3C,8BAA4B,IAAM,CACnC,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,GAAW,EACX,OAA+B,EAC/B,SAAqB,EACrB,OAAqD;IAErD,IAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;IACjC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtB,IAAM,cAAc,GAAG;QACrB,QAAQ,EAAE,kBAAkB;QAC5B,cAAc,EAAE,kBAAkB;KACnC,CAAC;IAEF,MAAM,CAAC,OAAO,uBACT,cAAc,GACd,OAAO,EACV,CAAC,OAAO,CAAC,UAAC,EAAM;YAAL,CAAC,QAAA,EAAE,CAAC,QAAA;QACf,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEf,GAAG,CAAC,kBAAkB,GAAG;QACvB,IAAI,GAAG,CAAC,UAAU,KAAK,cAAc,CAAC,IAAI,EAAE;YAC1C,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;gBAC1C,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBAChC,SAAS,EAAE,CAAC;aACb;iBAAM;gBACL,IAAM,KAAK,GAAG,IAAI,SAAS,CAAC,iBAAiB,CAC3C,wCAAsC,GAAG,CAAC,MAAM,MAAG,EACnD,GAAG,CAAC,MAAM,CACX,CAAC;gBAEF,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 * 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;;;;;;;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Ac,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