Trace AWS Lambda Java functions

The io.lumigo:java-tracer package is Lumigo's Java agent for distributed tracing and performance monitoring on AWS Lambda. It allows you to pursue automated metric gathering through Lambda Layers, automated metric gathering and instrumentation.

Add the Lumigo Tracer to your application

Add the Lumigo Java tracer dependencies to your application configuration using the following code:

<repositories>
    <repository>
        <id>lumigo</id>
        <url>https://raw.githubusercontent.com/lumigo-io/java-tracer/master/local-repository/</url>        
    </repository>
</repositories>


<dependency>
  <groupId>io.lumigo</groupId>
  <artifactId>java-tracer</artifactId>
  <version>{version}</version>
</dependency>

<dependency>
  <groupId>io.lumigo</groupId>
  <artifactId>lumigo-agent</artifactId>
  <version>{version}</version>
</dependency>

Wrap the code

With the package installed, simply implement a supplier with your code included, as the following example demonstrates:

class MyFunction implements RequestHandler<INPUT, OUTPUT> {
  
  static{
    LumigoConfiguration.builder().build().init();
  }
  
  @Override
    public OUTPUT handleRequest(INPUT event, Context context) {
    Supplier<OUTPUT> supplier = () -> {
      //Your lambda code
      // return <result of type OUTPUT>;
    };
    
    return LumigoRequestExecutor.execute(event, context, supplier);
  }
}

Connect Your Lumigo Account

Set your Lumigo token as the LUMIGO_TRACER_TOKEN environment variable of your Lambda function; refer to the Using AWS Lambda environment variables documentation for more information. Your Lumigo token is available in Settings -> Tracing -> Manual tracing, see the Lumigo Tokens documentation.

We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN; refer to AWS Lambda's Securing environment variables documentation for guidance on keeping the values of your Lambda environment variables secure.

Additional steps for Java 11

Set the environment variable JAVA_TOOL_OPTIONS to your Lambda functions as follows:

export JAVA_TOOL_OPTIONS='-Djdk.attach.allowAttachSelf=true'