@senzops/apm-node 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.3.1
2
+
3
+ feat: add support for aws lambda extension layer
4
+
1
5
  # 1.3.0
2
6
 
3
7
  feat: AI SDK instrumentation — Anthropic, Google Gemini (generative-ai + Vertex AI), Azure OpenAI, Cohere, Mistral
package/README.md CHANGED
@@ -245,6 +245,64 @@ export default {
245
245
 
246
246
  ### AWS Lambda
247
247
 
248
+ Three deployment options, from zero-code to code-level:
249
+
250
+ #### Option 1: Lambda Extension Layer (Zero Code Changes, Recommended)
251
+
252
+ Build and publish a Lambda Layer, then reconfigure your function. No changes to your application code.
253
+
254
+ ```sh
255
+ # 1. Build the layer
256
+ mkdir -p senzor-layer/nodejs && cd senzor-layer/nodejs
257
+ npm init -y && npm install @senzops/apm-node
258
+ cd .. && zip -r senzor-apm-layer.zip nodejs/
259
+
260
+ # 2. Publish
261
+ aws lambda publish-layer-version \
262
+ --layer-name senzor-apm-node \
263
+ --zip-file fileb://senzor-apm-layer.zip \
264
+ --compatible-runtimes nodejs18.x nodejs20.x nodejs22.x
265
+
266
+ # 3. Attach to function and configure
267
+ aws lambda update-function-configuration \
268
+ --function-name my-function \
269
+ --layers <LAYER_ARN> \
270
+ --handler @senzops/apm-node/dist/lambda-handler.handler \
271
+ --environment Variables="{ \
272
+ SENZOR_API_KEY=sz_apm_xxx, \
273
+ SENZOR_LAMBDA_HANDLER=index.handler, \
274
+ NODE_OPTIONS=--require @senzops/apm-node/register \
275
+ }"
276
+ ```
277
+
278
+ The auto-handler wrapper reads `SENZOR_LAMBDA_HANDLER` to load your original handler, wraps it with full APM instrumentation, and re-exports it for Lambda to invoke.
279
+
280
+ **AWS CDK:**
281
+
282
+ ```ts
283
+ const senzorLayer = new lambda.LayerVersion(this, 'SenzorApmLayer', {
284
+ code: lambda.Code.fromAsset(path.join(__dirname, 'senzor-layer')),
285
+ compatibleRuntimes: [lambda.Runtime.NODEJS_18_X, lambda.Runtime.NODEJS_20_X],
286
+ description: 'Senzor APM Lambda Extension Layer',
287
+ });
288
+
289
+ const fn = new lambda.Function(this, 'MyFunction', {
290
+ runtime: lambda.Runtime.NODEJS_20_X,
291
+ handler: '@senzops/apm-node/dist/lambda-handler.handler',
292
+ code: lambda.Code.fromAsset('lambda'),
293
+ layers: [senzorLayer],
294
+ environment: {
295
+ SENZOR_API_KEY: 'sz_apm_xxx',
296
+ SENZOR_LAMBDA_HANDLER: 'index.handler',
297
+ NODE_OPTIONS: '--require @senzops/apm-node/register',
298
+ },
299
+ });
300
+ ```
301
+
302
+ Also works with SAM, Serverless Framework, Terraform, and the AWS Console. See the [wiki](wiki.md#4-aws-lambda-integration) for full examples.
303
+
304
+ #### Option 2: Code-Level Handler Wrapper
305
+
248
306
  ```ts
249
307
  import Senzor from '@senzops/apm-node';
250
308
 
@@ -255,25 +313,15 @@ export const handler = Senzor.wrapLambda(async (event, context) => {
255
313
  });
256
314
  ```
257
315
 
258
- `wrapLambda` provides:
316
+ #### What's Captured
317
+
318
+ Both approaches provide:
259
319
  - **Cold start detection** tagged on the first invocation per container
260
320
  - **Trigger-type detection**: API Gateway v1/v2, ALB, SQS, SNS, DynamoDB Streams, EventBridge, S3, Scheduled events
261
321
  - **Lambda context extraction**: function name, request ID, memory limit, log group, invoked ARN, region, account ID
262
322
  - **Forced flush** before each invocation returns (Lambda freezes the process immediately after)
263
323
  - **Lambda Extensions API** registration for SHUTDOWN lifecycle safety-net flush
264
-
265
- #### Lambda Layer Deployment (No Code Changes)
266
-
267
- ```sh
268
- # Set environment variables on your Lambda function
269
- SENZOR_API_KEY=sz_apm_xxx
270
- NODE_OPTIONS=--require @senzops/apm-node/register
271
- ```
272
-
273
- When running inside Lambda, the SDK auto-detects the environment and optimizes:
274
- - Runtime metrics are disabled (meaningless per-invocation)
275
- - Batch size reduced to 10
276
- - Flush interval set to 0 (flush only on demand)
324
+ - **Auto-optimized settings**: runtime metrics disabled, batch size 10, flush on demand only
277
325
 
278
326
  ---
279
327