The atatus.startMessageTransaction
function is used to initiate a transaction in Atatus for monitoring and tracking the processing of messages retrieved from an Amazon SQS queue. This function should be called whenever a message is processed after retrieving it using sqs.receiveMessage
from the AWS SDK. It helps track the performance and attributes of message processing as a transaction.
When to Call
- Trigger Point: Call
atatus.startMessageTransaction
immediately after receiving a message viasqs.receiveMessage
and before processing its contents. - Purpose: To monitor the lifecycle of message processing, including any custom logic or operations performed on the message.
- Context: Suitable for both AWS SDK v2 (e.g.,
aws-sdk
) and v3 (e.g.,@aws-sdk/client-sqs
) when handling SQS messages.
Compatibility
Compatible with Node.js agent version 3.2.0 or higher
Syntax
atatus.startMessageTransaction(transaction_name, options)
Parameter
Parameter | Type | Description |
---|---|---|
transaction_name | String (Required) | A string that identifies the transaction (e.g., "ProcessSQSMessage" or a dynamic name based on the message) |
options | Object | An object containing additional metadata, such as attributes , which should include the message.MessageAttributes from the SQS message for detailed tracking. |
Example
const AWS = require('aws-sdk');
const atatus = require('atatus-nodejs');
const sqs = new AWS.SQS();
sqs.receiveMessage({
QueueUrl: 'YOUR_QUEUE_URL',
MaxNumberOfMessages: 1,
MessageAttributeNames: ['All']
}, (err, data) => {
if (err) {
console.error(err);
return;
}
if (data.Messages) {
const message = data.Messages[0];
// Start Atatus transaction with message attributes
const transaction = atatus.startMessageTransaction('ProcessSQSMessage', {
attributes: message.MessageAttributes
});
try {
// Process the message here
console.log('Processing message:', message.Body);
// End transaction on success
transaction.end();
} catch (error) {
// End transaction with error if processing fails
agent.notifyError(error);
transaction.end();
}
}
});