autotel-aws 0.13.13 → 0.13.14

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 (205) hide show
  1. package/dist/attributes.cjs +155 -46
  2. package/dist/attributes.cjs.map +1 -1
  3. package/dist/attributes.d.cts +64 -62
  4. package/dist/attributes.d.cts.map +1 -0
  5. package/dist/attributes.d.ts +64 -62
  6. package/dist/attributes.d.ts.map +1 -0
  7. package/dist/attributes.js +146 -3
  8. package/dist/attributes.js.map +1 -1
  9. package/dist/cloudwatch.cjs +324 -358
  10. package/dist/cloudwatch.cjs.map +1 -1
  11. package/dist/cloudwatch.d.cts +126 -153
  12. package/dist/cloudwatch.d.cts.map +1 -0
  13. package/dist/cloudwatch.d.ts +126 -153
  14. package/dist/cloudwatch.d.ts.map +1 -0
  15. package/dist/cloudwatch.js +323 -356
  16. package/dist/cloudwatch.js.map +1 -1
  17. package/dist/config-D8QZwF1e.d.ts +123 -0
  18. package/dist/config-D8QZwF1e.d.ts.map +1 -0
  19. package/dist/config-SPkMWWXY.d.cts +123 -0
  20. package/dist/config-SPkMWWXY.d.cts.map +1 -0
  21. package/dist/dynamodb.cjs +89 -11
  22. package/dist/dynamodb.cjs.map +1 -1
  23. package/dist/dynamodb.d.cts +15 -63
  24. package/dist/dynamodb.d.cts.map +1 -0
  25. package/dist/dynamodb.d.ts +15 -63
  26. package/dist/dynamodb.d.ts.map +1 -0
  27. package/dist/dynamodb.js +90 -4
  28. package/dist/dynamodb.js.map +1 -1
  29. package/dist/eventbridge.cjs +423 -261
  30. package/dist/eventbridge.cjs.map +1 -1
  31. package/dist/eventbridge.d.cts +113 -174
  32. package/dist/eventbridge.d.cts.map +1 -0
  33. package/dist/eventbridge.d.ts +113 -174
  34. package/dist/eventbridge.d.ts.map +1 -0
  35. package/dist/eventbridge.js +422 -259
  36. package/dist/eventbridge.js.map +1 -1
  37. package/dist/index.cjs +117 -241
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +42 -55
  40. package/dist/index.d.cts.map +1 -0
  41. package/dist/index.d.ts +42 -55
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +62 -41
  44. package/dist/index.js.map +1 -1
  45. package/dist/kinesis.cjs +485 -20
  46. package/dist/kinesis.cjs.map +1 -1
  47. package/dist/kinesis.d.cts +179 -226
  48. package/dist/kinesis.d.cts.map +1 -0
  49. package/dist/kinesis.d.ts +179 -226
  50. package/dist/kinesis.d.ts.map +1 -0
  51. package/dist/kinesis.js +484 -5
  52. package/dist/kinesis.js.map +1 -1
  53. package/dist/lambda-B0LQa5vS.d.ts +168 -0
  54. package/dist/lambda-B0LQa5vS.d.ts.map +1 -0
  55. package/dist/lambda-DR33vPpL.cjs +500 -0
  56. package/dist/lambda-DR33vPpL.cjs.map +1 -0
  57. package/dist/lambda-DYyKH-f-.js +453 -0
  58. package/dist/lambda-DYyKH-f-.js.map +1 -0
  59. package/dist/lambda-DnroO4Od.d.cts +168 -0
  60. package/dist/lambda-DnroO4Od.d.cts.map +1 -0
  61. package/dist/lambda-auto.cjs +33 -16
  62. package/dist/lambda-auto.cjs.map +1 -1
  63. package/dist/lambda-auto.d.cts +1 -2
  64. package/dist/lambda-auto.d.ts +1 -2
  65. package/dist/lambda-auto.js +35 -15
  66. package/dist/lambda-auto.js.map +1 -1
  67. package/dist/lambda.cjs +11 -42
  68. package/dist/lambda.d.cts +3 -231
  69. package/dist/lambda.d.ts +3 -231
  70. package/dist/lambda.js +3 -5
  71. package/dist/s3.cjs +70 -11
  72. package/dist/s3.cjs.map +1 -1
  73. package/dist/s3.d.cts +15 -51
  74. package/dist/s3.d.cts.map +1 -0
  75. package/dist/s3.d.ts +15 -51
  76. package/dist/s3.d.ts.map +1 -0
  77. package/dist/s3.js +71 -4
  78. package/dist/s3.js.map +1 -1
  79. package/dist/sdk-C-o7ngkk.js +198 -0
  80. package/dist/sdk-C-o7ngkk.js.map +1 -0
  81. package/dist/sdk-C9Nvlh7R.cjs +222 -0
  82. package/dist/sdk-C9Nvlh7R.cjs.map +1 -0
  83. package/dist/sdk-CXqc4o_q.d.ts +135 -0
  84. package/dist/sdk-CXqc4o_q.d.ts.map +1 -0
  85. package/dist/sdk-DkAItj4z.d.cts +135 -0
  86. package/dist/sdk-DkAItj4z.d.cts.map +1 -0
  87. package/dist/sdk-wrapper-BDrcyEQ_.cjs +161 -0
  88. package/dist/sdk-wrapper-BDrcyEQ_.cjs.map +1 -0
  89. package/dist/sdk-wrapper-BVr62EfA.js +120 -0
  90. package/dist/sdk-wrapper-BVr62EfA.js.map +1 -0
  91. package/dist/sdk.cjs +8 -31
  92. package/dist/sdk.d.cts +3 -156
  93. package/dist/sdk.d.ts +3 -156
  94. package/dist/sdk.js +3 -6
  95. package/dist/sns.cjs +305 -16
  96. package/dist/sns.cjs.map +1 -1
  97. package/dist/sns.d.cts +109 -155
  98. package/dist/sns.d.cts.map +1 -0
  99. package/dist/sns.d.ts +109 -155
  100. package/dist/sns.d.ts.map +1 -0
  101. package/dist/sns.js +305 -5
  102. package/dist/sns.js.map +1 -1
  103. package/dist/sqs.cjs +455 -20
  104. package/dist/sqs.cjs.map +1 -1
  105. package/dist/sqs.d.cts +191 -240
  106. package/dist/sqs.d.cts.map +1 -0
  107. package/dist/sqs.d.ts +191 -240
  108. package/dist/sqs.d.ts.map +1 -0
  109. package/dist/sqs.js +454 -5
  110. package/dist/sqs.js.map +1 -1
  111. package/dist/step-functions.cjs +557 -32
  112. package/dist/step-functions.cjs.map +1 -1
  113. package/dist/step-functions.d.cts +155 -210
  114. package/dist/step-functions.d.cts.map +1 -0
  115. package/dist/step-functions.d.ts +155 -210
  116. package/dist/step-functions.d.ts.map +1 -0
  117. package/dist/step-functions.js +553 -5
  118. package/dist/step-functions.js.map +1 -1
  119. package/dist/testing.cjs +60 -58
  120. package/dist/testing.cjs.map +1 -1
  121. package/dist/testing.d.cts +20 -23
  122. package/dist/testing.d.cts.map +1 -0
  123. package/dist/testing.d.ts +20 -23
  124. package/dist/testing.d.ts.map +1 -0
  125. package/dist/testing.js +59 -57
  126. package/dist/testing.js.map +1 -1
  127. package/dist/{types-B2Mi8Goj.d.cts → types-0uHbJsBN.d.ts} +5 -7
  128. package/dist/types-0uHbJsBN.d.ts.map +1 -0
  129. package/dist/types-DOUDks8I.d.cts +71 -0
  130. package/dist/types-DOUDks8I.d.cts.map +1 -0
  131. package/dist/types-DOUDks8I.d.ts +71 -0
  132. package/dist/types-DOUDks8I.d.ts.map +1 -0
  133. package/dist/{types-BqTI4s4V.d.ts → types-iyHj03Q1.d.cts} +5 -7
  134. package/dist/types-iyHj03Q1.d.cts.map +1 -0
  135. package/dist/xray-B46i6z6K.js +59 -0
  136. package/dist/xray-B46i6z6K.js.map +1 -0
  137. package/dist/xray-CG4jciQs.d.ts +19 -0
  138. package/dist/xray-CG4jciQs.d.ts.map +1 -0
  139. package/dist/xray-Cd2UiVRA.cjs +75 -0
  140. package/dist/xray-Cd2UiVRA.cjs.map +1 -0
  141. package/dist/xray-DDcKCKKo.d.cts +19 -0
  142. package/dist/xray-DDcKCKKo.d.cts.map +1 -0
  143. package/dist/xray.cjs +10 -23
  144. package/dist/xray.d.cts +3 -24
  145. package/dist/xray.d.ts +3 -24
  146. package/dist/xray.js +3 -5
  147. package/package.json +5 -5
  148. package/dist/chunk-35F3UBOO.cjs +0 -48
  149. package/dist/chunk-35F3UBOO.cjs.map +0 -1
  150. package/dist/chunk-4THGOYZL.js +0 -387
  151. package/dist/chunk-4THGOYZL.js.map +0 -1
  152. package/dist/chunk-CIGXV6HA.js +0 -192
  153. package/dist/chunk-CIGXV6HA.js.map +0 -1
  154. package/dist/chunk-DGUM43GV.js +0 -10
  155. package/dist/chunk-DGUM43GV.js.map +0 -1
  156. package/dist/chunk-DHHLKZHI.cjs +0 -23
  157. package/dist/chunk-DHHLKZHI.cjs.map +0 -1
  158. package/dist/chunk-HMTKKKKP.cjs +0 -390
  159. package/dist/chunk-HMTKKKKP.cjs.map +0 -1
  160. package/dist/chunk-I4CKQ4RD.js +0 -153
  161. package/dist/chunk-I4CKQ4RD.js.map +0 -1
  162. package/dist/chunk-JEQ2X3Z6.cjs +0 -12
  163. package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
  164. package/dist/chunk-JL33WEVE.js +0 -341
  165. package/dist/chunk-JL33WEVE.js.map +0 -1
  166. package/dist/chunk-JMSFE6FJ.js +0 -24
  167. package/dist/chunk-JMSFE6FJ.js.map +0 -1
  168. package/dist/chunk-JPDJPOIB.js +0 -78
  169. package/dist/chunk-JPDJPOIB.js.map +0 -1
  170. package/dist/chunk-KNRQYDAS.cjs +0 -394
  171. package/dist/chunk-KNRQYDAS.cjs.map +0 -1
  172. package/dist/chunk-NQ65Y5AI.cjs +0 -195
  173. package/dist/chunk-NQ65Y5AI.cjs.map +0 -1
  174. package/dist/chunk-OB4XTAVK.cjs +0 -345
  175. package/dist/chunk-OB4XTAVK.cjs.map +0 -1
  176. package/dist/chunk-OHFR7WX5.js +0 -341
  177. package/dist/chunk-OHFR7WX5.js.map +0 -1
  178. package/dist/chunk-PZGYL7XZ.js +0 -40
  179. package/dist/chunk-PZGYL7XZ.js.map +0 -1
  180. package/dist/chunk-Q3DMMQ7K.cjs +0 -164
  181. package/dist/chunk-Q3DMMQ7K.cjs.map +0 -1
  182. package/dist/chunk-SPC4VYOI.cjs +0 -350
  183. package/dist/chunk-SPC4VYOI.cjs.map +0 -1
  184. package/dist/chunk-UZEJV2YD.cjs +0 -139
  185. package/dist/chunk-UZEJV2YD.cjs.map +0 -1
  186. package/dist/chunk-VZHQH75L.cjs +0 -26
  187. package/dist/chunk-VZHQH75L.cjs.map +0 -1
  188. package/dist/chunk-X6BY6PCK.js +0 -386
  189. package/dist/chunk-X6BY6PCK.js.map +0 -1
  190. package/dist/chunk-XOF2H2PI.cjs +0 -84
  191. package/dist/chunk-XOF2H2PI.cjs.map +0 -1
  192. package/dist/chunk-YG56NRIO.js +0 -131
  193. package/dist/chunk-YG56NRIO.js.map +0 -1
  194. package/dist/chunk-ZPDRKCAR.js +0 -21
  195. package/dist/chunk-ZPDRKCAR.js.map +0 -1
  196. package/dist/config-DbZv4bpy.d.ts +0 -125
  197. package/dist/config-srkLBXZH.d.cts +0 -125
  198. package/dist/lambda.cjs.map +0 -1
  199. package/dist/lambda.js.map +0 -1
  200. package/dist/sdk.cjs.map +0 -1
  201. package/dist/sdk.js.map +0 -1
  202. package/dist/types-B9IaHmGa.d.cts +0 -73
  203. package/dist/types-B9IaHmGa.d.ts +0 -73
  204. package/dist/xray.cjs.map +0 -1
  205. package/dist/xray.js.map +0 -1
@@ -1,389 +1,356 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _opentelemetry_core = require("@opentelemetry/core");
3
+ let _opentelemetry_otlp_transformer = require("@opentelemetry/otlp-transformer");
4
+ let _opentelemetry_sdk_metrics = require("@opentelemetry/sdk-metrics");
2
5
 
3
- require('./chunk-JEQ2X3Z6.cjs');
4
- var core = require('@opentelemetry/core');
5
- var otlpTransformer = require('@opentelemetry/otlp-transformer');
6
- var sdkMetrics = require('@opentelemetry/sdk-metrics');
7
-
8
- // src/cloudwatch/endpoints.ts
6
+ //#region src/cloudwatch/endpoints.ts
7
+ /** Traces signed against the `xray` service. */
9
8
  function cloudWatchTracesEndpoint({ region }) {
10
- return `https://xray.${region}.amazonaws.com/v1/traces`;
9
+ return `https://xray.${region}.amazonaws.com/v1/traces`;
11
10
  }
11
+ /** Logs — signed against the `logs` service. Requires log group/stream headers. */
12
12
  function cloudWatchLogsEndpoint({ region }) {
13
- return `https://logs.${region}.amazonaws.com/v1/logs`;
13
+ return `https://logs.${region}.amazonaws.com/v1/logs`;
14
14
  }
15
+ /** Metrics — signed against the `monitoring` service. */
15
16
  function cloudWatchMetricsEndpoint({ region }) {
16
- return `https://monitoring.${region}.amazonaws.com/v1/metrics`;
17
+ return `https://monitoring.${region}.amazonaws.com/v1/metrics`;
17
18
  }
18
- var SIGV4_SERVICE = {
19
- traces: "xray",
20
- logs: "logs",
21
- metrics: "monitoring"
19
+ /**
20
+ * The SigV4 service name used when signing requests for each endpoint.
21
+ * These do NOT always match the host prefix — they're the canonical
22
+ * AWS service identifiers used by the SigV4 signer.
23
+ */
24
+ const SIGV4_SERVICE = {
25
+ traces: "xray",
26
+ logs: "logs",
27
+ metrics: "monitoring"
22
28
  };
23
29
 
24
- // src/cloudwatch/sigv4.ts
30
+ //#endregion
31
+ //#region src/cloudwatch/sigv4.ts
32
+ /**
33
+ * Compute SigV4-signed headers for an OTLP HTTP POST to a CloudWatch endpoint.
34
+ *
35
+ * Throws if the optional `@smithy/signature-v4` / `@aws-crypto/sha256-js`
36
+ * peer dependencies aren't installed — install them alongside autotel-aws
37
+ * when you want to ship telemetry directly from app code (no collector).
38
+ */
25
39
  async function signCloudWatchOtlpRequest(input) {
26
- const { SignatureV4 } = await loadSigV4();
27
- const { Sha256 } = await loadSha256();
28
- const credentials = await resolveCredentials(input.credentials);
29
- const parsed = new URL(input.url);
30
- const contentType = input.contentType ?? "application/json";
31
- const headers = {
32
- host: parsed.host,
33
- "content-type": contentType,
34
- ...input.contentEncoding && { "content-encoding": input.contentEncoding },
35
- ...input.additionalHeaders
36
- };
37
- const signer = new SignatureV4({
38
- service: SIGV4_SERVICE[input.signal],
39
- region: input.region,
40
- credentials,
41
- sha256: Sha256
42
- });
43
- const signed = await signer.sign({
44
- method: "POST",
45
- protocol: parsed.protocol,
46
- hostname: parsed.hostname,
47
- port: parsed.port ? Number(parsed.port) : void 0,
48
- path: parsed.pathname + parsed.search,
49
- headers,
50
- body: input.body
51
- });
52
- return signed.headers;
40
+ const { SignatureV4 } = await loadSigV4();
41
+ const { Sha256 } = await loadSha256();
42
+ const credentials = await resolveCredentials(input.credentials);
43
+ const parsed = new URL(input.url);
44
+ const contentType = input.contentType ?? "application/json";
45
+ const headers = {
46
+ host: parsed.host,
47
+ "content-type": contentType,
48
+ ...input.contentEncoding && { "content-encoding": input.contentEncoding },
49
+ ...input.additionalHeaders
50
+ };
51
+ return (await new SignatureV4({
52
+ service: SIGV4_SERVICE[input.signal],
53
+ region: input.region,
54
+ credentials,
55
+ sha256: Sha256
56
+ }).sign({
57
+ method: "POST",
58
+ protocol: parsed.protocol,
59
+ hostname: parsed.hostname,
60
+ port: parsed.port ? Number(parsed.port) : void 0,
61
+ path: parsed.pathname + parsed.search,
62
+ headers,
63
+ body: input.body
64
+ })).headers;
53
65
  }
54
66
  async function resolveCredentials(source) {
55
- if (typeof source === "function") return source();
56
- if (source) return source;
57
- return loadDefaultCredentials();
67
+ if (typeof source === "function") return source();
68
+ if (source) return source;
69
+ return loadDefaultCredentials();
58
70
  }
59
71
  async function loadDefaultCredentials() {
60
- try {
61
- const mod = await import('@aws-sdk/credential-providers');
62
- return await mod.fromNodeProviderChain()();
63
- } catch (error) {
64
- throw new Error(
65
- "autotel-aws/cloudwatch: no credentials supplied and `@aws-sdk/credential-providers` is not installed. Either pass `credentials` explicitly or install the package.",
66
- { cause: error }
67
- );
68
- }
72
+ try {
73
+ return await (await import("@aws-sdk/credential-providers")).fromNodeProviderChain()();
74
+ } catch (error) {
75
+ throw new Error("autotel-aws/cloudwatch: no credentials supplied and `@aws-sdk/credential-providers` is not installed. Either pass `credentials` explicitly or install the package.", { cause: error });
76
+ }
69
77
  }
70
78
  async function loadSigV4() {
71
- try {
72
- return await import('@smithy/signature-v4');
73
- } catch (error) {
74
- throw new Error(
75
- "autotel-aws/cloudwatch: `@smithy/signature-v4` is required to sign OTLP requests. Install it (and `@aws-crypto/sha256-js`) alongside autotel-aws.",
76
- { cause: error }
77
- );
78
- }
79
+ try {
80
+ return await import("@smithy/signature-v4");
81
+ } catch (error) {
82
+ throw new Error("autotel-aws/cloudwatch: `@smithy/signature-v4` is required to sign OTLP requests. Install it (and `@aws-crypto/sha256-js`) alongside autotel-aws.", { cause: error });
83
+ }
79
84
  }
80
85
  async function loadSha256() {
81
- try {
82
- return await import('@aws-crypto/sha256-js');
83
- } catch (error) {
84
- throw new Error(
85
- "autotel-aws/cloudwatch: `@aws-crypto/sha256-js` is required to sign OTLP requests. Install it alongside `@smithy/signature-v4`.",
86
- { cause: error }
87
- );
88
- }
86
+ try {
87
+ return await import("@aws-crypto/sha256-js");
88
+ } catch (error) {
89
+ throw new Error("autotel-aws/cloudwatch: `@aws-crypto/sha256-js` is required to sign OTLP requests. Install it alongside `@smithy/signature-v4`.", { cause: error });
90
+ }
89
91
  }
92
+
93
+ //#endregion
94
+ //#region src/cloudwatch/trace-exporter.ts
95
+ /**
96
+ * OTLP/JSON exporter for CloudWatch's traces endpoint.
97
+ *
98
+ * Use with `BatchSpanProcessor` or `SimpleSpanProcessor` from
99
+ * `@opentelemetry/sdk-trace-base`. For Lambda, `SimpleSpanProcessor`
100
+ * (synchronous export per span) is fine for small workloads;
101
+ * `BatchSpanProcessor` is better for higher-throughput functions but
102
+ * needs `forceFlush()` before the handler returns.
103
+ */
90
104
  var CloudWatchTraceExporter = class {
91
- region;
92
- endpoint;
93
- credentials;
94
- timeoutMs;
95
- fetchImpl;
96
- shutdownOnce = false;
97
- constructor(config = {}) {
98
- const region = config.region ?? process.env.AWS_REGION;
99
- if (!region) {
100
- throw new Error(
101
- "CloudWatchTraceExporter: `region` is required (pass it explicitly or set AWS_REGION)."
102
- );
103
- }
104
- this.region = region;
105
- this.endpoint = config.endpoint ?? cloudWatchTracesEndpoint({ region });
106
- this.credentials = config.credentials;
107
- this.timeoutMs = config.timeoutMs ?? 1e4;
108
- this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
109
- if (typeof this.fetchImpl !== "function") {
110
- throw new TypeError(
111
- "CloudWatchTraceExporter: global `fetch` is not available \u2014 pass `fetchImpl` explicitly (Node 18+ has it natively)."
112
- );
113
- }
114
- }
115
- export(spans, resultCallback) {
116
- if (this.shutdownOnce) {
117
- resultCallback({
118
- code: core.ExportResultCode.FAILED,
119
- error: new Error("CloudWatchTraceExporter: already shut down")
120
- });
121
- return;
122
- }
123
- if (spans.length === 0) {
124
- resultCallback({ code: core.ExportResultCode.SUCCESS });
125
- return;
126
- }
127
- this.sendBatch(spans).then(
128
- () => resultCallback({ code: core.ExportResultCode.SUCCESS }),
129
- (error) => resultCallback({
130
- code: core.ExportResultCode.FAILED,
131
- error: error instanceof Error ? error : new Error(String(error))
132
- })
133
- );
134
- }
135
- async shutdown() {
136
- this.shutdownOnce = true;
137
- }
138
- async forceFlush() {
139
- }
140
- async sendBatch(spans) {
141
- const body = otlpTransformer.JsonTraceSerializer.serializeRequest(spans);
142
- if (!body) {
143
- throw new Error("CloudWatchTraceExporter: serializer produced no body");
144
- }
145
- const headers = await signCloudWatchOtlpRequest({
146
- url: this.endpoint,
147
- body,
148
- region: this.region,
149
- signal: "traces",
150
- credentials: this.credentials,
151
- contentType: "application/json"
152
- });
153
- const controller = new AbortController();
154
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
155
- let response;
156
- try {
157
- response = await this.fetchImpl(this.endpoint, {
158
- method: "POST",
159
- headers,
160
- body,
161
- signal: controller.signal
162
- });
163
- } finally {
164
- clearTimeout(timer);
165
- }
166
- if (!response.ok) {
167
- const text = await safeReadText(response);
168
- throw new Error(
169
- `CloudWatchTraceExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim()
170
- );
171
- }
172
- }
105
+ region;
106
+ endpoint;
107
+ credentials;
108
+ timeoutMs;
109
+ fetchImpl;
110
+ shutdownOnce = false;
111
+ constructor(config = {}) {
112
+ const region = config.region ?? process.env.AWS_REGION;
113
+ if (!region) throw new Error("CloudWatchTraceExporter: `region` is required (pass it explicitly or set AWS_REGION).");
114
+ this.region = region;
115
+ this.endpoint = config.endpoint ?? cloudWatchTracesEndpoint({ region });
116
+ this.credentials = config.credentials;
117
+ this.timeoutMs = config.timeoutMs ?? 1e4;
118
+ this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
119
+ if (typeof this.fetchImpl !== "function") throw new TypeError("CloudWatchTraceExporter: global `fetch` is not available — pass `fetchImpl` explicitly (Node 18+ has it natively).");
120
+ }
121
+ export(spans, resultCallback) {
122
+ if (this.shutdownOnce) {
123
+ resultCallback({
124
+ code: _opentelemetry_core.ExportResultCode.FAILED,
125
+ error: /* @__PURE__ */ new Error("CloudWatchTraceExporter: already shut down")
126
+ });
127
+ return;
128
+ }
129
+ if (spans.length === 0) {
130
+ resultCallback({ code: _opentelemetry_core.ExportResultCode.SUCCESS });
131
+ return;
132
+ }
133
+ this.sendBatch(spans).then(() => resultCallback({ code: _opentelemetry_core.ExportResultCode.SUCCESS }), (error) => resultCallback({
134
+ code: _opentelemetry_core.ExportResultCode.FAILED,
135
+ error: error instanceof Error ? error : new Error(String(error))
136
+ }));
137
+ }
138
+ async shutdown() {
139
+ this.shutdownOnce = true;
140
+ }
141
+ async forceFlush() {}
142
+ async sendBatch(spans) {
143
+ const body = _opentelemetry_otlp_transformer.JsonTraceSerializer.serializeRequest(spans);
144
+ if (!body) throw new Error("CloudWatchTraceExporter: serializer produced no body");
145
+ const headers = await signCloudWatchOtlpRequest({
146
+ url: this.endpoint,
147
+ body,
148
+ region: this.region,
149
+ signal: "traces",
150
+ credentials: this.credentials,
151
+ contentType: "application/json"
152
+ });
153
+ const controller = new AbortController();
154
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
155
+ let response;
156
+ try {
157
+ response = await this.fetchImpl(this.endpoint, {
158
+ method: "POST",
159
+ headers,
160
+ body,
161
+ signal: controller.signal
162
+ });
163
+ } finally {
164
+ clearTimeout(timer);
165
+ }
166
+ if (!response.ok) {
167
+ const text = await safeReadText$2(response);
168
+ throw new Error(`CloudWatchTraceExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim());
169
+ }
170
+ }
173
171
  };
174
- async function safeReadText(response) {
175
- try {
176
- return await response.text();
177
- } catch {
178
- return "";
179
- }
172
+ async function safeReadText$2(response) {
173
+ try {
174
+ return await response.text();
175
+ } catch {
176
+ return "";
177
+ }
180
178
  }
179
+
180
+ //#endregion
181
+ //#region src/cloudwatch/log-exporter.ts
181
182
  var CloudWatchLogExporter = class {
182
- region;
183
- endpoint;
184
- credentials;
185
- logGroup;
186
- logStream;
187
- truncatableFields;
188
- timeoutMs;
189
- fetchImpl;
190
- shutdownOnce = false;
191
- constructor(config = {}) {
192
- const region = config.region ?? process.env.AWS_REGION;
193
- if (!region) {
194
- throw new Error(
195
- "CloudWatchLogExporter: `region` is required (pass it explicitly or set AWS_REGION)."
196
- );
197
- }
198
- const logGroup = config.logGroup ?? process.env.AWS_LAMBDA_LOG_GROUP_NAME;
199
- const logStream = config.logStream ?? process.env.AWS_LAMBDA_LOG_STREAM_NAME;
200
- if (!logGroup || !logStream) {
201
- throw new Error(
202
- "CloudWatchLogExporter: `logGroup` and `logStream` are required (in Lambda they come from AWS_LAMBDA_LOG_GROUP_NAME / AWS_LAMBDA_LOG_STREAM_NAME)."
203
- );
204
- }
205
- this.region = region;
206
- this.endpoint = config.endpoint ?? cloudWatchLogsEndpoint({ region });
207
- this.credentials = config.credentials;
208
- this.logGroup = logGroup;
209
- this.logStream = logStream;
210
- this.truncatableFields = config.truncatableFields;
211
- this.timeoutMs = config.timeoutMs ?? 1e4;
212
- this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
213
- if (typeof this.fetchImpl !== "function") {
214
- throw new TypeError(
215
- "CloudWatchLogExporter: global `fetch` is not available \u2014 pass `fetchImpl` explicitly."
216
- );
217
- }
218
- }
219
- export(logs, resultCallback) {
220
- if (this.shutdownOnce) {
221
- resultCallback({
222
- code: core.ExportResultCode.FAILED,
223
- error: new Error("CloudWatchLogExporter: already shut down")
224
- });
225
- return;
226
- }
227
- if (logs.length === 0) {
228
- resultCallback({ code: core.ExportResultCode.SUCCESS });
229
- return;
230
- }
231
- this.sendBatch(logs).then(
232
- () => resultCallback({ code: core.ExportResultCode.SUCCESS }),
233
- (error) => resultCallback({
234
- code: core.ExportResultCode.FAILED,
235
- error: error instanceof Error ? error : new Error(String(error))
236
- })
237
- );
238
- }
239
- async shutdown() {
240
- this.shutdownOnce = true;
241
- }
242
- async forceFlush() {
243
- }
244
- async sendBatch(logs) {
245
- const body = otlpTransformer.JsonLogsSerializer.serializeRequest(logs);
246
- if (!body) {
247
- throw new Error("CloudWatchLogExporter: serializer produced no body");
248
- }
249
- const additionalHeaders = {
250
- "x-aws-log-group": this.logGroup,
251
- "x-aws-log-stream": this.logStream
252
- };
253
- if (this.truncatableFields) {
254
- additionalHeaders["x-aws-truncatable-fields"] = this.truncatableFields;
255
- }
256
- const headers = await signCloudWatchOtlpRequest({
257
- url: this.endpoint,
258
- body,
259
- region: this.region,
260
- signal: "logs",
261
- credentials: this.credentials,
262
- contentType: "application/json",
263
- additionalHeaders
264
- });
265
- const controller = new AbortController();
266
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
267
- let response;
268
- try {
269
- response = await this.fetchImpl(this.endpoint, {
270
- method: "POST",
271
- headers,
272
- body,
273
- signal: controller.signal
274
- });
275
- } finally {
276
- clearTimeout(timer);
277
- }
278
- if (!response.ok) {
279
- const text = await safeReadText2(response);
280
- throw new Error(
281
- `CloudWatchLogExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim()
282
- );
283
- }
284
- }
183
+ region;
184
+ endpoint;
185
+ credentials;
186
+ logGroup;
187
+ logStream;
188
+ truncatableFields;
189
+ timeoutMs;
190
+ fetchImpl;
191
+ shutdownOnce = false;
192
+ constructor(config = {}) {
193
+ const region = config.region ?? process.env.AWS_REGION;
194
+ if (!region) throw new Error("CloudWatchLogExporter: `region` is required (pass it explicitly or set AWS_REGION).");
195
+ const logGroup = config.logGroup ?? process.env.AWS_LAMBDA_LOG_GROUP_NAME;
196
+ const logStream = config.logStream ?? process.env.AWS_LAMBDA_LOG_STREAM_NAME;
197
+ if (!logGroup || !logStream) throw new Error("CloudWatchLogExporter: `logGroup` and `logStream` are required (in Lambda they come from AWS_LAMBDA_LOG_GROUP_NAME / AWS_LAMBDA_LOG_STREAM_NAME).");
198
+ this.region = region;
199
+ this.endpoint = config.endpoint ?? cloudWatchLogsEndpoint({ region });
200
+ this.credentials = config.credentials;
201
+ this.logGroup = logGroup;
202
+ this.logStream = logStream;
203
+ this.truncatableFields = config.truncatableFields;
204
+ this.timeoutMs = config.timeoutMs ?? 1e4;
205
+ this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
206
+ if (typeof this.fetchImpl !== "function") throw new TypeError("CloudWatchLogExporter: global `fetch` is not available — pass `fetchImpl` explicitly.");
207
+ }
208
+ export(logs, resultCallback) {
209
+ if (this.shutdownOnce) {
210
+ resultCallback({
211
+ code: _opentelemetry_core.ExportResultCode.FAILED,
212
+ error: /* @__PURE__ */ new Error("CloudWatchLogExporter: already shut down")
213
+ });
214
+ return;
215
+ }
216
+ if (logs.length === 0) {
217
+ resultCallback({ code: _opentelemetry_core.ExportResultCode.SUCCESS });
218
+ return;
219
+ }
220
+ this.sendBatch(logs).then(() => resultCallback({ code: _opentelemetry_core.ExportResultCode.SUCCESS }), (error) => resultCallback({
221
+ code: _opentelemetry_core.ExportResultCode.FAILED,
222
+ error: error instanceof Error ? error : new Error(String(error))
223
+ }));
224
+ }
225
+ async shutdown() {
226
+ this.shutdownOnce = true;
227
+ }
228
+ async forceFlush() {}
229
+ async sendBatch(logs) {
230
+ const body = _opentelemetry_otlp_transformer.JsonLogsSerializer.serializeRequest(logs);
231
+ if (!body) throw new Error("CloudWatchLogExporter: serializer produced no body");
232
+ const additionalHeaders = {
233
+ "x-aws-log-group": this.logGroup,
234
+ "x-aws-log-stream": this.logStream
235
+ };
236
+ if (this.truncatableFields) additionalHeaders["x-aws-truncatable-fields"] = this.truncatableFields;
237
+ const headers = await signCloudWatchOtlpRequest({
238
+ url: this.endpoint,
239
+ body,
240
+ region: this.region,
241
+ signal: "logs",
242
+ credentials: this.credentials,
243
+ contentType: "application/json",
244
+ additionalHeaders
245
+ });
246
+ const controller = new AbortController();
247
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
248
+ let response;
249
+ try {
250
+ response = await this.fetchImpl(this.endpoint, {
251
+ method: "POST",
252
+ headers,
253
+ body,
254
+ signal: controller.signal
255
+ });
256
+ } finally {
257
+ clearTimeout(timer);
258
+ }
259
+ if (!response.ok) {
260
+ const text = await safeReadText$1(response);
261
+ throw new Error(`CloudWatchLogExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim());
262
+ }
263
+ }
285
264
  };
286
- async function safeReadText2(response) {
287
- try {
288
- return await response.text();
289
- } catch {
290
- return "";
291
- }
265
+ async function safeReadText$1(response) {
266
+ try {
267
+ return await response.text();
268
+ } catch {
269
+ return "";
270
+ }
292
271
  }
293
- var DEFAULT_TEMPORALITY = (_instrumentType) => sdkMetrics.AggregationTemporality.DELTA;
272
+
273
+ //#endregion
274
+ //#region src/cloudwatch/metric-exporter.ts
275
+ const DEFAULT_TEMPORALITY = (_instrumentType) => _opentelemetry_sdk_metrics.AggregationTemporality.DELTA;
294
276
  var CloudWatchMetricExporter = class {
295
- region;
296
- endpoint;
297
- credentials;
298
- timeoutMs;
299
- fetchImpl;
300
- temporalitySelector;
301
- shutdownOnce = false;
302
- constructor(config = {}) {
303
- const region = config.region ?? process.env.AWS_REGION;
304
- if (!region) {
305
- throw new Error(
306
- "CloudWatchMetricExporter: `region` is required (pass it explicitly or set AWS_REGION)."
307
- );
308
- }
309
- this.region = region;
310
- this.endpoint = config.endpoint ?? cloudWatchMetricsEndpoint({ region });
311
- this.credentials = config.credentials;
312
- this.timeoutMs = config.timeoutMs ?? 1e4;
313
- this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
314
- this.temporalitySelector = config.temporalitySelector ?? DEFAULT_TEMPORALITY;
315
- if (typeof this.fetchImpl !== "function") {
316
- throw new TypeError(
317
- "CloudWatchMetricExporter: global `fetch` is not available \u2014 pass `fetchImpl` explicitly."
318
- );
319
- }
320
- }
321
- export(metrics, resultCallback) {
322
- if (this.shutdownOnce) {
323
- resultCallback({
324
- code: core.ExportResultCode.FAILED,
325
- error: new Error("CloudWatchMetricExporter: already shut down")
326
- });
327
- return;
328
- }
329
- this.sendBatch(metrics).then(
330
- () => resultCallback({ code: core.ExportResultCode.SUCCESS }),
331
- (error) => resultCallback({
332
- code: core.ExportResultCode.FAILED,
333
- error: error instanceof Error ? error : new Error(String(error))
334
- })
335
- );
336
- }
337
- async shutdown() {
338
- this.shutdownOnce = true;
339
- }
340
- async forceFlush() {
341
- }
342
- selectAggregationTemporality(instrumentType) {
343
- return this.temporalitySelector(instrumentType);
344
- }
345
- async sendBatch(metrics) {
346
- const body = otlpTransformer.JsonMetricsSerializer.serializeRequest(metrics);
347
- if (!body) {
348
- throw new Error("CloudWatchMetricExporter: serializer produced no body");
349
- }
350
- const headers = await signCloudWatchOtlpRequest({
351
- url: this.endpoint,
352
- body,
353
- region: this.region,
354
- signal: "metrics",
355
- credentials: this.credentials,
356
- contentType: "application/json"
357
- });
358
- const controller = new AbortController();
359
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
360
- let response;
361
- try {
362
- response = await this.fetchImpl(this.endpoint, {
363
- method: "POST",
364
- headers,
365
- body,
366
- signal: controller.signal
367
- });
368
- } finally {
369
- clearTimeout(timer);
370
- }
371
- if (!response.ok) {
372
- const text = await safeReadText3(response);
373
- throw new Error(
374
- `CloudWatchMetricExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim()
375
- );
376
- }
377
- }
277
+ region;
278
+ endpoint;
279
+ credentials;
280
+ timeoutMs;
281
+ fetchImpl;
282
+ temporalitySelector;
283
+ shutdownOnce = false;
284
+ constructor(config = {}) {
285
+ const region = config.region ?? process.env.AWS_REGION;
286
+ if (!region) throw new Error("CloudWatchMetricExporter: `region` is required (pass it explicitly or set AWS_REGION).");
287
+ this.region = region;
288
+ this.endpoint = config.endpoint ?? cloudWatchMetricsEndpoint({ region });
289
+ this.credentials = config.credentials;
290
+ this.timeoutMs = config.timeoutMs ?? 1e4;
291
+ this.fetchImpl = config.fetchImpl ?? globalThis.fetch;
292
+ this.temporalitySelector = config.temporalitySelector ?? DEFAULT_TEMPORALITY;
293
+ if (typeof this.fetchImpl !== "function") throw new TypeError("CloudWatchMetricExporter: global `fetch` is not available — pass `fetchImpl` explicitly.");
294
+ }
295
+ export(metrics, resultCallback) {
296
+ if (this.shutdownOnce) {
297
+ resultCallback({
298
+ code: _opentelemetry_core.ExportResultCode.FAILED,
299
+ error: /* @__PURE__ */ new Error("CloudWatchMetricExporter: already shut down")
300
+ });
301
+ return;
302
+ }
303
+ this.sendBatch(metrics).then(() => resultCallback({ code: _opentelemetry_core.ExportResultCode.SUCCESS }), (error) => resultCallback({
304
+ code: _opentelemetry_core.ExportResultCode.FAILED,
305
+ error: error instanceof Error ? error : new Error(String(error))
306
+ }));
307
+ }
308
+ async shutdown() {
309
+ this.shutdownOnce = true;
310
+ }
311
+ async forceFlush() {}
312
+ selectAggregationTemporality(instrumentType) {
313
+ return this.temporalitySelector(instrumentType);
314
+ }
315
+ async sendBatch(metrics) {
316
+ const body = _opentelemetry_otlp_transformer.JsonMetricsSerializer.serializeRequest(metrics);
317
+ if (!body) throw new Error("CloudWatchMetricExporter: serializer produced no body");
318
+ const headers = await signCloudWatchOtlpRequest({
319
+ url: this.endpoint,
320
+ body,
321
+ region: this.region,
322
+ signal: "metrics",
323
+ credentials: this.credentials,
324
+ contentType: "application/json"
325
+ });
326
+ const controller = new AbortController();
327
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
328
+ let response;
329
+ try {
330
+ response = await this.fetchImpl(this.endpoint, {
331
+ method: "POST",
332
+ headers,
333
+ body,
334
+ signal: controller.signal
335
+ });
336
+ } finally {
337
+ clearTimeout(timer);
338
+ }
339
+ if (!response.ok) {
340
+ const text = await safeReadText(response);
341
+ throw new Error(`CloudWatchMetricExporter: HTTP ${response.status} ${response.statusText} ${text}`.trim());
342
+ }
343
+ }
378
344
  };
379
- async function safeReadText3(response) {
380
- try {
381
- return await response.text();
382
- } catch {
383
- return "";
384
- }
345
+ async function safeReadText(response) {
346
+ try {
347
+ return await response.text();
348
+ } catch {
349
+ return "";
350
+ }
385
351
  }
386
352
 
353
+ //#endregion
387
354
  exports.CloudWatchLogExporter = CloudWatchLogExporter;
388
355
  exports.CloudWatchMetricExporter = CloudWatchMetricExporter;
389
356
  exports.CloudWatchTraceExporter = CloudWatchTraceExporter;
@@ -392,5 +359,4 @@ exports.cloudWatchLogsEndpoint = cloudWatchLogsEndpoint;
392
359
  exports.cloudWatchMetricsEndpoint = cloudWatchMetricsEndpoint;
393
360
  exports.cloudWatchTracesEndpoint = cloudWatchTracesEndpoint;
394
361
  exports.signCloudWatchOtlpRequest = signCloudWatchOtlpRequest;
395
- //# sourceMappingURL=cloudwatch.cjs.map
396
362
  //# sourceMappingURL=cloudwatch.cjs.map