@opentelemetry/otlp-exporter-base 0.52.0 → 0.53.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 (169) hide show
  1. package/build/esm/OTLPExporterBase.d.ts +3 -0
  2. package/build/esm/OTLPExporterBase.js.map +1 -1
  3. package/build/esm/export-response.d.ts +14 -0
  4. package/build/esm/export-response.js +17 -0
  5. package/build/esm/export-response.js.map +1 -0
  6. package/build/esm/exporter-transport.d.ts +6 -0
  7. package/build/esm/exporter-transport.js +17 -0
  8. package/build/esm/exporter-transport.js.map +1 -0
  9. package/build/esm/index.d.ts +2 -0
  10. package/build/esm/index.js +3 -0
  11. package/build/esm/index.js.map +1 -1
  12. package/build/esm/is-export-retryable.d.ts +3 -0
  13. package/build/esm/is-export-retryable.js +35 -0
  14. package/build/esm/is-export-retryable.js.map +1 -0
  15. package/build/esm/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  16. package/build/esm/platform/browser/OTLPExporterBrowserBase.js +36 -27
  17. package/build/esm/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  18. package/build/esm/platform/browser/index.d.ts +0 -1
  19. package/build/esm/platform/browser/index.js +0 -1
  20. package/build/esm/platform/browser/index.js.map +1 -1
  21. package/build/esm/platform/browser/send-beacon-transport.d.ts +10 -0
  22. package/build/esm/platform/browser/send-beacon-transport.js +47 -0
  23. package/build/esm/platform/browser/send-beacon-transport.js.map +1 -0
  24. package/build/esm/platform/browser/xhr-transport.d.ts +11 -0
  25. package/build/esm/platform/browser/xhr-transport.js +101 -0
  26. package/build/esm/platform/browser/xhr-transport.js.map +1 -0
  27. package/build/esm/platform/index.d.ts +2 -2
  28. package/build/esm/platform/index.js +2 -2
  29. package/build/esm/platform/index.js.map +1 -1
  30. package/build/esm/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  31. package/build/esm/platform/node/OTLPExporterNodeBase.js +52 -12
  32. package/build/esm/platform/node/OTLPExporterNodeBase.js.map +1 -1
  33. package/build/esm/platform/node/http-exporter-transport.d.ts +4 -0
  34. package/build/esm/platform/node/http-exporter-transport.js +87 -0
  35. package/build/esm/platform/node/http-exporter-transport.js.map +1 -0
  36. package/build/esm/platform/node/http-transport-types.d.ts +12 -0
  37. package/build/esm/platform/node/http-transport-types.js +17 -0
  38. package/build/esm/platform/node/http-transport-types.js.map +1 -0
  39. package/build/esm/platform/node/http-transport-utils.d.ts +16 -0
  40. package/build/esm/platform/node/http-transport-utils.js +127 -0
  41. package/build/esm/platform/node/http-transport-utils.js.map +1 -0
  42. package/build/esm/platform/node/index.d.ts +0 -1
  43. package/build/esm/platform/node/index.js +0 -1
  44. package/build/esm/platform/node/index.js.map +1 -1
  45. package/build/esm/platform/node/util.d.ts +0 -16
  46. package/build/esm/platform/node/util.js +0 -164
  47. package/build/esm/platform/node/util.js.map +1 -1
  48. package/build/esm/retrying-transport.d.ts +8 -0
  49. package/build/esm/retrying-transport.js +119 -0
  50. package/build/esm/retrying-transport.js.map +1 -0
  51. package/build/esm/version.d.ts +1 -1
  52. package/build/esm/version.js +1 -1
  53. package/build/esm/version.js.map +1 -1
  54. package/build/esnext/OTLPExporterBase.d.ts +3 -0
  55. package/build/esnext/OTLPExporterBase.js.map +1 -1
  56. package/build/esnext/export-response.d.ts +14 -0
  57. package/build/esnext/export-response.js +17 -0
  58. package/build/esnext/export-response.js.map +1 -0
  59. package/build/esnext/exporter-transport.d.ts +6 -0
  60. package/build/esnext/exporter-transport.js +17 -0
  61. package/build/esnext/exporter-transport.js.map +1 -0
  62. package/build/esnext/index.d.ts +2 -0
  63. package/build/esnext/index.js +3 -0
  64. package/build/esnext/index.js.map +1 -1
  65. package/build/esnext/is-export-retryable.d.ts +3 -0
  66. package/build/esnext/is-export-retryable.js +35 -0
  67. package/build/esnext/is-export-retryable.js.map +1 -0
  68. package/build/esnext/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  69. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js +36 -16
  70. package/build/esnext/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  71. package/build/esnext/platform/browser/index.d.ts +0 -1
  72. package/build/esnext/platform/browser/index.js +0 -1
  73. package/build/esnext/platform/browser/index.js.map +1 -1
  74. package/build/esnext/platform/browser/send-beacon-transport.d.ts +10 -0
  75. package/build/esnext/platform/browser/send-beacon-transport.js +45 -0
  76. package/build/esnext/platform/browser/send-beacon-transport.js.map +1 -0
  77. package/build/esnext/platform/browser/xhr-transport.d.ts +11 -0
  78. package/build/esnext/platform/browser/xhr-transport.js +82 -0
  79. package/build/esnext/platform/browser/xhr-transport.js.map +1 -0
  80. package/build/esnext/platform/index.d.ts +2 -2
  81. package/build/esnext/platform/index.js +2 -2
  82. package/build/esnext/platform/index.js.map +1 -1
  83. package/build/esnext/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  84. package/build/esnext/platform/node/OTLPExporterNodeBase.js +52 -12
  85. package/build/esnext/platform/node/OTLPExporterNodeBase.js.map +1 -1
  86. package/build/esnext/platform/node/http-exporter-transport.d.ts +4 -0
  87. package/build/esnext/platform/node/http-exporter-transport.js +47 -0
  88. package/build/esnext/platform/node/http-exporter-transport.js.map +1 -0
  89. package/build/esnext/platform/node/http-transport-types.d.ts +12 -0
  90. package/build/esnext/platform/node/http-transport-types.js +17 -0
  91. package/build/esnext/platform/node/http-transport-types.js.map +1 -0
  92. package/build/esnext/platform/node/http-transport-utils.d.ts +16 -0
  93. package/build/esnext/platform/node/http-transport-utils.js +116 -0
  94. package/build/esnext/platform/node/http-transport-utils.js.map +1 -0
  95. package/build/esnext/platform/node/index.d.ts +0 -1
  96. package/build/esnext/platform/node/index.js +0 -1
  97. package/build/esnext/platform/node/index.js.map +1 -1
  98. package/build/esnext/platform/node/util.d.ts +0 -16
  99. package/build/esnext/platform/node/util.js +0 -151
  100. package/build/esnext/platform/node/util.js.map +1 -1
  101. package/build/esnext/retrying-transport.d.ts +8 -0
  102. package/build/esnext/retrying-transport.js +69 -0
  103. package/build/esnext/retrying-transport.js.map +1 -0
  104. package/build/esnext/version.d.ts +1 -1
  105. package/build/esnext/version.js +1 -1
  106. package/build/esnext/version.js.map +1 -1
  107. package/build/src/OTLPExporterBase.d.ts +3 -0
  108. package/build/src/OTLPExporterBase.js.map +1 -1
  109. package/build/src/export-response.d.ts +14 -0
  110. package/build/src/export-response.js +18 -0
  111. package/build/src/export-response.js.map +1 -0
  112. package/build/src/exporter-transport.d.ts +6 -0
  113. package/build/src/exporter-transport.js +18 -0
  114. package/build/src/exporter-transport.js.map +1 -0
  115. package/build/src/index.d.ts +2 -0
  116. package/build/src/index.js +15 -12
  117. package/build/src/index.js.map +1 -1
  118. package/build/src/is-export-retryable.d.ts +3 -0
  119. package/build/src/is-export-retryable.js +40 -0
  120. package/build/src/is-export-retryable.js.map +1 -0
  121. package/build/src/platform/browser/OTLPExporterBrowserBase.d.ts +3 -6
  122. package/build/src/platform/browser/OTLPExporterBrowserBase.js +36 -16
  123. package/build/src/platform/browser/OTLPExporterBrowserBase.js.map +1 -1
  124. package/build/src/platform/browser/index.d.ts +0 -1
  125. package/build/src/platform/browser/index.js +1 -3
  126. package/build/src/platform/browser/index.js.map +1 -1
  127. package/build/src/platform/browser/send-beacon-transport.d.ts +10 -0
  128. package/build/src/platform/browser/send-beacon-transport.js +49 -0
  129. package/build/src/platform/browser/send-beacon-transport.js.map +1 -0
  130. package/build/src/platform/browser/xhr-transport.d.ts +11 -0
  131. package/build/src/platform/browser/xhr-transport.js +86 -0
  132. package/build/src/platform/browser/xhr-transport.js.map +1 -0
  133. package/build/src/platform/index.d.ts +2 -2
  134. package/build/src/platform/index.js +1 -5
  135. package/build/src/platform/index.js.map +1 -1
  136. package/build/src/platform/node/OTLPExporterNodeBase.d.ts +5 -12
  137. package/build/src/platform/node/OTLPExporterNodeBase.js +52 -12
  138. package/build/src/platform/node/OTLPExporterNodeBase.js.map +1 -1
  139. package/build/src/platform/node/http-exporter-transport.d.ts +4 -0
  140. package/build/src/platform/node/http-exporter-transport.js +51 -0
  141. package/build/src/platform/node/http-exporter-transport.js.map +1 -0
  142. package/build/src/platform/node/http-transport-types.d.ts +12 -0
  143. package/build/src/platform/node/http-transport-types.js +18 -0
  144. package/build/src/platform/node/http-transport-types.js.map +1 -0
  145. package/build/src/platform/node/http-transport-utils.d.ts +16 -0
  146. package/build/src/platform/node/http-transport-utils.js +121 -0
  147. package/build/src/platform/node/http-transport-utils.js.map +1 -0
  148. package/build/src/platform/node/index.d.ts +0 -1
  149. package/build/src/platform/node/index.js +1 -5
  150. package/build/src/platform/node/index.js.map +1 -1
  151. package/build/src/platform/node/util.d.ts +0 -16
  152. package/build/src/platform/node/util.js +2 -155
  153. package/build/src/platform/node/util.js.map +1 -1
  154. package/build/src/retrying-transport.d.ts +8 -0
  155. package/build/src/retrying-transport.js +73 -0
  156. package/build/src/retrying-transport.js.map +1 -0
  157. package/build/src/version.d.ts +1 -1
  158. package/build/src/version.js +1 -1
  159. package/build/src/version.js.map +1 -1
  160. package/package.json +11 -12
  161. package/build/esm/platform/browser/util.d.ts +0 -21
  162. package/build/esm/platform/browser/util.js +0 -152
  163. package/build/esm/platform/browser/util.js.map +0 -1
  164. package/build/esnext/platform/browser/util.d.ts +0 -21
  165. package/build/esnext/platform/browser/util.js +0 -122
  166. package/build/esnext/platform/browser/util.js.map +0 -1
  167. package/build/src/platform/browser/util.d.ts +0 -21
  168. package/build/src/platform/browser/util.js +0 -127
  169. package/build/src/platform/browser/util.js.map +0 -1
@@ -1,23 +1,16 @@
1
- /// <reference types="node" />
2
- import type * as http from 'http';
3
- import type * as https from 'https';
4
1
  import { OTLPExporterBase } from '../../OTLPExporterBase';
5
- import { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
6
- import * as otlpTypes from '../../types';
2
+ import { OTLPExporterNodeConfigBase } from './types';
7
3
  import { ISerializer } from '@opentelemetry/otlp-transformer';
4
+ import { OTLPExporterError } from '../../types';
8
5
  /**
9
6
  * Collector Metric Exporter abstract base class
10
7
  */
11
8
  export declare abstract class OTLPExporterNodeBase<ExportItem, ServiceResponse> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {
12
- DEFAULT_HEADERS: Record<string, string>;
13
- headers: Record<string, string>;
14
- agent: http.Agent | https.Agent | undefined;
15
- compression: CompressionAlgorithm;
16
9
  private _serializer;
17
- private _contentType;
18
- constructor(config: OTLPExporterNodeConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, contentType: string);
10
+ private _transport;
11
+ constructor(config: OTLPExporterNodeConfigBase | undefined, serializer: ISerializer<ExportItem[], ServiceResponse>, signalSpecificHeaders: Record<string, string>);
19
12
  onInit(_config: OTLPExporterNodeConfigBase): void;
20
- send(objects: ExportItem[], onSuccess: () => void, onError: (error: otlpTypes.OTLPExporterError) => void): void;
13
+ send(objects: ExportItem[], onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
21
14
  onShutdown(): void;
22
15
  }
23
16
  //# sourceMappingURL=OTLPExporterNodeBase.d.ts.map
@@ -29,28 +29,51 @@ var __extends = (this && this.__extends) || (function () {
29
29
  };
30
30
  })();
31
31
  import { OTLPExporterBase } from '../../OTLPExporterBase';
32
- import { parseHeaders } from '../../util';
33
- import { createHttpAgent, sendWithHttp, configureCompression } from './util';
32
+ import { configureCompression } from './util';
34
33
  import { diag } from '@opentelemetry/api';
35
34
  import { getEnv, baggageUtils } from '@opentelemetry/core';
35
+ import { createHttpExporterTransport } from './http-exporter-transport';
36
+ import { OTLPExporterError } from '../../types';
37
+ import { createRetryingTransport } from '../../retrying-transport';
36
38
  /**
37
39
  * Collector Metric Exporter abstract base class
38
40
  */
39
41
  var OTLPExporterNodeBase = /** @class */ (function (_super) {
40
42
  __extends(OTLPExporterNodeBase, _super);
41
- function OTLPExporterNodeBase(config, serializer, contentType) {
43
+ function OTLPExporterNodeBase(config, serializer, signalSpecificHeaders) {
42
44
  if (config === void 0) { config = {}; }
45
+ var _a;
43
46
  var _this = _super.call(this, config) || this;
44
- _this.DEFAULT_HEADERS = {};
45
- _this._contentType = contentType;
46
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
48
  if (config.metadata) {
48
49
  diag.warn('Metadata cannot be set when using http');
49
50
  }
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 = configureCompression(config.compression);
53
51
  _this._serializer = serializer;
52
+ // populate keepAlive for use with new settings
53
+ if ((config === null || config === void 0 ? void 0 : config.keepAlive) != null) {
54
+ if (config.httpAgentOptions != null) {
55
+ if (config.httpAgentOptions.keepAlive == null) {
56
+ // specific setting is not set, populate with non-specific setting.
57
+ config.httpAgentOptions.keepAlive = config.keepAlive;
58
+ }
59
+ // do nothing, use specific setting otherwise
60
+ }
61
+ else {
62
+ // populate specific option if AgentOptions does not exist.
63
+ config.httpAgentOptions = {
64
+ keepAlive: config.keepAlive,
65
+ };
66
+ }
67
+ }
68
+ var nonSignalSpecificHeaders = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS);
69
+ _this._transport = createRetryingTransport({
70
+ transport: createHttpExporterTransport({
71
+ agentOptions: (_a = config.httpAgentOptions) !== null && _a !== void 0 ? _a : { keepAlive: true },
72
+ compression: configureCompression(config.compression),
73
+ headers: Object.assign({}, nonSignalSpecificHeaders, signalSpecificHeaders),
74
+ url: _this.url,
75
+ }),
76
+ });
54
77
  return _this;
55
78
  }
56
79
  OTLPExporterNodeBase.prototype.onInit = function (_config) { };
@@ -60,10 +83,27 @@ var OTLPExporterNodeBase = /** @class */ (function (_super) {
60
83
  diag.debug('Shutdown already started. Cannot send objects');
61
84
  return;
62
85
  }
63
- var promise = new Promise(function (resolve, reject) {
64
- var _a;
65
- sendWithHttp(_this, (_a = _this._serializer.serializeRequest(objects)) !== null && _a !== void 0 ? _a : new Uint8Array(), _this._contentType, resolve, reject);
66
- }).then(onSuccess, onError);
86
+ var data = this._serializer.serializeRequest(objects);
87
+ if (data == null) {
88
+ onError(new Error('Could not serialize message'));
89
+ return;
90
+ }
91
+ var promise = this._transport
92
+ .send(data, this.timeoutMillis)
93
+ .then(function (response) {
94
+ if (response.status === 'success') {
95
+ onSuccess();
96
+ }
97
+ else if (response.status === 'failure' && response.error) {
98
+ onError(response.error);
99
+ }
100
+ else if (response.status === 'retryable') {
101
+ onError(new OTLPExporterError('Export failed with retryable status'));
102
+ }
103
+ else {
104
+ onError(new OTLPExporterError('Export failed with unknown error'));
105
+ }
106
+ }, onError);
67
107
  this._sendingPromises.push(promise);
68
108
  var popPromise = function () {
69
109
  var index = _this._sendingPromises.indexOf(promise);
@@ -1 +1 @@
1
- {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH;IAGU,wCAAwD;IAQhE,8BACE,MAAuC,EACvC,UAAsD,EACtD,WAAmB;QAFnB,uBAAA,EAAA,WAAuC;QADzC,YAKE,kBAAM,MAAM,CAAC,SAcd;QA1BD,qBAAe,GAA2B,EAAE,CAAC;QAa3C,KAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,8DAA8D;QAC9D,IAAK,MAAc,CAAC,QAAQ,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;S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AAU,CAAC,CAAC;IACvC,CAAC;IAED,yCAAU,GAAV,cAAoB,CAAC;IACvB,2BAAC;AAAD,CAAC,AA/DD,CAGU,gBAAgB,GA4DzB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as http from 'http';\nimport type * as https from 'https';\n\nimport { OTLPExporterBase } from '../../OTLPExporterBase';\nimport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\nimport * as otlpTypes from '../../types';\nimport { parseHeaders } from '../../util';\nimport { createHttpAgent, sendWithHttp, configureCompression } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {\n DEFAULT_HEADERS: Record<string, string> = {};\n headers: Record<string, string>;\n agent: http.Agent | https.Agent | undefined;\n compression: CompressionAlgorithm;\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _contentType: string;\n\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n contentType: string\n ) {\n super(config);\n this._contentType = contentType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((config as any).metadata) {\n diag.warn('Metadata cannot be set when using http');\n }\n this.headers = Object.assign(\n this.DEFAULT_HEADERS,\n parseHeaders(config.headers),\n baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)\n );\n this.agent = createHttpAgent(config);\n this.compression = configureCompression(config.compression);\n this._serializer = serializer;\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: otlpTypes.OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const promise = new Promise<void>((resolve, reject) => {\n sendWithHttp(\n this,\n this._serializer.serializeRequest(objects) ?? new Uint8Array(),\n this._contentType,\n resolve,\n reject\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 onShutdown(): void {}\n}\n"]}
1
+ {"version":3,"file":"OTLPExporterNodeBase.js","sourceRoot":"","sources":["../../../../src/platform/node/OTLPExporterNodeBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;GAEG;AACH;IAGU,wCAAwD;IAIhE,8BACE,MAAuC,EACvC,UAAsD,EACtD,qBAA6C;QAF7C,uBAAA,EAAA,WAAuC;;QADzC,YAKE,kBAAM,MAAM,CAAC,SAsCd;QArCC,8DAA8D;QAC9D,IAAK,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zB","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 { OTLPExporterNodeConfigBase } from './types';\nimport { configureCompression } from './util';\nimport { diag } from '@opentelemetry/api';\nimport { getEnv, baggageUtils } from '@opentelemetry/core';\nimport { ISerializer } from '@opentelemetry/otlp-transformer';\nimport { IExporterTransport } from '../../exporter-transport';\nimport { createHttpExporterTransport } from './http-exporter-transport';\nimport { OTLPExporterError } from '../../types';\nimport { createRetryingTransport } from '../../retrying-transport';\n\n/**\n * Collector Metric Exporter abstract base class\n */\nexport abstract class OTLPExporterNodeBase<\n ExportItem,\n ServiceResponse,\n> extends OTLPExporterBase<OTLPExporterNodeConfigBase, ExportItem> {\n private _serializer: ISerializer<ExportItem[], ServiceResponse>;\n private _transport: IExporterTransport;\n\n constructor(\n config: OTLPExporterNodeConfigBase = {},\n serializer: ISerializer<ExportItem[], ServiceResponse>,\n signalSpecificHeaders: Record<string, string>\n ) {\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._serializer = serializer;\n\n // populate keepAlive for use with new settings\n if (config?.keepAlive != null) {\n if (config.httpAgentOptions != null) {\n if (config.httpAgentOptions.keepAlive == null) {\n // specific setting is not set, populate with non-specific setting.\n config.httpAgentOptions.keepAlive = config.keepAlive;\n }\n // do nothing, use specific setting otherwise\n } else {\n // populate specific option if AgentOptions does not exist.\n config.httpAgentOptions = {\n keepAlive: config.keepAlive,\n };\n }\n }\n const nonSignalSpecificHeaders = baggageUtils.parseKeyPairsIntoRecord(\n getEnv().OTEL_EXPORTER_OTLP_HEADERS\n );\n\n this._transport = createRetryingTransport({\n transport: createHttpExporterTransport({\n agentOptions: config.httpAgentOptions ?? { keepAlive: true },\n compression: configureCompression(config.compression),\n headers: Object.assign(\n {},\n nonSignalSpecificHeaders,\n signalSpecificHeaders\n ),\n url: this.url,\n }),\n });\n }\n\n onInit(_config: OTLPExporterNodeConfigBase): void {}\n\n send(\n objects: ExportItem[],\n onSuccess: () => void,\n onError: (error: OTLPExporterError) => void\n ): void {\n if (this._shutdownOnce.isCalled) {\n diag.debug('Shutdown already started. Cannot send objects');\n return;\n }\n\n const data = this._serializer.serializeRequest(objects);\n\n if (data == null) {\n onError(new Error('Could not serialize message'));\n return;\n }\n\n const promise = this._transport\n .send(data, this.timeoutMillis)\n .then(response => {\n if (response.status === 'success') {\n onSuccess();\n } else if (response.status === 'failure' && response.error) {\n onError(response.error);\n } else if (response.status === 'retryable') {\n onError(new OTLPExporterError('Export failed with retryable status'));\n } else {\n onError(new OTLPExporterError('Export failed with unknown error'));\n }\n }, 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 onShutdown(): void {}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { HttpRequestParameters } from './http-transport-types';
2
+ import { IExporterTransport } from '../../exporter-transport';
3
+ export declare function createHttpExporterTransport(parameters: HttpRequestParameters): IExporterTransport;
4
+ //# sourceMappingURL=http-exporter-transport.d.ts.map
@@ -0,0 +1,87 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (_) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ var HttpExporterTransport = /** @class */ (function () {
53
+ function HttpExporterTransport(_parameters) {
54
+ this._parameters = _parameters;
55
+ this._send = null;
56
+ this._agent = null;
57
+ }
58
+ HttpExporterTransport.prototype.send = function (data, timeoutMillis) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var _a, sendWithHttp, createHttpAgent;
61
+ var _this = this;
62
+ return __generator(this, function (_b) {
63
+ if (this._send == null) {
64
+ _a = require('./http-transport-utils'), sendWithHttp = _a.sendWithHttp, createHttpAgent = _a.createHttpAgent;
65
+ this._agent = createHttpAgent(this._parameters.url, this._parameters.agentOptions);
66
+ this._send = sendWithHttp;
67
+ }
68
+ return [2 /*return*/, new Promise(function (resolve) {
69
+ var _a;
70
+ // this will always be defined
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ (_a = _this._send) === null || _a === void 0 ? void 0 : _a.call(_this, _this._parameters, _this._agent, data, function (result) {
73
+ resolve(result);
74
+ }, timeoutMillis);
75
+ })];
76
+ });
77
+ });
78
+ };
79
+ HttpExporterTransport.prototype.shutdown = function () {
80
+ // intentionally left empty, nothing to do.
81
+ };
82
+ return HttpExporterTransport;
83
+ }());
84
+ export function createHttpExporterTransport(parameters) {
85
+ return new HttpExporterTransport(parameters);
86
+ }
87
+ //# sourceMappingURL=http-exporter-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exporter-transport.js","sourceRoot":"","sources":["../../../../src/platform/node/http-exporter-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcH;IAIE,+BAAoB,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;QAH9C,UAAK,GAAwB,IAAI,CAAC;QAClC,WAAM,GAAoC,IAAI,CAAC;IAEE,CAAC;IAEpD,oCAAI,GAAV,UAAW,IAAgB,EAAE,aAAqB;;;;;gBAChD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;oBAEhB,KAIF,OAAO,CAAC,wBAAwB,CAAC,EAHnC,YAAY,kBAAA,EACZ,eAAe,qBAAA,CAEqB;oBACtC,IAAI,CAAC,MAAM,GAAG,eAAe,CAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,EACpB,IAAI,CAAC,WAAW,CAAC,YAAY,CAC9B,CAAC;oBACF,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC;iBAC3B;gBAED,sBAAO,IAAI,OAAO,CAAiB,UAAA,OAAO;;wBACxC,8BAA8B;wBAC9B,oEAAoE;wBACpE,MAAA,KAAI,CAAC,KAAK,+CAAV,KAAI,EACF,KAAI,CAAC,WAAW,EAChB,KAAI,CAAC,MAAO,EACZ,IAAI,EACJ,UAAA,MAAM;4BACJ,OAAO,CAAC,MAAM,CAAC,CAAC;wBAClB,CAAC,EACD,aAAa,CACd,CAAC;oBACJ,CAAC,CAAC,EAAC;;;KACJ;IACD,wCAAQ,GAAR;QACE,2CAA2C;IAC7C,CAAC;IACH,4BAAC;AAAD,CAAC,AAtCD,IAsCC;AAED,MAAM,UAAU,2BAA2B,CACzC,UAAiC;IAEjC,OAAO,IAAI,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC/C,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 type {\n HttpRequestParameters,\n sendWithHttp,\n} from './http-transport-types';\n\n// NOTE: do not change these type imports to actual imports. Doing so WILL break `@opentelemetry/instrumentation-http`,\n// as they'd be imported before the http/https modules can be wrapped.\nimport type * as https from 'https';\nimport type * as http from 'http';\nimport { ExportResponse } from '../../export-response';\nimport { IExporterTransport } from '../../exporter-transport';\n\nclass HttpExporterTransport implements IExporterTransport {\n private _send: sendWithHttp | null = null;\n private _agent: http.Agent | https.Agent | null = null;\n\n constructor(private _parameters: HttpRequestParameters) {}\n\n async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {\n if (this._send == null) {\n // Lazy require to ensure that http/https is not required before instrumentations can wrap it.\n const {\n sendWithHttp,\n createHttpAgent,\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n } = require('./http-transport-utils');\n this._agent = createHttpAgent(\n this._parameters.url,\n this._parameters.agentOptions\n );\n this._send = sendWithHttp;\n }\n\n return new Promise<ExportResponse>(resolve => {\n // this will always be defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this._send?.(\n this._parameters,\n this._agent!,\n data,\n result => {\n resolve(result);\n },\n timeoutMillis\n );\n });\n }\n shutdown() {\n // intentionally left empty, nothing to do.\n }\n}\n\nexport function createHttpExporterTransport(\n parameters: HttpRequestParameters\n): IExporterTransport {\n return new HttpExporterTransport(parameters);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import type * as http from 'http';
3
+ import type * as https from 'https';
4
+ import { ExportResponse } from '../../export-response';
5
+ export declare type sendWithHttp = (params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number) => void;
6
+ export interface HttpRequestParameters {
7
+ url: string;
8
+ headers: Record<string, string>;
9
+ compression: 'gzip' | 'none';
10
+ agentOptions: http.AgentOptions | https.AgentOptions;
11
+ }
12
+ //# sourceMappingURL=http-transport-types.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=http-transport-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-types.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","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';\nimport { ExportResponse } from '../../export-response';\n\nexport type sendWithHttp = (\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n) => void;\n\nexport interface HttpRequestParameters {\n url: string;\n headers: Record<string, string>;\n compression: 'gzip' | 'none';\n agentOptions: http.AgentOptions | https.AgentOptions;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import * as https from 'https';
4
+ import { HttpRequestParameters } from './http-transport-types';
5
+ import { ExportResponse } from '../../export-response';
6
+ /**
7
+ * Sends data using http
8
+ * @param params
9
+ * @param agent
10
+ * @param data
11
+ * @param onDone
12
+ * @param timeoutMillis
13
+ */
14
+ export declare function sendWithHttp(params: HttpRequestParameters, agent: http.Agent | https.Agent, data: Uint8Array, onDone: (response: ExportResponse) => void, timeoutMillis: number): void;
15
+ export declare function createHttpAgent(rawUrl: string, agentOptions: http.AgentOptions | https.AgentOptions): http.Agent;
16
+ //# sourceMappingURL=http-transport-utils.d.ts.map
@@ -0,0 +1,127 @@
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 http from 'http';
28
+ import * as https from 'https';
29
+ import * as zlib from 'zlib';
30
+ import { Readable } from 'stream';
31
+ import { isExportRetryable, parseRetryAfterToMills, } from '../../is-export-retryable';
32
+ import { OTLPExporterError } from '../../types';
33
+ /**
34
+ * Sends data using http
35
+ * @param params
36
+ * @param agent
37
+ * @param data
38
+ * @param onDone
39
+ * @param timeoutMillis
40
+ */
41
+ export function sendWithHttp(params, agent, data, onDone, timeoutMillis) {
42
+ var parsedUrl = new URL(params.url);
43
+ var nodeVersion = Number(process.versions.node.split('.')[0]);
44
+ var options = {
45
+ hostname: parsedUrl.hostname,
46
+ port: parsedUrl.port,
47
+ path: parsedUrl.pathname,
48
+ method: 'POST',
49
+ headers: __assign({}, params.headers),
50
+ agent: agent,
51
+ };
52
+ var request = parsedUrl.protocol === 'http:' ? http.request : https.request;
53
+ var req = request(options, function (res) {
54
+ var responseData = [];
55
+ res.on('data', function (chunk) { return responseData.push(chunk); });
56
+ res.on('end', function () {
57
+ if (res.statusCode && res.statusCode < 299) {
58
+ onDone({
59
+ status: 'success',
60
+ data: Buffer.concat(responseData),
61
+ });
62
+ }
63
+ else if (res.statusCode && isExportRetryable(res.statusCode)) {
64
+ onDone({
65
+ status: 'retryable',
66
+ retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),
67
+ });
68
+ }
69
+ else {
70
+ var error = new OTLPExporterError(res.statusMessage, res.statusCode);
71
+ onDone({
72
+ status: 'failure',
73
+ error: error,
74
+ });
75
+ }
76
+ });
77
+ });
78
+ req.setTimeout(timeoutMillis, function () {
79
+ req.destroy();
80
+ onDone({
81
+ status: 'failure',
82
+ error: new Error('Request Timeout'),
83
+ });
84
+ });
85
+ req.on('error', function (error) {
86
+ onDone({
87
+ status: 'failure',
88
+ error: error,
89
+ });
90
+ });
91
+ var reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';
92
+ req.on(reportTimeoutErrorEvent, function () {
93
+ onDone({
94
+ status: 'failure',
95
+ error: new Error('Request timed out'),
96
+ });
97
+ });
98
+ compressAndSend(req, params.compression, data, function (error) {
99
+ onDone({
100
+ status: 'failure',
101
+ error: error,
102
+ });
103
+ });
104
+ }
105
+ function compressAndSend(req, compression, data, onError) {
106
+ var dataStream = readableFromUint8Array(data);
107
+ if (compression === 'gzip') {
108
+ req.setHeader('Content-Encoding', 'gzip');
109
+ dataStream = dataStream
110
+ .on('error', onError)
111
+ .pipe(zlib.createGzip())
112
+ .on('error', onError);
113
+ }
114
+ dataStream.pipe(req);
115
+ }
116
+ function readableFromUint8Array(buff) {
117
+ var readable = new Readable();
118
+ readable.push(buff);
119
+ readable.push(null);
120
+ return readable;
121
+ }
122
+ export function createHttpAgent(rawUrl, agentOptions) {
123
+ var parsedUrl = new URL(rawUrl);
124
+ var Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
125
+ return new Agent(agentOptions);
126
+ }
127
+ //# sourceMappingURL=http-transport-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-transport-utils.js","sourceRoot":"","sources":["../../../../src/platform/node/http-transport-utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA6B,EAC7B,KAA+B,EAC/B,IAAgB,EAChB,MAA0C,EAC1C,aAAqB;IAErB,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACtC,IAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhE,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,MAAM;QACd,OAAO,eACF,MAAM,CAAC,OAAO,CAClB;QACD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E,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,YAAoD;IAEpD,IAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,IAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACxE,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,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 http from 'http';\nimport * as https from 'https';\nimport * as zlib from 'zlib';\nimport { Readable } from 'stream';\nimport { HttpRequestParameters } from './http-transport-types';\nimport { ExportResponse } from '../../export-response';\nimport {\n isExportRetryable,\n parseRetryAfterToMills,\n} from '../../is-export-retryable';\nimport { OTLPExporterError } from '../../types';\n\n/**\n * Sends data using http\n * @param params\n * @param agent\n * @param data\n * @param onDone\n * @param timeoutMillis\n */\nexport function sendWithHttp(\n params: HttpRequestParameters,\n agent: http.Agent | https.Agent,\n data: Uint8Array,\n onDone: (response: ExportResponse) => void,\n timeoutMillis: number\n): void {\n const parsedUrl = new URL(params.url);\n const nodeVersion = Number(process.versions.node.split('.')[0]);\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 ...params.headers,\n },\n agent: agent,\n };\n\n const request = parsedUrl.protocol === 'http:' ? http.request : https.request;\n\n const req = request(options, (res: http.IncomingMessage) => {\n const responseData: Buffer[] = [];\n res.on('data', chunk => responseData.push(chunk));\n\n res.on('end', () => {\n if (res.statusCode && res.statusCode < 299) {\n onDone({\n status: 'success',\n data: Buffer.concat(responseData),\n });\n } else if (res.statusCode && isExportRetryable(res.statusCode)) {\n onDone({\n status: 'retryable',\n retryInMillis: parseRetryAfterToMills(res.headers['retry-after']),\n });\n } else {\n const error = new OTLPExporterError(res.statusMessage, res.statusCode);\n onDone({\n status: 'failure',\n error,\n });\n }\n });\n });\n\n req.setTimeout(timeoutMillis, () => {\n req.destroy();\n onDone({\n status: 'failure',\n error: new Error('Request Timeout'),\n });\n });\n req.on('error', (error: Error | any) => {\n onDone({\n status: 'failure',\n error: error,\n });\n });\n\n const reportTimeoutErrorEvent = nodeVersion >= 14 ? 'close' : 'abort';\n req.on(reportTimeoutErrorEvent, () => {\n onDone({\n status: 'failure',\n error: new Error('Request timed out'),\n });\n });\n\n compressAndSend(req, params.compression, data, (error: Error) => {\n onDone({\n status: 'failure',\n error,\n });\n });\n}\n\nfunction compressAndSend(\n req: http.ClientRequest,\n compression: 'gzip' | 'none',\n data: Uint8Array,\n onError: (error: Error) => void\n) {\n let dataStream = readableFromUint8Array(data);\n\n if (compression === 'gzip') {\n req.setHeader('Content-Encoding', 'gzip');\n dataStream = dataStream\n .on('error', onError)\n .pipe(zlib.createGzip())\n .on('error', onError);\n }\n\n dataStream.pipe(req);\n}\n\nfunction readableFromUint8Array(buff: string | Uint8Array): Readable {\n const readable = new Readable();\n readable.push(buff);\n readable.push(null);\n\n return readable;\n}\n\nexport function createHttpAgent(\n rawUrl: string,\n agentOptions: http.AgentOptions | https.AgentOptions\n) {\n const parsedUrl = new URL(rawUrl);\n const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;\n return new Agent(agentOptions);\n}\n"]}
@@ -1,4 +1,3 @@
1
1
  export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
2
- export { sendWithHttp, createHttpAgent, configureCompression } from './util';
3
2
  export { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -14,6 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
17
- export { sendWithHttp, createHttpAgent, configureCompression } from './util';
18
17
  export { CompressionAlgorithm } from './types';
19
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,EAA8B,oBAAoB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { sendWithHttp, createHttpAgent, configureCompression } from './util';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAA8B,oBAAoB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { OTLPExporterNodeBase } from './OTLPExporterNodeBase';\nexport { OTLPExporterNodeConfigBase, CompressionAlgorithm } from './types';\n"]}
@@ -1,19 +1,3 @@
1
- /// <reference types="node" />
2
- import * as http from 'http';
3
- import * as https from 'https';
4
- import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
5
- import { OTLPExporterNodeConfigBase } from '.';
6
1
  import { CompressionAlgorithm } from './types';
7
- import { OTLPExporterError } from '../../types';
8
- /**
9
- * Sends data using http
10
- * @param collector
11
- * @param data
12
- * @param contentType
13
- * @param onSuccess
14
- * @param onError
15
- */
16
- export declare function sendWithHttp<ExportItem, ServiceResponse>(collector: OTLPExporterNodeBase<ExportItem, ServiceResponse>, data: string | Uint8Array, contentType: string, onSuccess: () => void, onError: (error: OTLPExporterError) => void): void;
17
- export declare function createHttpAgent(config: OTLPExporterNodeConfigBase): http.Agent | https.Agent | undefined;
18
2
  export declare function configureCompression(compression: CompressionAlgorithm | undefined): CompressionAlgorithm;
19
3
  //# sourceMappingURL=util.d.ts.map