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.
Files changed (141) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +540 -0
  3. package/dist/attributes.cjs +49 -0
  4. package/dist/attributes.cjs.map +1 -0
  5. package/dist/attributes.d.cts +117 -0
  6. package/dist/attributes.d.ts +117 -0
  7. package/dist/attributes.js +4 -0
  8. package/dist/attributes.js.map +1 -0
  9. package/dist/chunk-35F3UBOO.cjs +48 -0
  10. package/dist/chunk-35F3UBOO.cjs.map +1 -0
  11. package/dist/chunk-4TGVGEUN.cjs +84 -0
  12. package/dist/chunk-4TGVGEUN.cjs.map +1 -0
  13. package/dist/chunk-CIGXV6HA.js +192 -0
  14. package/dist/chunk-CIGXV6HA.js.map +1 -0
  15. package/dist/chunk-D5INYMRP.cjs +350 -0
  16. package/dist/chunk-D5INYMRP.cjs.map +1 -0
  17. package/dist/chunk-DF5PT3JK.js +387 -0
  18. package/dist/chunk-DF5PT3JK.js.map +1 -0
  19. package/dist/chunk-DGUM43GV.js +10 -0
  20. package/dist/chunk-DGUM43GV.js.map +1 -0
  21. package/dist/chunk-DHHLKZHI.cjs +23 -0
  22. package/dist/chunk-DHHLKZHI.cjs.map +1 -0
  23. package/dist/chunk-FKZOELBT.js +78 -0
  24. package/dist/chunk-FKZOELBT.js.map +1 -0
  25. package/dist/chunk-HMTKKKKP.cjs +390 -0
  26. package/dist/chunk-HMTKKKKP.cjs.map +1 -0
  27. package/dist/chunk-I4CKQ4RD.js +153 -0
  28. package/dist/chunk-I4CKQ4RD.js.map +1 -0
  29. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  30. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  31. package/dist/chunk-JMSFE6FJ.js +24 -0
  32. package/dist/chunk-JMSFE6FJ.js.map +1 -0
  33. package/dist/chunk-KUIOI74B.cjs +394 -0
  34. package/dist/chunk-KUIOI74B.cjs.map +1 -0
  35. package/dist/chunk-NQ65Y5AI.cjs +195 -0
  36. package/dist/chunk-NQ65Y5AI.cjs.map +1 -0
  37. package/dist/chunk-OB4XTAVK.cjs +345 -0
  38. package/dist/chunk-OB4XTAVK.cjs.map +1 -0
  39. package/dist/chunk-OHFR7WX5.js +341 -0
  40. package/dist/chunk-OHFR7WX5.js.map +1 -0
  41. package/dist/chunk-PZGYL7XZ.js +40 -0
  42. package/dist/chunk-PZGYL7XZ.js.map +1 -0
  43. package/dist/chunk-Q3DMMQ7K.cjs +164 -0
  44. package/dist/chunk-Q3DMMQ7K.cjs.map +1 -0
  45. package/dist/chunk-UZEJV2YD.cjs +139 -0
  46. package/dist/chunk-UZEJV2YD.cjs.map +1 -0
  47. package/dist/chunk-V4IQWFYN.js +341 -0
  48. package/dist/chunk-V4IQWFYN.js.map +1 -0
  49. package/dist/chunk-VZHQH75L.cjs +26 -0
  50. package/dist/chunk-VZHQH75L.cjs.map +1 -0
  51. package/dist/chunk-X6BY6PCK.js +386 -0
  52. package/dist/chunk-X6BY6PCK.js.map +1 -0
  53. package/dist/chunk-YG56NRIO.js +131 -0
  54. package/dist/chunk-YG56NRIO.js.map +1 -0
  55. package/dist/chunk-ZPDRKCAR.js +21 -0
  56. package/dist/chunk-ZPDRKCAR.js.map +1 -0
  57. package/dist/config-C7zV8Zm6.d.cts +125 -0
  58. package/dist/config-DxjTT8jd.d.ts +125 -0
  59. package/dist/dynamodb.cjs +14 -0
  60. package/dist/dynamodb.cjs.map +1 -0
  61. package/dist/dynamodb.d.cts +93 -0
  62. package/dist/dynamodb.d.ts +93 -0
  63. package/dist/dynamodb.js +5 -0
  64. package/dist/dynamodb.js.map +1 -0
  65. package/dist/eventbridge.cjs +279 -0
  66. package/dist/eventbridge.cjs.map +1 -0
  67. package/dist/eventbridge.d.cts +360 -0
  68. package/dist/eventbridge.d.ts +360 -0
  69. package/dist/eventbridge.js +273 -0
  70. package/dist/eventbridge.js.map +1 -0
  71. package/dist/index.cjs +251 -0
  72. package/dist/index.cjs.map +1 -0
  73. package/dist/index.d.cts +126 -0
  74. package/dist/index.d.ts +126 -0
  75. package/dist/index.js +48 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/kinesis.cjs +23 -0
  78. package/dist/kinesis.cjs.map +1 -0
  79. package/dist/kinesis.d.cts +360 -0
  80. package/dist/kinesis.d.ts +360 -0
  81. package/dist/kinesis.js +6 -0
  82. package/dist/kinesis.js.map +1 -0
  83. package/dist/lambda-auto.cjs +19 -0
  84. package/dist/lambda-auto.cjs.map +1 -0
  85. package/dist/lambda-auto.d.cts +2 -0
  86. package/dist/lambda-auto.d.ts +2 -0
  87. package/dist/lambda-auto.js +17 -0
  88. package/dist/lambda-auto.js.map +1 -0
  89. package/dist/lambda.cjs +42 -0
  90. package/dist/lambda.cjs.map +1 -0
  91. package/dist/lambda.d.cts +231 -0
  92. package/dist/lambda.d.ts +231 -0
  93. package/dist/lambda.js +5 -0
  94. package/dist/lambda.js.map +1 -0
  95. package/dist/s3.cjs +14 -0
  96. package/dist/s3.cjs.map +1 -0
  97. package/dist/s3.d.cts +77 -0
  98. package/dist/s3.d.ts +77 -0
  99. package/dist/s3.js +5 -0
  100. package/dist/s3.js.map +1 -0
  101. package/dist/sdk.cjs +31 -0
  102. package/dist/sdk.cjs.map +1 -0
  103. package/dist/sdk.d.cts +155 -0
  104. package/dist/sdk.d.ts +155 -0
  105. package/dist/sdk.js +6 -0
  106. package/dist/sdk.js.map +1 -0
  107. package/dist/sns.cjs +19 -0
  108. package/dist/sns.cjs.map +1 -0
  109. package/dist/sns.d.cts +256 -0
  110. package/dist/sns.d.ts +256 -0
  111. package/dist/sns.js +6 -0
  112. package/dist/sns.js.map +1 -0
  113. package/dist/sqs.cjs +23 -0
  114. package/dist/sqs.cjs.map +1 -0
  115. package/dist/sqs.d.cts +384 -0
  116. package/dist/sqs.d.ts +384 -0
  117. package/dist/sqs.js +6 -0
  118. package/dist/sqs.js.map +1 -0
  119. package/dist/step-functions.cjs +35 -0
  120. package/dist/step-functions.cjs.map +1 -0
  121. package/dist/step-functions.d.cts +423 -0
  122. package/dist/step-functions.d.ts +423 -0
  123. package/dist/step-functions.js +6 -0
  124. package/dist/step-functions.js.map +1 -0
  125. package/dist/testing.cjs +61 -0
  126. package/dist/testing.cjs.map +1 -0
  127. package/dist/testing.d.cts +39 -0
  128. package/dist/testing.d.ts +39 -0
  129. package/dist/testing.js +58 -0
  130. package/dist/testing.js.map +1 -0
  131. package/dist/types-3_ak5jhy.d.cts +76 -0
  132. package/dist/types-3_ak5jhy.d.ts +76 -0
  133. package/dist/types-UiBv_I_M.d.ts +16 -0
  134. package/dist/types-kTFVdSqO.d.cts +16 -0
  135. package/dist/xray.cjs +26 -0
  136. package/dist/xray.cjs.map +1 -0
  137. package/dist/xray.d.cts +23 -0
  138. package/dist/xray.d.ts +23 -0
  139. package/dist/xray.js +5 -0
  140. package/dist/xray.js.map +1 -0
  141. package/package.json +184 -0
@@ -0,0 +1,231 @@
1
+ import { TraceContext } from 'autotel';
2
+ import { L as LambdaHandler } from './types-kTFVdSqO.cjs';
3
+ export { a as LambdaTrigger } from './types-kTFVdSqO.cjs';
4
+ import { L as LambdaEvent } from './types-3_ak5jhy.cjs';
5
+ import { L as LambdaInstrumentationConfig } from './config-C7zV8Zm6.cjs';
6
+ import { MiddlewareObj, Request } from '@middy/core';
7
+ import { Context } from 'aws-lambda';
8
+ import { Span, Context as Context$1, SpanContext } from '@opentelemetry/api';
9
+
10
+ /**
11
+ * Lambda handler wrappers
12
+ *
13
+ * Provides instrumentation wrappers for AWS Lambda handlers with automatic
14
+ * trace context extraction from various event sources (API Gateway, SQS, SNS, etc.).
15
+ *
16
+ * @example Simple wrapper
17
+ * ```typescript
18
+ * import { wrapHandler } from 'autotel-aws/lambda';
19
+ *
20
+ * export const handler = wrapHandler(async (event, context) => {
21
+ * return { statusCode: 200 };
22
+ * });
23
+ * ```
24
+ *
25
+ * @example With context access
26
+ * ```typescript
27
+ * import { traceLambda } from 'autotel-aws/lambda';
28
+ *
29
+ * export const handler = traceLambda(ctx => async (event, context) => {
30
+ * ctx.setAttribute('user.id', event.userId);
31
+ * return { statusCode: 200 };
32
+ * });
33
+ * ```
34
+ */
35
+
36
+ /**
37
+ * Wrap Lambda handler with OpenTelemetry instrumentation
38
+ *
39
+ * Automatically extracts trace context from incoming events and creates
40
+ * a root span for the Lambda invocation with proper semantic attributes.
41
+ *
42
+ * @param handler - The Lambda handler function to wrap
43
+ * @param config - Optional instrumentation configuration
44
+ * @returns Wrapped handler with automatic tracing
45
+ *
46
+ * @example Basic usage
47
+ * ```typescript
48
+ * export const handler = wrapHandler(async (event, context) => {
49
+ * // Your handler code - automatically traced
50
+ * return { statusCode: 200 };
51
+ * });
52
+ * ```
53
+ *
54
+ * @example With configuration
55
+ * ```typescript
56
+ * export const handler = wrapHandler(
57
+ * async (event, context) => {
58
+ * return { statusCode: 200, body: JSON.stringify({ result: 'ok' }) };
59
+ * },
60
+ * { captureResponse: true, extractTraceContext: true }
61
+ * );
62
+ * ```
63
+ *
64
+ * @remarks
65
+ * Semantic attributes set automatically:
66
+ * - `faas.name` - Function name
67
+ * - `faas.version` - Function version
68
+ * - `faas.invocation_id` - AWS request ID
69
+ * - `faas.coldstart` - Whether this is a cold start
70
+ * - `faas.trigger` - Trigger type (http, pubsub, datasource, timer, other)
71
+ * - `cloud.provider` - 'aws'
72
+ * - `cloud.region` - AWS region
73
+ * - `cloud.account.id` - AWS account ID (extracted from ARN)
74
+ */
75
+ declare function wrapHandler<TEvent = LambdaEvent, TResult = unknown>(handler: LambdaHandler<TEvent, TResult>, config?: LambdaInstrumentationConfig): LambdaHandler<TEvent, TResult>;
76
+ /**
77
+ * Functional API for Lambda with trace context access
78
+ *
79
+ * Similar to `wrapHandler`, but provides access to the trace context
80
+ * for setting custom attributes during handler execution.
81
+ *
82
+ * @param factory - Factory function that receives trace context and returns a handler
83
+ * @param config - Optional instrumentation configuration
84
+ * @returns Wrapped handler with automatic tracing
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * export const handler = traceLambda(ctx => async (event, context) => {
89
+ * // Access trace context for custom attributes
90
+ * ctx.setAttribute('user.id', event.userId);
91
+ * ctx.setAttribute('order.id', event.orderId);
92
+ *
93
+ * // Use X-Ray annotations for indexed attributes
94
+ * setXRayAnnotation('user.tier', event.userTier);
95
+ *
96
+ * const result = await processOrder(event);
97
+ * ctx.setAttribute('order.status', result.status);
98
+ *
99
+ * return { statusCode: 200, body: JSON.stringify(result) };
100
+ * });
101
+ * ```
102
+ *
103
+ * @remarks
104
+ * The trace context (`ctx`) provides:
105
+ * - `setAttribute(key, value)` - Set a single attribute
106
+ * - `setAttributes(attrs)` - Set multiple attributes
107
+ * - `setStatus(status)` - Set span status
108
+ * - `recordException(error)` - Record an exception
109
+ * - `traceId`, `spanId` - Trace identifiers
110
+ */
111
+ declare function traceLambda<TEvent = LambdaEvent, TResult = unknown>(factory: (ctx: TraceContext) => LambdaHandler<TEvent, TResult>, config?: LambdaInstrumentationConfig): LambdaHandler<TEvent, TResult>;
112
+
113
+ /**
114
+ * Middy-compatible Lambda middleware for OpenTelemetry instrumentation
115
+ *
116
+ * Provides full span lifecycle management for Lambda handlers using Middy.
117
+ *
118
+ * @example Basic usage
119
+ * ```typescript
120
+ * import middy from '@middy/core';
121
+ * import { tracingMiddleware } from 'autotel-aws/lambda';
122
+ *
123
+ * const baseHandler = async (event, context) => {
124
+ * return { statusCode: 200 };
125
+ * };
126
+ *
127
+ * export const handler = middy(baseHandler)
128
+ * .use(tracingMiddleware());
129
+ * ```
130
+ *
131
+ * @example With configuration
132
+ * ```typescript
133
+ * export const handler = middy(baseHandler)
134
+ * .use(tracingMiddleware({
135
+ * captureResponse: true,
136
+ * extractTraceContext: true
137
+ * }));
138
+ * ```
139
+ *
140
+ * @example Combined with other middleware
141
+ * ```typescript
142
+ * export const handler = middy(baseHandler)
143
+ * .use(tracingMiddleware())
144
+ * .use(jsonBodyParser())
145
+ * .use(httpErrorHandler());
146
+ * ```
147
+ */
148
+
149
+ /**
150
+ * Middy middleware for Lambda instrumentation with full span lifecycle
151
+ *
152
+ * Creates a span that wraps the entire handler execution, including:
153
+ * - Trace context extraction from incoming events
154
+ * - Cold start detection
155
+ * - Semantic attributes for Lambda (faas.*, cloud.*)
156
+ * - Error recording and status
157
+ * - Response capture (optional)
158
+ *
159
+ * @param config - Optional instrumentation configuration
160
+ * @returns Middy middleware object
161
+ *
162
+ * @remarks
163
+ * This middleware uses Middy's before/after/onError hooks to manage
164
+ * the span lifecycle. The span is created in `before`, ended in `after`
165
+ * or `onError`.
166
+ *
167
+ * Semantic attributes set automatically:
168
+ * - `faas.name` - Function name
169
+ * - `faas.version` - Function version
170
+ * - `faas.invocation_id` - AWS request ID
171
+ * - `faas.coldstart` - Whether this is a cold start
172
+ * - `faas.trigger` - Trigger type (http, pubsub, datasource, timer, other)
173
+ * - `cloud.provider` - 'aws'
174
+ * - `cloud.region` - AWS region
175
+ * - `cloud.account.id` - AWS account ID (extracted from ARN)
176
+ */
177
+ declare function tracingMiddleware(config?: LambdaInstrumentationConfig): MiddlewareObj<LambdaEvent, unknown, Error, Context>;
178
+ /**
179
+ * @deprecated Use tracingMiddleware instead. LambdaMiddleware is an alias for backwards compatibility.
180
+ */
181
+ declare const LambdaMiddleware: typeof tracingMiddleware;
182
+ /**
183
+ * Get the current span from a Middy request object
184
+ *
185
+ * Useful for setting custom attributes within your handler when using
186
+ * the tracing middleware.
187
+ *
188
+ * @param request - Middy request object
189
+ * @returns The active span, or undefined if not available
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const baseHandler = async (event, context) => {
194
+ * const span = getSpanFromRequest(request);
195
+ * if (span) {
196
+ * span.setAttribute('user.id', event.userId);
197
+ * }
198
+ * return { statusCode: 200 };
199
+ * };
200
+ * ```
201
+ */
202
+ declare function getSpanFromRequest(request: Request<any, any, any, any>): Span | undefined;
203
+ /**
204
+ * Get the OpenTelemetry context from a Middy request object
205
+ *
206
+ * @param request - Middy request object
207
+ * @returns The active context, or undefined if not available
208
+ */
209
+ declare function getContextFromRequest(request: Request<any, any, any, any>): Context$1 | undefined;
210
+
211
+ /**
212
+ * Extract trace context from Lambda events
213
+ */
214
+
215
+ /**
216
+ * Extract trace context from Lambda event
217
+ *
218
+ * Supports:
219
+ * - API Gateway (W3C Trace Context headers)
220
+ * - SQS (message attributes)
221
+ * - SNS (message attributes)
222
+ * - X-Ray header (Lambda integration)
223
+ * - Step Functions (payload context)
224
+ */
225
+ declare function extractTraceContext(event: LambdaEvent): SpanContext | undefined;
226
+ /**
227
+ * Detect Lambda trigger type from event
228
+ */
229
+ declare function detectTriggerType(event: LambdaEvent): 'http' | 'pubsub' | 'datasource' | 'timer' | 'other';
230
+
231
+ export { LambdaHandler, LambdaMiddleware, detectTriggerType, extractTraceContext, getContextFromRequest, getSpanFromRequest, traceLambda, tracingMiddleware, wrapHandler };
@@ -0,0 +1,231 @@
1
+ import { TraceContext } from 'autotel';
2
+ import { L as LambdaHandler } from './types-UiBv_I_M.js';
3
+ export { a as LambdaTrigger } from './types-UiBv_I_M.js';
4
+ import { L as LambdaEvent } from './types-3_ak5jhy.js';
5
+ import { L as LambdaInstrumentationConfig } from './config-DxjTT8jd.js';
6
+ import { MiddlewareObj, Request } from '@middy/core';
7
+ import { Context } from 'aws-lambda';
8
+ import { Span, Context as Context$1, SpanContext } from '@opentelemetry/api';
9
+
10
+ /**
11
+ * Lambda handler wrappers
12
+ *
13
+ * Provides instrumentation wrappers for AWS Lambda handlers with automatic
14
+ * trace context extraction from various event sources (API Gateway, SQS, SNS, etc.).
15
+ *
16
+ * @example Simple wrapper
17
+ * ```typescript
18
+ * import { wrapHandler } from 'autotel-aws/lambda';
19
+ *
20
+ * export const handler = wrapHandler(async (event, context) => {
21
+ * return { statusCode: 200 };
22
+ * });
23
+ * ```
24
+ *
25
+ * @example With context access
26
+ * ```typescript
27
+ * import { traceLambda } from 'autotel-aws/lambda';
28
+ *
29
+ * export const handler = traceLambda(ctx => async (event, context) => {
30
+ * ctx.setAttribute('user.id', event.userId);
31
+ * return { statusCode: 200 };
32
+ * });
33
+ * ```
34
+ */
35
+
36
+ /**
37
+ * Wrap Lambda handler with OpenTelemetry instrumentation
38
+ *
39
+ * Automatically extracts trace context from incoming events and creates
40
+ * a root span for the Lambda invocation with proper semantic attributes.
41
+ *
42
+ * @param handler - The Lambda handler function to wrap
43
+ * @param config - Optional instrumentation configuration
44
+ * @returns Wrapped handler with automatic tracing
45
+ *
46
+ * @example Basic usage
47
+ * ```typescript
48
+ * export const handler = wrapHandler(async (event, context) => {
49
+ * // Your handler code - automatically traced
50
+ * return { statusCode: 200 };
51
+ * });
52
+ * ```
53
+ *
54
+ * @example With configuration
55
+ * ```typescript
56
+ * export const handler = wrapHandler(
57
+ * async (event, context) => {
58
+ * return { statusCode: 200, body: JSON.stringify({ result: 'ok' }) };
59
+ * },
60
+ * { captureResponse: true, extractTraceContext: true }
61
+ * );
62
+ * ```
63
+ *
64
+ * @remarks
65
+ * Semantic attributes set automatically:
66
+ * - `faas.name` - Function name
67
+ * - `faas.version` - Function version
68
+ * - `faas.invocation_id` - AWS request ID
69
+ * - `faas.coldstart` - Whether this is a cold start
70
+ * - `faas.trigger` - Trigger type (http, pubsub, datasource, timer, other)
71
+ * - `cloud.provider` - 'aws'
72
+ * - `cloud.region` - AWS region
73
+ * - `cloud.account.id` - AWS account ID (extracted from ARN)
74
+ */
75
+ declare function wrapHandler<TEvent = LambdaEvent, TResult = unknown>(handler: LambdaHandler<TEvent, TResult>, config?: LambdaInstrumentationConfig): LambdaHandler<TEvent, TResult>;
76
+ /**
77
+ * Functional API for Lambda with trace context access
78
+ *
79
+ * Similar to `wrapHandler`, but provides access to the trace context
80
+ * for setting custom attributes during handler execution.
81
+ *
82
+ * @param factory - Factory function that receives trace context and returns a handler
83
+ * @param config - Optional instrumentation configuration
84
+ * @returns Wrapped handler with automatic tracing
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * export const handler = traceLambda(ctx => async (event, context) => {
89
+ * // Access trace context for custom attributes
90
+ * ctx.setAttribute('user.id', event.userId);
91
+ * ctx.setAttribute('order.id', event.orderId);
92
+ *
93
+ * // Use X-Ray annotations for indexed attributes
94
+ * setXRayAnnotation('user.tier', event.userTier);
95
+ *
96
+ * const result = await processOrder(event);
97
+ * ctx.setAttribute('order.status', result.status);
98
+ *
99
+ * return { statusCode: 200, body: JSON.stringify(result) };
100
+ * });
101
+ * ```
102
+ *
103
+ * @remarks
104
+ * The trace context (`ctx`) provides:
105
+ * - `setAttribute(key, value)` - Set a single attribute
106
+ * - `setAttributes(attrs)` - Set multiple attributes
107
+ * - `setStatus(status)` - Set span status
108
+ * - `recordException(error)` - Record an exception
109
+ * - `traceId`, `spanId` - Trace identifiers
110
+ */
111
+ declare function traceLambda<TEvent = LambdaEvent, TResult = unknown>(factory: (ctx: TraceContext) => LambdaHandler<TEvent, TResult>, config?: LambdaInstrumentationConfig): LambdaHandler<TEvent, TResult>;
112
+
113
+ /**
114
+ * Middy-compatible Lambda middleware for OpenTelemetry instrumentation
115
+ *
116
+ * Provides full span lifecycle management for Lambda handlers using Middy.
117
+ *
118
+ * @example Basic usage
119
+ * ```typescript
120
+ * import middy from '@middy/core';
121
+ * import { tracingMiddleware } from 'autotel-aws/lambda';
122
+ *
123
+ * const baseHandler = async (event, context) => {
124
+ * return { statusCode: 200 };
125
+ * };
126
+ *
127
+ * export const handler = middy(baseHandler)
128
+ * .use(tracingMiddleware());
129
+ * ```
130
+ *
131
+ * @example With configuration
132
+ * ```typescript
133
+ * export const handler = middy(baseHandler)
134
+ * .use(tracingMiddleware({
135
+ * captureResponse: true,
136
+ * extractTraceContext: true
137
+ * }));
138
+ * ```
139
+ *
140
+ * @example Combined with other middleware
141
+ * ```typescript
142
+ * export const handler = middy(baseHandler)
143
+ * .use(tracingMiddleware())
144
+ * .use(jsonBodyParser())
145
+ * .use(httpErrorHandler());
146
+ * ```
147
+ */
148
+
149
+ /**
150
+ * Middy middleware for Lambda instrumentation with full span lifecycle
151
+ *
152
+ * Creates a span that wraps the entire handler execution, including:
153
+ * - Trace context extraction from incoming events
154
+ * - Cold start detection
155
+ * - Semantic attributes for Lambda (faas.*, cloud.*)
156
+ * - Error recording and status
157
+ * - Response capture (optional)
158
+ *
159
+ * @param config - Optional instrumentation configuration
160
+ * @returns Middy middleware object
161
+ *
162
+ * @remarks
163
+ * This middleware uses Middy's before/after/onError hooks to manage
164
+ * the span lifecycle. The span is created in `before`, ended in `after`
165
+ * or `onError`.
166
+ *
167
+ * Semantic attributes set automatically:
168
+ * - `faas.name` - Function name
169
+ * - `faas.version` - Function version
170
+ * - `faas.invocation_id` - AWS request ID
171
+ * - `faas.coldstart` - Whether this is a cold start
172
+ * - `faas.trigger` - Trigger type (http, pubsub, datasource, timer, other)
173
+ * - `cloud.provider` - 'aws'
174
+ * - `cloud.region` - AWS region
175
+ * - `cloud.account.id` - AWS account ID (extracted from ARN)
176
+ */
177
+ declare function tracingMiddleware(config?: LambdaInstrumentationConfig): MiddlewareObj<LambdaEvent, unknown, Error, Context>;
178
+ /**
179
+ * @deprecated Use tracingMiddleware instead. LambdaMiddleware is an alias for backwards compatibility.
180
+ */
181
+ declare const LambdaMiddleware: typeof tracingMiddleware;
182
+ /**
183
+ * Get the current span from a Middy request object
184
+ *
185
+ * Useful for setting custom attributes within your handler when using
186
+ * the tracing middleware.
187
+ *
188
+ * @param request - Middy request object
189
+ * @returns The active span, or undefined if not available
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const baseHandler = async (event, context) => {
194
+ * const span = getSpanFromRequest(request);
195
+ * if (span) {
196
+ * span.setAttribute('user.id', event.userId);
197
+ * }
198
+ * return { statusCode: 200 };
199
+ * };
200
+ * ```
201
+ */
202
+ declare function getSpanFromRequest(request: Request<any, any, any, any>): Span | undefined;
203
+ /**
204
+ * Get the OpenTelemetry context from a Middy request object
205
+ *
206
+ * @param request - Middy request object
207
+ * @returns The active context, or undefined if not available
208
+ */
209
+ declare function getContextFromRequest(request: Request<any, any, any, any>): Context$1 | undefined;
210
+
211
+ /**
212
+ * Extract trace context from Lambda events
213
+ */
214
+
215
+ /**
216
+ * Extract trace context from Lambda event
217
+ *
218
+ * Supports:
219
+ * - API Gateway (W3C Trace Context headers)
220
+ * - SQS (message attributes)
221
+ * - SNS (message attributes)
222
+ * - X-Ray header (Lambda integration)
223
+ * - Step Functions (payload context)
224
+ */
225
+ declare function extractTraceContext(event: LambdaEvent): SpanContext | undefined;
226
+ /**
227
+ * Detect Lambda trigger type from event
228
+ */
229
+ declare function detectTriggerType(event: LambdaEvent): 'http' | 'pubsub' | 'datasource' | 'timer' | 'other';
230
+
231
+ export { LambdaHandler, LambdaMiddleware, detectTriggerType, extractTraceContext, getContextFromRequest, getSpanFromRequest, traceLambda, tracingMiddleware, wrapHandler };
package/dist/lambda.js ADDED
@@ -0,0 +1,5 @@
1
+ export { LambdaMiddleware, detectTriggerType, extractTraceContext, getContextFromRequest, getSpanFromRequest, traceLambda, tracingMiddleware, wrapHandler } from './chunk-V4IQWFYN.js';
2
+ import './chunk-I4CKQ4RD.js';
3
+ import './chunk-DGUM43GV.js';
4
+ //# sourceMappingURL=lambda.js.map
5
+ //# sourceMappingURL=lambda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"lambda.js"}
package/dist/s3.cjs ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkDHHLKZHI_cjs = require('./chunk-DHHLKZHI.cjs');
4
+ require('./chunk-Q3DMMQ7K.cjs');
5
+ require('./chunk-JEQ2X3Z6.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "traceS3", {
10
+ enumerable: true,
11
+ get: function () { return chunkDHHLKZHI_cjs.traceS3; }
12
+ });
13
+ //# sourceMappingURL=s3.cjs.map
14
+ //# sourceMappingURL=s3.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"s3.cjs"}
package/dist/s3.d.cts ADDED
@@ -0,0 +1,77 @@
1
+ import { TraceContext } from 'autotel';
2
+
3
+ /**
4
+ * S3-specific instrumentation
5
+ *
6
+ * Provides semantic helpers for tracing S3 operations with proper OpenTelemetry
7
+ * semantic conventions. Automatically sets `aws.s3.*` attributes.
8
+ *
9
+ * @example Basic usage with factory pattern
10
+ * ```typescript
11
+ * import { traceS3 } from 'autotel-aws/s3';
12
+ * import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
13
+ *
14
+ * const s3 = new S3Client({});
15
+ *
16
+ * export const getFile = traceS3({
17
+ * operation: 'GetObject',
18
+ * bucket: 'my-bucket'
19
+ * })(ctx => async (key: string) => {
20
+ * ctx.setAttribute('aws.s3.key', key);
21
+ * return await s3.send(new GetObjectCommand({ Bucket: 'my-bucket', Key: key }));
22
+ * });
23
+ *
24
+ * // Usage: await getFile('path/to/file.txt');
25
+ * ```
26
+ *
27
+ * @example Dynamic bucket
28
+ * ```typescript
29
+ * export const getObject = traceS3({
30
+ * operation: 'GetObject',
31
+ * })(ctx => async (bucket: string, key: string) => {
32
+ * ctx.setAttribute('aws.s3.bucket', bucket);
33
+ * ctx.setAttribute('aws.s3.key', key);
34
+ * return await s3.send(new GetObjectCommand({ Bucket: bucket, Key: key }));
35
+ * });
36
+ *
37
+ * // Usage: await getObject('my-bucket', 'file.txt');
38
+ * ```
39
+ */
40
+
41
+ /**
42
+ * S3 operation configuration
43
+ */
44
+ interface TraceS3Config {
45
+ /**
46
+ * S3 operation name (e.g., 'GetObject', 'PutObject', 'DeleteObject')
47
+ * Used to generate the span name: `s3.{operation}`
48
+ */
49
+ operation: string;
50
+ /**
51
+ * Default bucket name for static configurations.
52
+ * Can be overridden by setting `aws.s3.bucket` attribute in the handler.
53
+ */
54
+ bucket?: string;
55
+ }
56
+ /**
57
+ * Trace S3 operations with semantic attributes
58
+ *
59
+ * Creates a traced function that automatically sets S3 semantic attributes
60
+ * following OpenTelemetry conventions.
61
+ *
62
+ * @param config - S3 operation configuration
63
+ * @returns A higher-order function that wraps your S3 operation with tracing
64
+ *
65
+ * @remarks
66
+ * Semantic attributes set automatically:
67
+ * - `aws.s3.bucket` - S3 bucket name (if provided in config)
68
+ *
69
+ * Additional attributes you should set in your handler:
70
+ * - `aws.s3.key` - Object key
71
+ * - `aws.s3.copy_source` - Source for copy operations
72
+ *
73
+ * @see https://opentelemetry.io/docs/specs/semconv/object-stores/s3/
74
+ */
75
+ declare function traceS3(config: TraceS3Config): <TArgs extends unknown[], TReturn>(fn: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => (...args: TArgs) => Promise<TReturn>;
76
+
77
+ export { type TraceS3Config, traceS3 };
package/dist/s3.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import { TraceContext } from 'autotel';
2
+
3
+ /**
4
+ * S3-specific instrumentation
5
+ *
6
+ * Provides semantic helpers for tracing S3 operations with proper OpenTelemetry
7
+ * semantic conventions. Automatically sets `aws.s3.*` attributes.
8
+ *
9
+ * @example Basic usage with factory pattern
10
+ * ```typescript
11
+ * import { traceS3 } from 'autotel-aws/s3';
12
+ * import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
13
+ *
14
+ * const s3 = new S3Client({});
15
+ *
16
+ * export const getFile = traceS3({
17
+ * operation: 'GetObject',
18
+ * bucket: 'my-bucket'
19
+ * })(ctx => async (key: string) => {
20
+ * ctx.setAttribute('aws.s3.key', key);
21
+ * return await s3.send(new GetObjectCommand({ Bucket: 'my-bucket', Key: key }));
22
+ * });
23
+ *
24
+ * // Usage: await getFile('path/to/file.txt');
25
+ * ```
26
+ *
27
+ * @example Dynamic bucket
28
+ * ```typescript
29
+ * export const getObject = traceS3({
30
+ * operation: 'GetObject',
31
+ * })(ctx => async (bucket: string, key: string) => {
32
+ * ctx.setAttribute('aws.s3.bucket', bucket);
33
+ * ctx.setAttribute('aws.s3.key', key);
34
+ * return await s3.send(new GetObjectCommand({ Bucket: bucket, Key: key }));
35
+ * });
36
+ *
37
+ * // Usage: await getObject('my-bucket', 'file.txt');
38
+ * ```
39
+ */
40
+
41
+ /**
42
+ * S3 operation configuration
43
+ */
44
+ interface TraceS3Config {
45
+ /**
46
+ * S3 operation name (e.g., 'GetObject', 'PutObject', 'DeleteObject')
47
+ * Used to generate the span name: `s3.{operation}`
48
+ */
49
+ operation: string;
50
+ /**
51
+ * Default bucket name for static configurations.
52
+ * Can be overridden by setting `aws.s3.bucket` attribute in the handler.
53
+ */
54
+ bucket?: string;
55
+ }
56
+ /**
57
+ * Trace S3 operations with semantic attributes
58
+ *
59
+ * Creates a traced function that automatically sets S3 semantic attributes
60
+ * following OpenTelemetry conventions.
61
+ *
62
+ * @param config - S3 operation configuration
63
+ * @returns A higher-order function that wraps your S3 operation with tracing
64
+ *
65
+ * @remarks
66
+ * Semantic attributes set automatically:
67
+ * - `aws.s3.bucket` - S3 bucket name (if provided in config)
68
+ *
69
+ * Additional attributes you should set in your handler:
70
+ * - `aws.s3.key` - Object key
71
+ * - `aws.s3.copy_source` - Source for copy operations
72
+ *
73
+ * @see https://opentelemetry.io/docs/specs/semconv/object-stores/s3/
74
+ */
75
+ declare function traceS3(config: TraceS3Config): <TArgs extends unknown[], TReturn>(fn: (ctx: TraceContext) => (...args: TArgs) => Promise<TReturn>) => (...args: TArgs) => Promise<TReturn>;
76
+
77
+ export { type TraceS3Config, traceS3 };
package/dist/s3.js ADDED
@@ -0,0 +1,5 @@
1
+ export { traceS3 } from './chunk-ZPDRKCAR.js';
2
+ import './chunk-I4CKQ4RD.js';
3
+ import './chunk-DGUM43GV.js';
4
+ //# sourceMappingURL=s3.js.map
5
+ //# sourceMappingURL=s3.js.map
package/dist/s3.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"s3.js"}
package/dist/sdk.cjs ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var chunk4TGVGEUN_cjs = require('./chunk-4TGVGEUN.cjs');
4
+ require('./chunk-UZEJV2YD.cjs');
5
+ require('./chunk-Q3DMMQ7K.cjs');
6
+ require('./chunk-JEQ2X3Z6.cjs');
7
+
8
+
9
+
10
+ Object.defineProperty(exports, "autoInstrumentAWS", {
11
+ enumerable: true,
12
+ get: function () { return chunk4TGVGEUN_cjs.autoInstrumentAWS; }
13
+ });
14
+ Object.defineProperty(exports, "createTracedClient", {
15
+ enumerable: true,
16
+ get: function () { return chunk4TGVGEUN_cjs.createTracedClient; }
17
+ });
18
+ Object.defineProperty(exports, "disableAutoInstrumentAWS", {
19
+ enumerable: true,
20
+ get: function () { return chunk4TGVGEUN_cjs.disableAutoInstrumentAWS; }
21
+ });
22
+ Object.defineProperty(exports, "instrumentSDK", {
23
+ enumerable: true,
24
+ get: function () { return chunk4TGVGEUN_cjs.instrumentSDK; }
25
+ });
26
+ Object.defineProperty(exports, "isAutoInstrumentEnabled", {
27
+ enumerable: true,
28
+ get: function () { return chunk4TGVGEUN_cjs.isAutoInstrumentEnabled; }
29
+ });
30
+ //# sourceMappingURL=sdk.cjs.map
31
+ //# sourceMappingURL=sdk.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"sdk.cjs"}