Manual tracer instrumentation consists of the following steps:
Instantiate the Java Serverless Tracer
To instantiate the tracer, call the
AppDynamics.getTracer(context) method. Place the method at the beginning of your function's entry point method.
The code snippet demonstrates how to instantiate the tracer:
Create a Transaction
Next, you need to create transactions. A transaction is a monitored segment in a larger business transaction. Creating a transaction involves locating the correlation header, which the tracer uses to pass contextual information downstream.
- Start a new business transaction, or
- Continue an existing business transaction
Start a New Business Transaction
A transaction that originates in the current function does not have an inbound correlation header. To create a business transaction, use the
createTransaction() method and provide an empty correlation header.
Continue an Existing Business Transaction
To continue an existing business transaction, you need to locate an inbound correlation header. You can locate a correlation header automatically or manually.
If the tracer cannot find the correlation header, the tracer creates a new business transaction.
Continue a Business Transaction by Locating the Correlation Header Automatically
createTransaction(inputStream, context) method to create a transaction that locates the correlation header automatically. This method searches your code's object schema for a key called
singularityheader in the
inputStream object. The correlation header finds the
singularityheader key, then continues the business transaction.
The tracer reads the
inputStream object, which is configured to be read once. If your application needs to read the
inputStream object, you must use a converter method to allow both the tracer and your application to read the stream.
The code snippet shows an example of how to create a transaction and automatically locate the correlation header:
Create a Transaction by Locating the Correlation Header Manually
To create a transaction that locates the correlation header using custom logic, you need to manually parse a
correlationHeader string. Next, call the
createTransaction()method and provide the
correlationHeader object. This process gives you full control over the parsing of your function's input payload.
The code snippet shows an example of how to obtain the correlation header string and create a transaction:
Start and Stop a Transaction
After creating a transaction, you need to set transaction boundaries. Use the
stop() methods to place boundaries around any section of code that you want the tracer to monitor.
As a best practice, you can report all events, even if your function crashes, by running your entire function within a
try block, and then stopping the transaction within a
This code sample demonstrates how to start and stop a transaction that monitors an entire function:
Create External Exit Calls
createExitCall method is used to obtain an
exitCall object. Exit call objects record the time spent in external exit calls and allow for correlation of downstream activity.
Exit Call Types and Identifying Properties
In the Controller, each exit call has a distinct type, determined by a set of identifying properties.
exitCall types and identifying properties are listed below:
|CUSTOM||Any user-defined set of properties|
Create an External Exit Call
createExitCall() on your transaction object.
The following code sample demonstrates how you might perform an external exit call:
Create Multiple External Exit Calls
If one AWS Lambda function makes multiple exit calls, each function should be identified by a unique
exitCall object. To make multiple exit calls, create new
exitCall objects for each distinct exit call. The
exitCall objects are not reusable.
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.