alex99_14
alex99_14

Reputation: 35

AWS Xray manual mode setting segment

I am attempting to some trace data to AWS Xray without express middleware. My code is as follows:

const AWSXRay = require('aws-xray-sdk'),
      AWS = AWSXRay.captureAWS(require('aws-sdk')),
      sqs = AWSXRay.captureAWSClient(new AWS.SQS({apiVersion: '2012-11-05', region: 'eu-west-1'}));

AWSXRay.enableManualMode();
var segment = new AWSXRay.Segment('sqsSegment');

var params = {
  QueueUrl: "https://sqs.eu-west-1.amazonaws.com/123/queuename",
  VisibilityTimeout: 0,
  WaitTimeSeconds: 0,
  XraySegment: segment
};

sqs.receiveMessage(params, function(err, data) {
  if (err) console.log(err, err.stack);
  else     console.log(data);
});

segment.close();

I'm getting the error: Error: No sub/segment specified. A sub/segment must be provided for manual mode.

I'm creating a segment and passing it in via params to receiveMessage. But it appears to not be working. Any ideas?

Upvotes: 1

Views: 2816

Answers (1)

AWSSandra
AWSSandra

Reputation: 384

You need to do either a global level capture (captureAWS) or client level capture (captureAWSClient), not both. Using 'captureAWS', all clients created will be automatically patched, so when you do another 'captureAWSClient' on the client that's already patched, capture function runs twice and can't resolve the context correctly.

Remove one of the captures and it should work. I'll see if I can add a fix to prevent this.

Hope this helps, Sandra

Upvotes: 2

Related Questions