startTransaction() function is used to create a custom transaction. For supported frameworks, Atatus Java agent will automatically capture the transactions. This function can be used to instrument unsupported frameworks or background operations.

Add dependency before starting with the api.

pom.xml

<dependency>
    <groupId>com.atatus.apm</groupId>
    <artifactId>atatus-agent-api</artifactId>
    <version>1.4.0</version>
</dependency>

Compatibility

Compatible with all Java agent versions.

Syntax

copy
icon/buttons/copy
import com.atatus.apm.api.Atatus;
import com.atatus.apm.api.Transaction;

Transaction transaction = Atatus.startTransaction();

Example

To call "startTransaction", you need to create transaction instance with atatus.

copy
icon/buttons/copy
import com.atatus.apm.api.Atatus;
import com.atatus.apm.api.Transaction;

public class ViewController {

    public String invoke() {

        Transaction transaction = Atatus.startTransaction();
        transaction.setName("Product/view");

        try {
            // Your code here...
        } catch (Exception ex) {
            // This sends an exception event to Atatus
            transaction.captureException(ex);
            throw ex;
        } finally {
            transaction.end();
        }
    }
}

After start transaction, you have to set a transaction name using the transaction.setName() function.

See also