Skip to main content

AWS Lambda - NodeJS function instrumentation

This document covers how to install and configure OpenTelemetry distributed tracing for AWS Lambda functions based on NodeJS and send the data to Sumo Logic.

To obtain tracing data from AWS Lambda functions developed in Node.js you can use OpenTelemetry NodeJS instrumentation. It provides auto instrumentation.

Sumo Logic AWS Distro Lambda Layer supports:

  • nodejs12.x and nodejs14.x runtimes
  • x86_64 and arm64 architectures

Sumo Logic AWS Distro Lambda layer

Sumo Logic AWS OTel Lambda Layer provides packed OpenTelemetry NodeJS libraries that automatically instrument Lambda functions. The biggest advantage of installing Sumo Logic OTel AWS as a layer is disabling/enabling instrumentation of the Lambda function without changing the code.

Distro Lambda Requirements

It is very simple to instrument your AWS NodeJS Lambda function using the Sumo Logic AWS Distro Lambda layer. You'll need the following:

  • NodeJS v12.x or newer
  • Lambda layers add permissions
  • HTTP Traces Source endpoint URL - To send spans from the instrumented Lambda function to Sumo Logic you need an endpoint URL from an existing or new HTTP Traces Source.
  1. Navigate to functions in the AWS Lambda Console and open the function you want to instrument.

  2. Navigate to the Layers section and click Add a layer.

  3. In the Choose a layer menu, select Specify an ARN and paste the ARN ID for your Lambda function AWS Region. Reference the amd64 and arm64 tables for the ARN ID.

    lambda-nodejs1.png

  4. Ensure the AWS Distro layer is present in the Layers section:

    lambda-nodejs2.png

  5. Navigate to the Configuration > Environment variables section and set up the following three required environment variables:

    • AWS_LAMBDA_EXEC_WRAPPER = /opt/otel-handler enables auto-instrumentation.

    • OTEL_TRACES_SAMPLER = always_on - enables traces sampling.

    • OTEL_SERVICE_NAME = YOUR_SERVICE_NAME - ensure you define it as a string value that represents the function name and its business logic such as "Check SQS Lambda". This will appear as the tracing service name in Sumo Logic.

    • Tracing application and cloud.account.id are set with the OTEL_RESOURCE_ATTRIBUTES environment variable.

      • application=YOUR_APPLICATION_NAME - the string value, if the function is a part of complex system/application then set it for all other functions/applications.

      • cloud.account.id=YOUR_CLOUD_ACCOUNT_ID - set an additional tag that will contain your AWS Lambda Account ID. This will help to provide more relevant data. 

        All of the attributes above are comma separated key/value pairs (this is also a way to add additional information to the spans, just after comma add additional key=value pair) such as, OTEL_RESOURCE_ATTRIBUTES=application=YOUR_APPLICATION_NAME,cloud.account.id=123456789012.

      • SUMOLOGIC_HTTP_TRACES_ENDPOINT_URL has to be set to send all gathered telemetry data to Sumo Logic. The URL comes from an HTTP Traces Endpoint URL. You can use an existing Source or create a new one if needed.

      lambda-nodejs3.png

  6. Your function should be successfully instrumented. Invoke the function and find your traces in the Sumo Logic Tracing screen.

amd64 architecture

The following are the Sumo Logic AWS Distro Lambda layers for AWS Region for amd64 (x86_64) architecture.

AWS RegionARN
US East (N.Virginia) us-east-1arn:aws:lambda:us-east-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
US East (Ohio) us-east-2arn:aws:lambda:us-east-2:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
US West (N.Carolina) us-west-1arn:aws:lambda:us-west-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
US West (Oregon) us-west-2arn:aws:lambda:us-west-2:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Africa (Cape Town) af-south-1arn:aws:lambda:af-south-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Hong Kong) ap-east-1arn:aws:lambda:ap-east-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Mumbai) ap-south-1arn:aws:lambda:ap-south-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Osaka) ap-northeast-3arn:aws:lambda:ap-northeast-3:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Seoul) ap-northeast-2arn:aws:lambda:ap-northeast-2:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Singapore) ap-southeast-1arn:aws:lambda:ap-southeast-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Sydney) ap-southeast-2arn:aws:lambda:ap-southeast-2:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Asia Pacific (Tokyo) ap-northeast-1arn:aws:lambda:ap-northeast-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Canada (Central) ca-central-1arn:aws:lambda:ca-central-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (Frankfurt) eu-central-1arn:aws:lambda:eu-central-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (Ireland) eu-west-1arn:aws:lambda:eu-west-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (London) eu-west-2arn:aws:lambda:eu-west-2:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (Milan) eu-south-1arn:aws:lambda:eu-south-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (Paris) eu-west-3arn:aws:lambda:eu-west-3:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Europe (Stockholm) eu-north-1arn:aws:lambda:eu-north-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
Middle East (Bahrain) me-south-1arn:aws:lambda:me-south-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1
South America (Sao Paulo) sa-east-1arn:aws:lambda:sa-east-1:663229565520:layer:sumologic-otel-nodejs-x86_64-ver-1-0-1:1

arm64 architecture

The following are the Sumo Logic AWS Distro Lambda layers for AWS Region for arm64.

AWS RegionARN
US East (N.Virginia) us-east-1arn:aws:lambda:us-east-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
US East (Ohio) us-east-2arn:aws:lambda:us-east-2:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
US West (Oregon) us-west-2arn:aws:lambda:us-west-2:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Asia Pacific (Mumbai) ap-south-1arn:aws:lambda:ap-south-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Asia Pacific (Osaka) ap-northeast-3arn:aws:lambda:ap-northeast-3:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Asia Pacific (Singapore) ap-southeast-1arn:aws:lambda:ap-southeast-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Asia Pacific (Sydney) ap-southeast-2arn:aws:lambda:ap-southeast-2:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Asia Pacific (Tokyo) ap-northeast-1arn:aws:lambda:ap-northeast-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Europe (Frankfurt) eu-central-1arn:aws:lambda:eu-central-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Europe (Ireland) eu-west-1arn:aws:lambda:eu-west-1:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1
Europe (London) eu-west-2arn:aws:lambda:eu-west-2:663229565520:layer:sumologic-otel-nodejs-arm64-ver-1-0-1:1

Sumo Logic AWS OTel Lambda container instrumentation

Sumo Logic AWS OTel Lambda also provides packed OpenTelemetry NodeJS libraries for container based Lambda functions. 

note

The instructions below support only AWS Base Images for Lambda.

Otel Lambda Requirements

Instrumentation of container based AWS Lambda function requires some changes in the Dockerfile and image rebuild. You'll need the following:

  • Docker
  • NodeJS v12.x or newer
  • HTTP Traces Source endpoint URL - To send spans from the instrumented Lambda function to Sumo Logic you need an endpoint URL from an existing or new HTTP Traces Source.

Lambda function image changes

  1. Download and extract Sumo Logic AWS OTel Lambda archive with instrumentation packages specific for your architecture - amd64 (x86_64) or arm64.

  2. Extracted instrumentation libraries have to be added to the image in /opt directory. Please see Dockerfile example:

    FROM public.ecr.aws/lambda/nodejs:14-arm64

    # Lambda Function Code
    COPY index.js ${LAMBDA_TASK_ROOT}
    COPY package.json ${LAMBDA_TASK_ROOT}
    RUN  npm install

    **# Copy OT Instrumentation
    COPY collector-config/ /opt/collector-config/
    COPY extensions/ /opt/extensions/
    COPY nodejs/ /opt/nodejs/
    COPY otel-handler /opt/
    COPY wrapper.d.ts /opt/
    COPY wrapper.d.ts.map /opt/
    COPY wrapper.js /opt/
    COPY wrapper.js.map /opt/**

    CMD \[ "index.handler" \]
  3. Rebuild docker image.

Deployment

  1. Navigate to functions in the AWS Lambda Console and open the function you want to instrument.

  2. Deploy new function image.

  3. Navigate to the Configuration > Environment variables section and set up the following environment variables:

    • AWS_LAMBDA_EXEC_WRAPPER = /opt/otel-handler enables auto-instrumentation.

    • OTEL_TRACES_SAMPLER = always_on - enables traces sampling.

    • OTEL_SERVICE_NAME = YOUR_SERVICE_NAME - ensure you define it as a string value that represents the function name and its business logic such as "Check SQS Lambda". This will appear as the tracing service name in Sumo Logic.

    • Tracing application and cloud.account.id are set with the OTEL_RESOURCE_ATTRIBUTES environment variable.

      • application=YOUR_APPLICATION_NAME - the string value, if the function is a part of complex system/application then set it for all other functions/applications.

      • cloud.account.id=YOUR_CLOUD_ACCOUNT_ID - set an additional tag that will contain your AWS Lambda Account ID. This will help to provide more relevant data. 

        All of the attributes above are comma separated key/value pairs (this is also a way to add additional information to the spans, just after comma add additional key=value pair) such as, OTEL_RESOURCE_ATTRIBUTES=application=YOUR_APPLICATION_NAME,cloud.account.id=123456789012.

      • SUMOLOGIC_HTTP_TRACES_ENDPOINT_URL has to be set to send all gathered telemetry data to Sumo Logic. The URL comes from an HTTP Traces Endpoint URL. You can use an existing Source or create a new one if needed.

      lambda-nodejs4.png

  4. Your function should be successfully instrumented. Invoke the function and find your traces in the Sumo Logic Tracing screen.

Legal
Privacy Statement
Terms of Use

Copyright © 2023 by Sumo Logic, Inc.