autotel-aws 0.2.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.
- package/LICENSE +21 -0
- package/README.md +540 -0
- package/dist/attributes.cjs +49 -0
- package/dist/attributes.cjs.map +1 -0
- package/dist/attributes.d.cts +117 -0
- package/dist/attributes.d.ts +117 -0
- package/dist/attributes.js +4 -0
- package/dist/attributes.js.map +1 -0
- package/dist/chunk-35F3UBOO.cjs +48 -0
- package/dist/chunk-35F3UBOO.cjs.map +1 -0
- package/dist/chunk-4TGVGEUN.cjs +84 -0
- package/dist/chunk-4TGVGEUN.cjs.map +1 -0
- package/dist/chunk-CIGXV6HA.js +192 -0
- package/dist/chunk-CIGXV6HA.js.map +1 -0
- package/dist/chunk-D5INYMRP.cjs +350 -0
- package/dist/chunk-D5INYMRP.cjs.map +1 -0
- package/dist/chunk-DF5PT3JK.js +387 -0
- package/dist/chunk-DF5PT3JK.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-DHHLKZHI.cjs +23 -0
- package/dist/chunk-DHHLKZHI.cjs.map +1 -0
- package/dist/chunk-FKZOELBT.js +78 -0
- package/dist/chunk-FKZOELBT.js.map +1 -0
- package/dist/chunk-HMTKKKKP.cjs +390 -0
- package/dist/chunk-HMTKKKKP.cjs.map +1 -0
- package/dist/chunk-I4CKQ4RD.js +153 -0
- package/dist/chunk-I4CKQ4RD.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-JMSFE6FJ.js +24 -0
- package/dist/chunk-JMSFE6FJ.js.map +1 -0
- package/dist/chunk-KUIOI74B.cjs +394 -0
- package/dist/chunk-KUIOI74B.cjs.map +1 -0
- package/dist/chunk-NQ65Y5AI.cjs +195 -0
- package/dist/chunk-NQ65Y5AI.cjs.map +1 -0
- package/dist/chunk-OB4XTAVK.cjs +345 -0
- package/dist/chunk-OB4XTAVK.cjs.map +1 -0
- package/dist/chunk-OHFR7WX5.js +341 -0
- package/dist/chunk-OHFR7WX5.js.map +1 -0
- package/dist/chunk-PZGYL7XZ.js +40 -0
- package/dist/chunk-PZGYL7XZ.js.map +1 -0
- package/dist/chunk-Q3DMMQ7K.cjs +164 -0
- package/dist/chunk-Q3DMMQ7K.cjs.map +1 -0
- package/dist/chunk-UZEJV2YD.cjs +139 -0
- package/dist/chunk-UZEJV2YD.cjs.map +1 -0
- package/dist/chunk-V4IQWFYN.js +341 -0
- package/dist/chunk-V4IQWFYN.js.map +1 -0
- package/dist/chunk-VZHQH75L.cjs +26 -0
- package/dist/chunk-VZHQH75L.cjs.map +1 -0
- package/dist/chunk-X6BY6PCK.js +386 -0
- package/dist/chunk-X6BY6PCK.js.map +1 -0
- package/dist/chunk-YG56NRIO.js +131 -0
- package/dist/chunk-YG56NRIO.js.map +1 -0
- package/dist/chunk-ZPDRKCAR.js +21 -0
- package/dist/chunk-ZPDRKCAR.js.map +1 -0
- package/dist/config-C7zV8Zm6.d.cts +125 -0
- package/dist/config-DxjTT8jd.d.ts +125 -0
- package/dist/dynamodb.cjs +14 -0
- package/dist/dynamodb.cjs.map +1 -0
- package/dist/dynamodb.d.cts +93 -0
- package/dist/dynamodb.d.ts +93 -0
- package/dist/dynamodb.js +5 -0
- package/dist/dynamodb.js.map +1 -0
- package/dist/eventbridge.cjs +279 -0
- package/dist/eventbridge.cjs.map +1 -0
- package/dist/eventbridge.d.cts +360 -0
- package/dist/eventbridge.d.ts +360 -0
- package/dist/eventbridge.js +273 -0
- package/dist/eventbridge.js.map +1 -0
- package/dist/index.cjs +251 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/kinesis.cjs +23 -0
- package/dist/kinesis.cjs.map +1 -0
- package/dist/kinesis.d.cts +360 -0
- package/dist/kinesis.d.ts +360 -0
- package/dist/kinesis.js +6 -0
- package/dist/kinesis.js.map +1 -0
- package/dist/lambda-auto.cjs +19 -0
- package/dist/lambda-auto.cjs.map +1 -0
- package/dist/lambda-auto.d.cts +2 -0
- package/dist/lambda-auto.d.ts +2 -0
- package/dist/lambda-auto.js +17 -0
- package/dist/lambda-auto.js.map +1 -0
- package/dist/lambda.cjs +42 -0
- package/dist/lambda.cjs.map +1 -0
- package/dist/lambda.d.cts +231 -0
- package/dist/lambda.d.ts +231 -0
- package/dist/lambda.js +5 -0
- package/dist/lambda.js.map +1 -0
- package/dist/s3.cjs +14 -0
- package/dist/s3.cjs.map +1 -0
- package/dist/s3.d.cts +77 -0
- package/dist/s3.d.ts +77 -0
- package/dist/s3.js +5 -0
- package/dist/s3.js.map +1 -0
- package/dist/sdk.cjs +31 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +155 -0
- package/dist/sdk.d.ts +155 -0
- package/dist/sdk.js +6 -0
- package/dist/sdk.js.map +1 -0
- package/dist/sns.cjs +19 -0
- package/dist/sns.cjs.map +1 -0
- package/dist/sns.d.cts +256 -0
- package/dist/sns.d.ts +256 -0
- package/dist/sns.js +6 -0
- package/dist/sns.js.map +1 -0
- package/dist/sqs.cjs +23 -0
- package/dist/sqs.cjs.map +1 -0
- package/dist/sqs.d.cts +384 -0
- package/dist/sqs.d.ts +384 -0
- package/dist/sqs.js +6 -0
- package/dist/sqs.js.map +1 -0
- package/dist/step-functions.cjs +35 -0
- package/dist/step-functions.cjs.map +1 -0
- package/dist/step-functions.d.cts +423 -0
- package/dist/step-functions.d.ts +423 -0
- package/dist/step-functions.js +6 -0
- package/dist/step-functions.js.map +1 -0
- package/dist/testing.cjs +61 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +39 -0
- package/dist/testing.d.ts +39 -0
- package/dist/testing.js +58 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-3_ak5jhy.d.cts +76 -0
- package/dist/types-3_ak5jhy.d.ts +76 -0
- package/dist/types-UiBv_I_M.d.ts +16 -0
- package/dist/types-kTFVdSqO.d.cts +16 -0
- package/dist/xray.cjs +26 -0
- package/dist/xray.cjs.map +1 -0
- package/dist/xray.d.cts +23 -0
- package/dist/xray.d.ts +23 -0
- package/dist/xray.js +5 -0
- package/dist/xray.js.map +1 -0
- package/package.json +184 -0
package/dist/sns.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { TraceContext } from 'autotel';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SNS-specific instrumentation
|
|
5
|
+
*
|
|
6
|
+
* Provides semantic helpers for tracing SNS operations with proper OpenTelemetry
|
|
7
|
+
* messaging semantic conventions. Automatically sets `messaging.*` attributes.
|
|
8
|
+
*
|
|
9
|
+
* @example Publish to topic
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { traceSNS } from 'autotel-aws/sns';
|
|
12
|
+
* import { SNSClient, PublishCommand } from '@aws-sdk/client-sns';
|
|
13
|
+
*
|
|
14
|
+
* const sns = new SNSClient({});
|
|
15
|
+
*
|
|
16
|
+
* export const publishNotification = traceSNS({
|
|
17
|
+
* topicArn: 'arn:aws:sns:us-east-1:123456789:notifications'
|
|
18
|
+
* })(ctx => async (message: string, subject?: string) => {
|
|
19
|
+
* const result = await sns.send(new PublishCommand({
|
|
20
|
+
* TopicArn: 'arn:aws:sns:us-east-1:123456789:notifications',
|
|
21
|
+
* Message: message,
|
|
22
|
+
* Subject: subject
|
|
23
|
+
* }));
|
|
24
|
+
*
|
|
25
|
+
* if (result.MessageId) {
|
|
26
|
+
* ctx.setAttribute('messaging.message.id', result.MessageId);
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return result;
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Usage: await publishNotification('User signed up', 'New User');
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Publish to mobile endpoint
|
|
36
|
+
* ```typescript
|
|
37
|
+
* export const sendPushNotification = traceSNS({
|
|
38
|
+
* operation: 'publish',
|
|
39
|
+
* topicArn: 'arn:aws:sns:us-east-1:123456789:app/APNS/my-app'
|
|
40
|
+
* })(ctx => async (endpointArn: string, payload: object) => {
|
|
41
|
+
* ctx.setAttribute('aws.sns.target_arn', endpointArn);
|
|
42
|
+
* return await sns.send(new PublishCommand({
|
|
43
|
+
* TargetArn: endpointArn,
|
|
44
|
+
* Message: JSON.stringify(payload),
|
|
45
|
+
* MessageStructure: 'json'
|
|
46
|
+
* }));
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* SNS operation configuration
|
|
53
|
+
*/
|
|
54
|
+
interface TraceSNSConfig {
|
|
55
|
+
/**
|
|
56
|
+
* SNS topic ARN
|
|
57
|
+
* Sets `messaging.destination.name` attribute.
|
|
58
|
+
*/
|
|
59
|
+
topicArn: string;
|
|
60
|
+
/**
|
|
61
|
+
* Operation type (defaults to 'publish')
|
|
62
|
+
*/
|
|
63
|
+
operation?: 'publish' | 'subscribe' | 'unsubscribe';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Trace SNS operations with semantic attributes
|
|
67
|
+
*
|
|
68
|
+
* Creates a traced function that automatically sets SNS messaging semantic attributes
|
|
69
|
+
* following OpenTelemetry conventions.
|
|
70
|
+
*
|
|
71
|
+
* @param config - SNS operation configuration
|
|
72
|
+
* @returns A higher-order function that wraps your SNS operation with tracing
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* Semantic attributes set automatically:
|
|
76
|
+
* - `messaging.system` - 'aws_sns'
|
|
77
|
+
* - `messaging.destination.name` - Topic ARN
|
|
78
|
+
* - `messaging.operation` - 'publish'
|
|
79
|
+
*
|
|
80
|
+
* Additional attributes you should set in your handler:
|
|
81
|
+
* - `messaging.message.id` - Message ID from response
|
|
82
|
+
* - `aws.sns.target_arn` - Target ARN for direct publishing
|
|
83
|
+
*
|
|
84
|
+
* @see https://opentelemetry.io/docs/specs/semconv/messaging/aws-sns/
|
|
85
|
+
*/
|
|
86
|
+
declare function traceSNS(config: TraceSNSConfig): <TArgs extends unknown[], TReturn>(fn: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => (...args: TArgs) => Promise<TReturn>;
|
|
87
|
+
/**
|
|
88
|
+
* Configuration for SNS Publisher
|
|
89
|
+
*/
|
|
90
|
+
interface SNSPublisherConfig {
|
|
91
|
+
/**
|
|
92
|
+
* SNS Topic ARN
|
|
93
|
+
*/
|
|
94
|
+
topicArn: string;
|
|
95
|
+
/**
|
|
96
|
+
* Inject W3C Trace Context into message attributes
|
|
97
|
+
* Enables distributed tracing to SNS subscribers (e.g., Lambda, SQS)
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
injectTraceContext?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Optional service name for tracing
|
|
103
|
+
*/
|
|
104
|
+
service?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Message to publish via SNS Publisher
|
|
108
|
+
*/
|
|
109
|
+
interface SNSPublishMessage {
|
|
110
|
+
/**
|
|
111
|
+
* Message body (string or JSON for message structure)
|
|
112
|
+
*/
|
|
113
|
+
message: string;
|
|
114
|
+
/**
|
|
115
|
+
* Optional subject (for email/SMS subscriptions)
|
|
116
|
+
*/
|
|
117
|
+
subject?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Optional message attributes
|
|
120
|
+
*/
|
|
121
|
+
attributes?: Record<string, {
|
|
122
|
+
StringValue: string;
|
|
123
|
+
DataType: string;
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Optional target ARN for direct endpoint publishing
|
|
127
|
+
*/
|
|
128
|
+
targetArn?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Optional phone number for SMS
|
|
131
|
+
*/
|
|
132
|
+
phoneNumber?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Optional message structure ('json' for platform-specific messages)
|
|
135
|
+
*/
|
|
136
|
+
messageStructure?: 'json';
|
|
137
|
+
/**
|
|
138
|
+
* Optional message group ID (for FIFO topics)
|
|
139
|
+
*/
|
|
140
|
+
messageGroupId?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Optional deduplication ID (for FIFO topics)
|
|
143
|
+
*/
|
|
144
|
+
messageDeduplicationId?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* SNS Publisher with automatic trace context injection
|
|
148
|
+
*
|
|
149
|
+
* Wraps an SNS client to automatically:
|
|
150
|
+
* - Create spans for publish operations
|
|
151
|
+
* - Inject W3C Trace Context into message attributes
|
|
152
|
+
* - Set proper semantic attributes
|
|
153
|
+
*
|
|
154
|
+
* @example Basic usage
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import { SNSPublisher } from 'autotel-aws/sns';
|
|
157
|
+
* import { SNSClient } from '@aws-sdk/client-sns';
|
|
158
|
+
*
|
|
159
|
+
* const sns = new SNSClient({ region: 'us-east-1' });
|
|
160
|
+
* const publisher = new SNSPublisher(sns, {
|
|
161
|
+
* topicArn: 'arn:aws:sns:us-east-1:123456789:my-topic'
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* // Publish with automatic trace context
|
|
165
|
+
* const result = await publisher.publish({
|
|
166
|
+
* message: 'Order completed',
|
|
167
|
+
* subject: 'Order #12345'
|
|
168
|
+
* });
|
|
169
|
+
* console.log('Message ID:', result.messageId);
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example With custom attributes
|
|
173
|
+
* ```typescript
|
|
174
|
+
* await publisher.publish({
|
|
175
|
+
* message: JSON.stringify({ orderId: '12345', status: 'completed' }),
|
|
176
|
+
* attributes: {
|
|
177
|
+
* 'eventType': { StringValue: 'ORDER_COMPLETED', DataType: 'String' },
|
|
178
|
+
* 'priority': { StringValue: 'high', DataType: 'String' }
|
|
179
|
+
* }
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @example Batch publish
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const results = await publisher.publishBatch([
|
|
186
|
+
* { message: 'Event 1' },
|
|
187
|
+
* { message: 'Event 2' },
|
|
188
|
+
* { message: 'Event 3' }
|
|
189
|
+
* ]);
|
|
190
|
+
* console.log(`Published ${results.successful.length} messages`);
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example Direct endpoint publish
|
|
194
|
+
* ```typescript
|
|
195
|
+
* await publisher.publishToEndpoint({
|
|
196
|
+
* targetArn: 'arn:aws:sns:us-east-1:123456789:endpoint/APNS/my-app/device-token',
|
|
197
|
+
* message: JSON.stringify({
|
|
198
|
+
* APNS: JSON.stringify({ aps: { alert: 'Hello!' } })
|
|
199
|
+
* }),
|
|
200
|
+
* messageStructure: 'json'
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare class SNSPublisher<TClient extends {
|
|
205
|
+
send: (command: any) => Promise<any>;
|
|
206
|
+
} = any> {
|
|
207
|
+
private client;
|
|
208
|
+
private config;
|
|
209
|
+
private topicName;
|
|
210
|
+
constructor(client: TClient, config: SNSPublisherConfig);
|
|
211
|
+
/**
|
|
212
|
+
* Inject trace context into message attributes
|
|
213
|
+
*/
|
|
214
|
+
private injectContext;
|
|
215
|
+
/**
|
|
216
|
+
* Publish a message to the topic
|
|
217
|
+
*
|
|
218
|
+
* @param message - Message to publish
|
|
219
|
+
* @returns Promise with message ID and sequence number
|
|
220
|
+
*/
|
|
221
|
+
publish(message: SNSPublishMessage): Promise<{
|
|
222
|
+
messageId?: string;
|
|
223
|
+
sequenceNumber?: string;
|
|
224
|
+
}>;
|
|
225
|
+
/**
|
|
226
|
+
* Publish multiple messages in a batch
|
|
227
|
+
*
|
|
228
|
+
* @param messages - Array of messages to publish (max 10)
|
|
229
|
+
* @returns Promise with successful and failed message results
|
|
230
|
+
*/
|
|
231
|
+
publishBatch(messages: SNSPublishMessage[]): Promise<{
|
|
232
|
+
successful: Array<{
|
|
233
|
+
id: string;
|
|
234
|
+
messageId?: string;
|
|
235
|
+
sequenceNumber?: string;
|
|
236
|
+
}>;
|
|
237
|
+
failed: Array<{
|
|
238
|
+
id: string;
|
|
239
|
+
code?: string;
|
|
240
|
+
message?: string;
|
|
241
|
+
}>;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Publish to a specific endpoint (mobile push, etc.)
|
|
245
|
+
*
|
|
246
|
+
* @param message - Message with targetArn set
|
|
247
|
+
* @returns Promise with message ID
|
|
248
|
+
*/
|
|
249
|
+
publishToEndpoint(message: Omit<SNSPublishMessage, 'targetArn'> & {
|
|
250
|
+
targetArn: string;
|
|
251
|
+
}): Promise<{
|
|
252
|
+
messageId?: string;
|
|
253
|
+
}>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export { type SNSPublishMessage, SNSPublisher, type SNSPublisherConfig, type TraceSNSConfig, traceSNS };
|
package/dist/sns.js
ADDED
package/dist/sns.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sns.js"}
|
package/dist/sqs.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOB4XTAVK_cjs = require('./chunk-OB4XTAVK.cjs');
|
|
4
|
+
require('./chunk-UZEJV2YD.cjs');
|
|
5
|
+
require('./chunk-Q3DMMQ7K.cjs');
|
|
6
|
+
require('./chunk-JEQ2X3Z6.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, "SQSConsumer", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return chunkOB4XTAVK_cjs.SQSConsumer; }
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "SQSProducer", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return chunkOB4XTAVK_cjs.SQSProducer; }
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "traceSQS", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return chunkOB4XTAVK_cjs.traceSQS; }
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=sqs.cjs.map
|
|
23
|
+
//# sourceMappingURL=sqs.cjs.map
|
package/dist/sqs.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sqs.cjs"}
|
package/dist/sqs.d.cts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { TraceContext } from 'autotel';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SQS-specific instrumentation
|
|
5
|
+
*
|
|
6
|
+
* Provides semantic helpers for tracing SQS operations with proper OpenTelemetry
|
|
7
|
+
* messaging semantic conventions. Automatically sets `messaging.*` and `aws.sqs.*` attributes.
|
|
8
|
+
*
|
|
9
|
+
* @example Send message
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { traceSQS } from 'autotel-aws/sqs';
|
|
12
|
+
* import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';
|
|
13
|
+
*
|
|
14
|
+
* const sqs = new SQSClient({});
|
|
15
|
+
*
|
|
16
|
+
* export const sendMessage = traceSQS({
|
|
17
|
+
* operation: 'send',
|
|
18
|
+
* queueName: 'my-queue',
|
|
19
|
+
* queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue'
|
|
20
|
+
* })(ctx => async (body: string, attributes?: Record<string, string>) => {
|
|
21
|
+
* const result = await sqs.send(new SendMessageCommand({
|
|
22
|
+
* QueueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue',
|
|
23
|
+
* MessageBody: body,
|
|
24
|
+
* MessageAttributes: attributes
|
|
25
|
+
* }));
|
|
26
|
+
*
|
|
27
|
+
* if (result.MessageId) {
|
|
28
|
+
* ctx.setAttribute('messaging.message.id', result.MessageId);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* return result;
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Usage: await sendMessage('Hello!', { correlationId: { StringValue: '123', DataType: 'String' } });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Receive and process messages
|
|
38
|
+
* ```typescript
|
|
39
|
+
* export const receiveMessages = traceSQS({
|
|
40
|
+
* operation: 'receive',
|
|
41
|
+
* queueName: 'my-queue'
|
|
42
|
+
* })(ctx => async (maxMessages: number) => {
|
|
43
|
+
* const result = await sqs.send(new ReceiveMessageCommand({
|
|
44
|
+
* QueueUrl: 'https://sqs.../my-queue',
|
|
45
|
+
* MaxNumberOfMessages: maxMessages
|
|
46
|
+
* }));
|
|
47
|
+
*
|
|
48
|
+
* ctx.setAttribute('messaging.batch.message_count', result.Messages?.length ?? 0);
|
|
49
|
+
* return result.Messages;
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* SQS operation configuration
|
|
56
|
+
*/
|
|
57
|
+
interface TraceSQSConfig {
|
|
58
|
+
/**
|
|
59
|
+
* SQS operation type
|
|
60
|
+
* - 'send' - SendMessage, SendMessageBatch
|
|
61
|
+
* - 'receive' - ReceiveMessage
|
|
62
|
+
*/
|
|
63
|
+
operation: 'send' | 'receive';
|
|
64
|
+
/**
|
|
65
|
+
* Queue name (last segment of queue URL)
|
|
66
|
+
* Sets `messaging.destination.name` attribute.
|
|
67
|
+
*/
|
|
68
|
+
queueName: string;
|
|
69
|
+
/**
|
|
70
|
+
* Full queue URL
|
|
71
|
+
* Sets `aws.sqs.queue_url` attribute.
|
|
72
|
+
*/
|
|
73
|
+
queueUrl?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Trace SQS operations with semantic attributes
|
|
77
|
+
*
|
|
78
|
+
* Creates a traced function that automatically sets SQS messaging semantic attributes
|
|
79
|
+
* following OpenTelemetry conventions.
|
|
80
|
+
*
|
|
81
|
+
* @param config - SQS operation configuration
|
|
82
|
+
* @returns A higher-order function that wraps your SQS operation with tracing
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* Semantic attributes set automatically:
|
|
86
|
+
* - `messaging.system` - 'aws_sqs'
|
|
87
|
+
* - `messaging.destination.name` - Queue name
|
|
88
|
+
* - `messaging.operation` - 'send' or 'receive'
|
|
89
|
+
* - `aws.sqs.queue_url` - Full queue URL (if provided)
|
|
90
|
+
*
|
|
91
|
+
* Additional attributes you should set in your handler:
|
|
92
|
+
* - `messaging.message.id` - Message ID from response
|
|
93
|
+
* - `messaging.batch.message_count` - Number of messages in batch
|
|
94
|
+
*
|
|
95
|
+
* @see https://opentelemetry.io/docs/specs/semconv/messaging/aws-sqs/
|
|
96
|
+
*/
|
|
97
|
+
declare function traceSQS(config: TraceSQSConfig): <TArgs extends unknown[], TReturn>(fn: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => (...args: TArgs) => Promise<TReturn>;
|
|
98
|
+
/**
|
|
99
|
+
* Configuration for SQS Producer
|
|
100
|
+
*/
|
|
101
|
+
interface SQSProducerConfig {
|
|
102
|
+
/**
|
|
103
|
+
* Full SQS queue URL
|
|
104
|
+
*/
|
|
105
|
+
queueUrl: string;
|
|
106
|
+
/**
|
|
107
|
+
* Inject W3C Trace Context into message attributes
|
|
108
|
+
* Enables distributed tracing across producer/consumer
|
|
109
|
+
* @default true
|
|
110
|
+
*/
|
|
111
|
+
injectTraceContext?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Optional service name for tracing
|
|
114
|
+
*/
|
|
115
|
+
service?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Message to send via SQS Producer
|
|
119
|
+
*/
|
|
120
|
+
interface SQSMessage {
|
|
121
|
+
/**
|
|
122
|
+
* Message body (string)
|
|
123
|
+
*/
|
|
124
|
+
body: string;
|
|
125
|
+
/**
|
|
126
|
+
* Optional message attributes
|
|
127
|
+
*/
|
|
128
|
+
attributes?: Record<string, {
|
|
129
|
+
StringValue: string;
|
|
130
|
+
DataType: string;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Optional message group ID (for FIFO queues)
|
|
134
|
+
*/
|
|
135
|
+
messageGroupId?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Optional deduplication ID (for FIFO queues)
|
|
138
|
+
*/
|
|
139
|
+
messageDeduplicationId?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Optional delay in seconds (0-900)
|
|
142
|
+
*/
|
|
143
|
+
delaySeconds?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* SQS Producer with automatic trace context injection
|
|
147
|
+
*
|
|
148
|
+
* Wraps an SQS client to automatically:
|
|
149
|
+
* - Create spans for send operations
|
|
150
|
+
* - Inject W3C Trace Context into message attributes
|
|
151
|
+
* - Set proper semantic attributes
|
|
152
|
+
*
|
|
153
|
+
* @example Basic usage
|
|
154
|
+
* ```typescript
|
|
155
|
+
* import { SQSProducer } from 'autotel-aws/sqs';
|
|
156
|
+
* import { SQSClient } from '@aws-sdk/client-sqs';
|
|
157
|
+
*
|
|
158
|
+
* const sqs = new SQSClient({ region: 'us-east-1' });
|
|
159
|
+
* const producer = new SQSProducer(sqs, {
|
|
160
|
+
* queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue'
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Send with automatic trace context
|
|
164
|
+
* const result = await producer.send({ body: 'Hello!' });
|
|
165
|
+
* console.log('Message ID:', result.messageId);
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example With custom attributes
|
|
169
|
+
* ```typescript
|
|
170
|
+
* await producer.send({
|
|
171
|
+
* body: JSON.stringify({ orderId: '12345' }),
|
|
172
|
+
* attributes: {
|
|
173
|
+
* 'correlationId': { StringValue: 'abc-123', DataType: 'String' },
|
|
174
|
+
* 'eventType': { StringValue: 'ORDER_CREATED', DataType: 'String' }
|
|
175
|
+
* }
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example Batch send
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const results = await producer.sendBatch([
|
|
182
|
+
* { body: 'Message 1' },
|
|
183
|
+
* { body: 'Message 2' },
|
|
184
|
+
* { body: 'Message 3' }
|
|
185
|
+
* ]);
|
|
186
|
+
* console.log(`Sent ${results.successful.length} messages`);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare class SQSProducer<TClient extends {
|
|
190
|
+
send: (command: any) => Promise<any>;
|
|
191
|
+
} = any> {
|
|
192
|
+
private client;
|
|
193
|
+
private config;
|
|
194
|
+
private queueName;
|
|
195
|
+
constructor(client: TClient, config: SQSProducerConfig);
|
|
196
|
+
/**
|
|
197
|
+
* Inject trace context into message attributes
|
|
198
|
+
*/
|
|
199
|
+
private injectContext;
|
|
200
|
+
/**
|
|
201
|
+
* Send a single message to the queue
|
|
202
|
+
*
|
|
203
|
+
* @param message - Message to send
|
|
204
|
+
* @returns Promise with message ID and other metadata
|
|
205
|
+
*/
|
|
206
|
+
send(message: SQSMessage): Promise<{
|
|
207
|
+
messageId?: string;
|
|
208
|
+
sequenceNumber?: string;
|
|
209
|
+
md5OfMessageBody?: string;
|
|
210
|
+
}>;
|
|
211
|
+
/**
|
|
212
|
+
* Send multiple messages in a batch
|
|
213
|
+
*
|
|
214
|
+
* @param messages - Array of messages to send (max 10)
|
|
215
|
+
* @returns Promise with successful and failed message results
|
|
216
|
+
*/
|
|
217
|
+
sendBatch(messages: SQSMessage[]): Promise<{
|
|
218
|
+
successful: Array<{
|
|
219
|
+
id: string;
|
|
220
|
+
messageId?: string;
|
|
221
|
+
sequenceNumber?: string;
|
|
222
|
+
}>;
|
|
223
|
+
failed: Array<{
|
|
224
|
+
id: string;
|
|
225
|
+
code?: string;
|
|
226
|
+
message?: string;
|
|
227
|
+
}>;
|
|
228
|
+
}>;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Configuration for SQS Consumer
|
|
232
|
+
*/
|
|
233
|
+
interface SQSConsumerConfig {
|
|
234
|
+
/**
|
|
235
|
+
* Full SQS queue URL
|
|
236
|
+
*/
|
|
237
|
+
queueUrl: string;
|
|
238
|
+
/**
|
|
239
|
+
* Extract W3C Trace Context from message attributes
|
|
240
|
+
* Creates child spans linked to the producer
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
extractTraceContext?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Maximum number of messages to receive per poll
|
|
246
|
+
* @default 10
|
|
247
|
+
*/
|
|
248
|
+
maxMessages?: number;
|
|
249
|
+
/**
|
|
250
|
+
* Visibility timeout in seconds
|
|
251
|
+
* @default 30
|
|
252
|
+
*/
|
|
253
|
+
visibilityTimeout?: number;
|
|
254
|
+
/**
|
|
255
|
+
* Wait time for long polling in seconds (0-20)
|
|
256
|
+
* @default 20
|
|
257
|
+
*/
|
|
258
|
+
waitTimeSeconds?: number;
|
|
259
|
+
/**
|
|
260
|
+
* Optional service name for tracing
|
|
261
|
+
*/
|
|
262
|
+
service?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Received SQS message with parsed attributes
|
|
266
|
+
*/
|
|
267
|
+
interface ReceivedSQSMessage {
|
|
268
|
+
/**
|
|
269
|
+
* Message ID
|
|
270
|
+
*/
|
|
271
|
+
messageId: string;
|
|
272
|
+
/**
|
|
273
|
+
* Receipt handle for deletion
|
|
274
|
+
*/
|
|
275
|
+
receiptHandle: string;
|
|
276
|
+
/**
|
|
277
|
+
* Message body (string)
|
|
278
|
+
*/
|
|
279
|
+
body: string;
|
|
280
|
+
/**
|
|
281
|
+
* Parsed message attributes
|
|
282
|
+
*/
|
|
283
|
+
attributes: Record<string, string>;
|
|
284
|
+
/**
|
|
285
|
+
* System attributes (ApproximateReceiveCount, etc.)
|
|
286
|
+
*/
|
|
287
|
+
systemAttributes: Record<string, string>;
|
|
288
|
+
/**
|
|
289
|
+
* Original AWS SDK message object
|
|
290
|
+
*/
|
|
291
|
+
raw: any;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Message processor function type
|
|
295
|
+
*/
|
|
296
|
+
type MessageProcessor = (message: ReceivedSQSMessage, ctx: TraceContext) => Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* SQS Consumer with automatic trace context extraction
|
|
299
|
+
*
|
|
300
|
+
* Wraps an SQS client to automatically:
|
|
301
|
+
* - Create spans for receive/process operations
|
|
302
|
+
* - Extract W3C Trace Context from message attributes
|
|
303
|
+
* - Link consumer spans to producer spans
|
|
304
|
+
* - Delete messages after successful processing
|
|
305
|
+
*
|
|
306
|
+
* @example Basic usage
|
|
307
|
+
* ```typescript
|
|
308
|
+
* import { SQSConsumer } from 'autotel-aws/sqs';
|
|
309
|
+
* import { SQSClient } from '@aws-sdk/client-sqs';
|
|
310
|
+
*
|
|
311
|
+
* const sqs = new SQSClient({ region: 'us-east-1' });
|
|
312
|
+
* const consumer = new SQSConsumer(sqs, {
|
|
313
|
+
* queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789/my-queue'
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* // Process messages with automatic tracing
|
|
317
|
+
* await consumer.processMessages(async (message, ctx) => {
|
|
318
|
+
* ctx.setAttribute('order.id', JSON.parse(message.body).orderId);
|
|
319
|
+
* await handleOrder(message.body);
|
|
320
|
+
* });
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example With polling loop
|
|
324
|
+
* ```typescript
|
|
325
|
+
* // Start continuous polling
|
|
326
|
+
* const controller = new AbortController();
|
|
327
|
+
*
|
|
328
|
+
* consumer.poll(async (message, ctx) => {
|
|
329
|
+
* await processMessage(message);
|
|
330
|
+
* }, { signal: controller.signal });
|
|
331
|
+
*
|
|
332
|
+
* // Stop polling gracefully
|
|
333
|
+
* controller.abort();
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
declare class SQSConsumer<TClient extends {
|
|
337
|
+
send: (command: any) => Promise<any>;
|
|
338
|
+
} = any> {
|
|
339
|
+
private client;
|
|
340
|
+
private config;
|
|
341
|
+
private queueName;
|
|
342
|
+
constructor(client: TClient, config: SQSConsumerConfig);
|
|
343
|
+
/**
|
|
344
|
+
* Extract trace context from message attributes
|
|
345
|
+
*/
|
|
346
|
+
private extractContext;
|
|
347
|
+
/**
|
|
348
|
+
* Parse AWS SDK message into our format
|
|
349
|
+
*/
|
|
350
|
+
private parseMessage;
|
|
351
|
+
/**
|
|
352
|
+
* Receive messages from the queue
|
|
353
|
+
*
|
|
354
|
+
* @returns Array of received messages
|
|
355
|
+
*/
|
|
356
|
+
receive(): Promise<ReceivedSQSMessage[]>;
|
|
357
|
+
/**
|
|
358
|
+
* Delete a message from the queue
|
|
359
|
+
*
|
|
360
|
+
* @param receiptHandle - Receipt handle of the message to delete
|
|
361
|
+
*/
|
|
362
|
+
delete(receiptHandle: string): Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* Process messages with automatic trace context extraction
|
|
365
|
+
*
|
|
366
|
+
* Receives messages, processes each with the provided handler,
|
|
367
|
+
* and deletes successfully processed messages.
|
|
368
|
+
*
|
|
369
|
+
* @param processor - Function to process each message
|
|
370
|
+
* @returns Number of messages processed
|
|
371
|
+
*/
|
|
372
|
+
processMessages(processor: MessageProcessor): Promise<number>;
|
|
373
|
+
/**
|
|
374
|
+
* Start continuous polling loop
|
|
375
|
+
*
|
|
376
|
+
* @param processor - Function to process each message
|
|
377
|
+
* @param options - Polling options including abort signal
|
|
378
|
+
*/
|
|
379
|
+
poll(processor: MessageProcessor, options?: {
|
|
380
|
+
signal?: AbortSignal;
|
|
381
|
+
}): Promise<void>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export { type MessageProcessor, type ReceivedSQSMessage, SQSConsumer, type SQSConsumerConfig, type SQSMessage, SQSProducer, type SQSProducerConfig, type TraceSQSConfig, traceSQS };
|