Create or Modify Exit Calls

If your function uses ES6 or includes exit calls other than HTTP or inter-AWS lambda calls, you need to create an exit call.

The following code snippet demonstrates how to create an exit call for an AWS Lambda function that calls a MySQL database:

// Use the exit call API in your AWS Lambda handler function
module.exports.myLambdaHandler = async function () {
const queryPromise = new Promise(function (resolve, reject) {
const dbConfig = {
host: '127.0.0.1', // The host where MySQL server runs
port: 3306, // Note that this is not an identifying property. Identifying properties must be strings
user: 'root',
database: 'movies'
};
const mysql = require('mysql');
const mysqlClient = mysql.createPool(dbConfig);
mysqlClient.getConnection(function (err, connection) {
if (err) {
reject({
statusCode: 500,
body: 'Couldn\'t make the connection to mysql client.'
});
return;
}
// Create an Exit Call
var exitCall = tracer.startExitCall({
exitType: 'DB',
exitSubType: 'DB',
identifyingProperties: {
'HOST': '127.0.0.1', // The host where MySQL server runs
'PORT': '3306',
'DATABASE': 'movies',
'VENDOR': 'MYSQL'
}
});
connection.query('SELECT * FROM ClassicHits', function (err, results) {
connection.release();
if (err) {
reject({
statusCode: 500,
body: 'Mysql query failed'
});
return;
}
// Stop the Exit Call
tracer.stopExitCall(exitCall);
resolve({
statusCode: 200,
body: JSON.stringify(results)
});
});
});
});
return queryPromise;
}

Exit Call Types and Identifying Properties

Each exit call in the Controller has a distinct type determined by a set of identifying properties. The exit call types, subtypes, and identifying properties are listed below. For exit call subtypes, you can use the examples in the table or an empty string. Identifying properties must be strings.

Exit Call Type Exit Call Subtype Identifying Properties
HTTP HTTP

HOST

PORT

URL

QUERY STRING

DB

DB

URL

HOST

PORT

DATABASE

VERSION

VENDOR

CACHE

CACHE

VENDOR

SERVER POOL

CUSTOM

CASSANDRA CQL

COUCHBASE

AMAZON WEB SERVICES

MONGODB

Any user-defined set of properties.
Note:

The following interceptors are supported and do not require manual instrumentation in CommonJS:

  • aws_sdk for lambda.invoke and lambda.invokeAsync
  • http and https libraries