Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 3.68 KB

File metadata and controls

85 lines (63 loc) · 3.68 KB

OpenTelemetry AWS Lambda Instrumentation for Node.js

NPM Published Version dependencies devDependencies Apache License

This module provides automatic instrumentation for AWS Lambda.

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

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/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? }
disableAwsPropagation boolean By default, this instrumentation will try to get the context using propagator-aws-xray, set this to true to disable this behavior

Hooks Usage Example

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

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

Useful links

License

Apache 2.0 - See LICENSE for more information.