JSPM

  • Created
  • Published
  • Downloads 1904397
  • Score
    100M100P100Q226120F
  • License Apache-2.0

OpenTelemetry AWS Lambda automatic instrumentation package.

Package Exports

  • @opentelemetry/instrumentation-aws-lambda
  • @opentelemetry/instrumentation-aws-lambda/build/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@opentelemetry/instrumentation-aws-lambda) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

OpenTelemetry AWS Lambda Instrumentation for Node.js

NPM Published Version Apache License

component owners: @carolabadeer

This module provides automatic instrumentation for the AWS Lambda module, which may be loaded using the @opentelemetry/sdk-trace-node package and is included in the @opentelemetry/auto-instrumentations-node bundle.

If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.

This module is currently under active development and not ready for general use.

Compatible with OpenTelemetry JS API and SDK 1.0+.

Installation

npm install --save @opentelemetry/instrumentation-aws-lambda

Usage

Create a file to initialize the instrumentation, such as lambda-wrapper.js.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new AwsLambdaInstrumentation({
        // see under for available configuration
    })
  ],
});

In your Lambda function configuration, add or update the NODE_OPTIONS environment variable to require the wrapper, e.g.,

NODE_OPTIONS=--require lambda-wrapper

AWS Lambda Instrumentation Options

Options Type Description
requestHook RequestHook (function) Hook for adding custom attributes before lambda starts handling the request. Receives params: span, { event, context }
responseHook ResponseHook (function) Hook for adding custom attributes before lambda returns the response. Receives params: span, { err?, res? }
disableAwsContextPropagation boolean By default, this instrumentation will try to read the context from the _X_AMZN_TRACE_ID environment variable set by Lambda, set this to true to disable this behavior
eventContextExtractor EventContextExtractor (function) Function for providing custom context extractor in order to support different event types that are handled by AWS Lambda (e.g., SQS, CloudWatch, Kinesis, API Gateway). Applied only when disableAwsContextPropagation is set to true. Receives params: event, context

Hooks Usage Example

const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');

new AwsLambdaInstrumentation({
    requestHook: (span, { event, context }) => {
        span.setAttribute('faas.name', context.functionName);
    },
    responseHook: (span, { err, res }) => {
        if (err instanceof Error) span.setAttribute('faas.error', err.message);
        if (res) span.setAttribute('faas.res', res);
    }
})

License

Apache 2.0 - See LICENSE for more information.