AWS Lambda - Java Function Instrumentation
This document covers how to install and configure OpenTelemetry distributed tracing for AWS Lambda functions based on Java and send the data to Sumo Logic.
To obtain tracing data from AWS Lambda functions developed in Java, you can use Sumo Logic Distribution for OpenTelemetry Java Lambda, which provides auto-instrumentation.
Sumo Logic OTel Java Lambda layer supports:
- Java8 (Corretto) and Java11 (Corretto) runtimes
- x86_64 and arm64 architectures
Sumo Logic Distribution for OpenTelemetry Lambda layer
Lambda function requirements
You'll need the following:
- Java8 (Corretto) or Java11 (Corretto)
- Lambda layers add permissions
- Sumo Logic OTLP/HTTP Source endpoint URL. To send spans from the instrumented Lambda function to Sumo Logic you need an endpoint URL from an existing or new OTLP/HTTP source.
You can instrument your AWS Java Lambda function using the Sumo Logic Distribution for OpenTelemetry Lambda Layer version 1.30.1. By default, calls to the Lambda function and AWS Services are instrumented, see the Manual Instrumentation section below if your function is performing some other calls like HTTP requests or database calls.
- Navigate to functions in the AWS Lambda Console and open the function you want to instrument.
- Navigate to the Layers section and click Add a layer.
- 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.
- Ensure the AWS Distro layer is present in the Layers section:
noteYou must place the Sumo Logic layer first in the order or you won't see traces in Sumo Logic.
- Navigate to the Configuration > Environment variables section and set up the following required environment variables:
AWS_LAMBDA_EXEC_WRAPPER
environment variable configures the appropriate wrapper for a specific type of lambda handler function. Set the value appropriate for your handler:/opt/otel-handler
. If implementing RequestHandler./opt/otel-proxy-handler
. If implementing RequestHandler but proxied through API Gateway./opt/otel-stream-handler
. If implementing RequestStreamHandler.
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.OTEL_RESOURCE_ATTRIBUTES
. Sets OpenTelemetry resources. Add thedeployment.environment=[environment-name]
tag as needed to allow for filtering by environment on dashboard panels. (For more information, see Services Dashboard Panels). Tracingapplication
andcloud.account.id
are set with theOTEL_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
.
SUMO_OTLP_HTTP_ENDPOINT_URL
has to be set to send all gathered telemetry data to Sumo Logic. The URL comes from an OTLP/HTTP source. You can use an existing Source or create a new one, if needed.
noteThe
SUMOLOGIC_HTTP_TRACES_ENDPOINT_URL
environment variable is deprecated. You'll need to switch from the HTTP Traces Source to OTLP/HTTP source and use theSUMO_OTLP_HTTP_ENDPOINT_URL
environment variable instead. - Your function should be successfully instrumented. Invoke the function and find your traces in the Sumo Logic Tracing screen.
Optional manual instrumentation
By default, only calls to the Lambda function and AWS Services are instrumented to decrease instrumentation overhead. If the Lambda function is performing some other calls like HTTP requests or database calls it's worth providing additional instrumentation to get a better understanding of the Lambda execution.
See the OpenTelemetry Java Instrumentation repository and check if they are on the list of supported packages. Some changes in the code are needed and the specific package will have to be added to the Lambda function dependencies. The steps below show how to instrument calls from the OkHttp library.
- Add the OkHttp instrumentation package to your Lambda function dependencies.
- Update the imports list, add:
import io.opentelemetry.instrumentation.okhttp.v3_0.OkHttpTracing;
import io.opentelemetry.api.GlobalOpenTelemetry; - Initialize tracing for the OkHttp library.
okHttpClient client =
new OkHttpClient.Builder()
.addInterceptor(OkHttpTracing.create(GlobalOpenTelemetry.get()).newInterceptor())
.build();
This will generate all the spans related to the calls made by the OkHttp library.
Sumo Logic Distro Lambda layers for AWS Region - amd64 (x86_64) architecture
The following are the Sumo Logic OTel Lambda layers for AWS Region amd64 (x86_64) architecture.
AWS Region | ARN |
---|---|
af-south-1 | arn:aws:lambda:af-south-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-east-1 | arn:aws:lambda:ap-east-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-northeast-1 | arn:aws:lambda:ap-northeast-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-northeast-2 | arn:aws:lambda:ap-northeast-2:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-northeast-3 | arn:aws:lambda:ap-northeast-3:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-south-1 | arn:aws:lambda:ap-south-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-southeast-1 | arn:aws:lambda:ap-southeast-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ap-southeast-2 | arn:aws:lambda:ap-southeast-2:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
ca-central-1 | arn:aws:lambda:ca-central-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-central-1 | arn:aws:lambda:eu-central-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-north-1 | arn:aws:lambda:eu-north-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-south-1 | arn:aws:lambda:eu-south-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-west-1 | arn:aws:lambda:eu-west-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-west-2 | arn:aws:lambda:eu-west-2:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
eu-west-3 | arn:aws:lambda:eu-west-3:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
me-south-1 | arn:aws:lambda:me-south-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
sa-east-1 | arn:aws:lambda:sa-east-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
us-east-1 | arn:aws:lambda:us-east-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
us-east-2 | arn:aws:lambda:us-east-2:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
us-west-1 | arn:aws:lambda:us-west-1:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
us-west-2 | arn:aws:lambda:us-west-2:663229565520:layer:sumologic-otel-lambda-java-x86_64-v1-30-1:2 |
Sumo Logic Distro Lambda layers for AWS Region - arm64 (arm) architecture
The following are the Sumo Logic OTel Lambda layers for AWS Region arm64 architecture.
AWS Region | ARN |
---|---|
ap-northeast-1 | arn:aws:lambda:ap-northeast-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
ap-northeast-3 | arn:aws:lambda:ap-northeast-3:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
ap-south-1 | arn:aws:lambda:ap-south-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
ap-southeast-1 | arn:aws:lambda:ap-southeast-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
ap-southeast-2 | arn:aws:lambda:ap-southeast-2:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
eu-central-1 | arn:aws:lambda:eu-central-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
eu-west-1 | arn:aws:lambda:eu-west-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
eu-west-2 | arn:aws:lambda:eu-west-2:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
us-east-1 | arn:aws:lambda:us-east-1:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
us-east-2 | arn:aws:lambda:us-east-2:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
us-west-2 | arn:aws:lambda:us-west-2:663229565520:layer:sumologic-otel-lambda-java-arm64-v1-30-1:2 |
Sumo Logic OTel Lambda container instrumentation
Sumo Logic Distribution for OpenTelemetry Lambda Layer version 1.30.1 also provides packed OpenTelemetry Java libraries for container-based Lambda functions.
The instructions below support only AWS Base Images for Lambda.
Container based lambda requirements
Instrumentation of container-based AWS Lambda function requires some changes in the Dockerfile and image rebuild. You'll need the following:
- Docker
- Java 1.8+
- Sumo Logic OTLP/HTTP Source endpoint URL. To send spans from the instrumented Lambda function to Sumo Logic you need an endpoint URL from an existing or new OTLP/HTTP source.
Lambda function image changes
- Download and extract Sumo Logic Distribution for OpenTelemetry Java Lambda Layer archive with instrumentation packages specific for your architecture, amd64 (x86_64) or arm64.
- Add extracted instrumentation libraries to the image in the
/opt
directory. See the Dockerfile example:FROM public.ecr.aws/lambda/java:11-arm64
# Lambda Function Code
COPY lambda-function-.jar /opt/java/lib/
# Copy OT Instrumentation
COPY collector-config/ /opt/collector-config/
COPY extensions/ /opt/extensions/
COPY java/ /opt/java/
COPY otel-handler /opt/
COPY otel-proxy-handler /opt/
COPY otel-stream-handler /opt/
CMD ["your.lambda.function.RequestHandler::lambdaHandler"] - Rebuild the Docker image.
Deployment
- Navigate to functions in the AWS Lambda Console and open the function you want to instrument.
- Deploy new function image.
- Navigate to the Configuration > Environment variables section and set up the following environment variables:
AWS_LAMBDA_EXEC_WRAPPER
environment variable configures the appropriate wrapper for a specific type of lambda handler function. Set the value appropriate for your handler:/opt/otel-handler
. If implementingRequestHandler
./opt/otel-proxy-handler
. If implementingRequestHandler
, but proxied through API Gateway/opt/otel-stream-handler
. If implementingRequestStreamHandler
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.OTEL_TRACES_SAMPLER = always_on
. Enables traces sampling.OTEL_RESOURCE_ATTRIBUTES
. Sets OpenTelemetry resources. Add thedeployment.environment=[environment-name]
tag as needed to allow for filtering by environment on dashboard panels. (For more information, see Services Dashboard Panels). Tracingapplication
andcloud.account.id
are set with theOTEL_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
.
SUMO_OTLP_HTTP_ENDPOINT_URL
has to be set to send all gathered telemetry data to Sumo Logic. The URL comes from an OTLP/HTTP source. You can use an existing Source or create a new one, if needed.noteThe
SUMOLOGIC_HTTP_TRACES_ENDPOINT_URL
environment variable is deprecated. You'll need to switch from the HTTP Traces Source to OTLP/HTTP source and use theSUMO_OTLP_HTTP_ENDPOINT_URL
environment variable instead.
- Your function should be successfully instrumented. Invoke the function and find your traces in the Sumo Logic Tracing screen. The instructions above instrument only requests related to the handler function. To instrument other calls like HTTP calls and DB calls, you'll need to add additional libraries to the Docker image. See Supported libraries, frameworks and application servers.