JVM

Configuring the Lumigo tracer for JVM Lambda functions consists of two steps: setting up the dependency, then wrapping your code.

Overview

Configuring the Lumigo tracer for JVM Lambda functions consists of two steps: setting up the dependency, then wrapping your code.

Setting the Lumigo dependency

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>

Wrapping 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);
  }
}

Finally, 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.

We advise you to use the most secure available to you to store secrets such as your LUMIGO_TRACER_TOKEN; additionally, AWS provides integrations for AWS Key Management Service that keep the values of your Lambda environment variables secure.

You should now see events flowing through from your JVM Lambda function!

Java 11 support

Add the environment variable JAVA_TOOL_OPTIONS to your Lambda functions and set it to
-Djdk.attach.allowAttachSelf=true in addition to the manual code mentioned above.


Did this page help you?