This page describes how to use the Java Serverless Tracer API to fine-tune your configuration.

Transaction Error Reports

If you automatically instrument the tracer, transaction errors are reported if an exception is thrown. If you manually instrument the tracer, transaction error reports are optional and require manual configuration. 

If your business logic defines the transaction as in error for any reason, you can customize the error report method to mark the transaction in error.

To create transaction error reports, use transaction.reportError()

The transaction.reportError() method reports one error per invocation. You can also use transaction.reportError() for any errorName or errorMessage:

transaction.reportError(errorName, errorMessage);
JAVA


Exit Call Error Reports

You can report errors and exceptions that occur during exit call execution using the exitCall.reportError() method. You must call the method before transaction.stop().

Use exitCall.reportError() for any exception or subclass:

exitCall.reportError(exception);
JAVA

You can also use exitCall.reportError() for a specific errorName or errorMessage

exitCall.reportError(errorName, errorMessage);
JAVA

Override the Tracer's Default Behavior 

If you prefer to customize the function and business transaction names, or keep the tracer settings in your code, you can override the environment variables using the AppDynamics.Config.Builder object. This option allows you to retrieve values at runtime from any desired source. 

AppDynamics.Config.Builder configBuilder = new AppDynamics.Config.Builder();
configBuilder.accountName(accountName)
   .applicationName(appName)
   .tierName(tierName)
   .controllerHost(controllerHost)
   .controllerPort(controllerPort)
   .defaultBtName(context.getFunctionName() + "_bt")
   .controllerAccessKey(controllerAccessKey)
   .lambdaContext(context);
JAVA


Implementation of the configBuilder object differs slightly depending on which instrumentation method you choose, automatic or manual.

Automatic Instrumentation

Automatic instrumentation uses the MonitoredRequestStreamHandler class, which implements a factory method, getConfigBuilder(), to instrument the tracer. 

You can override this factory method and use any builder method to configure environment variables.

The code snippet shows how to enter variables in your code for automatic instrumentation: 

@Override
public AppDynamics.Config.Builder getConfigBuilder(Context context) {
String controllerHost = System.getenv("APPDYNAMICS_CONTROLLER_HOST");
int controllerPort = Integer.parseInt(System.getenv("APPDYNAMICS_CONTROLLER_PORT"));
String accountName = System.getenv("APPDYNAMICS_ACCOUNT_NAME");
String appName = System.getenv("APPDYNAMICS_APPLICATION_NAME");
String tierName = System.getenv("APPDYNAMICS_TIER_NAME");
String controllerAccessKey = System.getenv("APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY");

AppDynamics.Config.Builder configBuilder = new AppDynamics.Config.Builder();
configBuilder.accountName(accountName)
   .applicationName(appName)
   .tierName(tierName)
   .controllerHost(controllerHost)
   .controllerPort(controllerPort)
   .defaultBtName(context.getFunctionName() + "_bt")
   .controllerAccessKey(controllerAccessKey)
   .lambdaContext(context);
return configBuilder;
  }
JAVA


Manual Instrumentation

In manual instrumentation, the overloaded version of the AppDynamics.getTracer() method configures the tracer's settings. The overloaded method takes a configBuilder object as a parameter, instead of the context object, to instrument the tracer. 

When you use this variant of AppDynamics.getTracer(), you must pass the context object via the AppDynamics.Config.Builder.lambdaContext() method.

The code snippet shows how to enter variables in your code for manual instrumentation. 

@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException) {
        String controllerHost = System.getenv("APPDYNAMICS_CONTROLLER_HOST");
        int controllerPort = Integer.parseInt(System.getenv("APPDYNAMICS_CONTROLLER_PORT"));
        String accountName = System.getenv("APPDYNAMICS_ACCOUNT_NAME");
        String appName = System.getenv("APPDYNAMICS_APPLICATION_NAME");
        String tierName = System.getenv("APPDYNAMICS_TIER_NAME");
        String controllerAccessKey = System.getenv("APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY");
        AppDynamics.Config.Builder configBuilder = new AppDynamics.Config.Builder();
        configBuilder.accountName(accountName)
                .applicationName(appName)
                .tierName(tierName)
                .controllerHost(controllerHost)
                .controllerPort(controllerPort)
                .defaultBtName(context.getFunctionName() + "_bt")
                .controllerAccessKey(controllerAccessKey)
                .lambdaContext(context);
        
	//Replace the context object with config.Builder.build()
	Tracer tracer = AppDynamics.getTracer(configBuilder.build());
JAVA


Amazon Web Services, the AWS logo, AWS, and any other AWS Marks used in these materials are trademarks of 
Amazon.com, Inc. or its affiliates in the United States and/or other countries.