Exit Call Management

An exit call is either a custom exit call or an automatically-detected exit call. A transaction needs its exit call object to create correlation information to provide to a downstream transaction that needs to correlate with it.

Custom Exit Calls

If you want an exit call to be reported to the controller, and it is not automatically detected by the agent, create a custom exit call with startExitCall() and end it with endExitCall().

See Node.js Supported Environments for the list of backends that are automatically detected by the Node.js Agent. If the exit call invokes a backend not listed on this page, you probably need to create a custom exit call.

You can also use a beforeExitCall() callback function to check for the existence of an automatically-detected exit call.

Processing a custom exit call is straightforward. First, create the exit call and then pass its returned ExitCall object to createCorrelationInfo() to create a string-encoded correlation information object that a downstream transaction can fetch later.

Workflow for a custom exit call
// start a custom transaction
var trx = appd.startTransaction(. . . )
. . .
// start a custom exit call
exit = trx.startExitCall(. . .);
// create correlation information
cinfo = trx.createCorrelationInfo(exit)
//store cinfo where it can be made available to a downstream transaction
// make the exit call
. . .
trx.endExitCall(. . .)

Automatically Detected Exit Calls

The code executing in your custom transaction might make an exit call that is automatically detected by the Node.js Agent.

In this case, you can provide a beforeExitCall() callback function to process that exit call. When your code makes an automatically-detected exit call, the agent intercepts the exit call request and invokes the callback, if you have provided one. Then it allows the application to proceed with the exit call request.

You would install a beforeExitCall() callback function for the following purposes:

  • To test for the existence of an automatically-detected exit call.

    If you are uncertain that the exit call will be automatically detected, you can install a callback function to test for the exit call. If the callback is not invoked, the exit call is not automatically detected.

    // start a custom transaction
    var trx = appd.startTransaction(. . . )
    . . .
    var detected = false;
    trx.beforeExitCall = function(call) { detected = true; return call; };
    // make the exit call
    . . .
    // test whether the exit call was automatically detected
    if (detected == false)
    . . .

    If detected is false after the exit call, you need to create a custom exit call to report the exit call to the Controller. If detected is true, you can capture the exit call and create the correlation information with the callback.

  • To capture the ExitCall object to create correlation information

    // start a custom transaction
    var trx = appd.startTransaction(. . . )
    . . .
    trx.beforeExitCall = function getExitInfo(exitCall) {
    // create the correlation header from the captured exit call
    var c = trx.createCorrelationInfo(exitCall);
    // store c somewhere
    // … (c)
    return exitCall;
    }
    // make the exit call
  • To modify the exit call that is reported to the Controller

    // start a custom transaction
    var trx = appd.startTransaction(. . . )
    . . .
    trx.beforeExitCall = function customExitCallHandler(exitCall) {
        // don't report database access for this transaction
        if (exitCall.isSql) return;
        // customize label for all other exit calls in this transaction
        exitCall.label += " (my custom transaction)";
        return exitCall;
    }
    // make the exit call