4

I'm trying to get a custom X-Ray segment reporting, but I'm not seeing anything in the trace. My code looks something like this:

var AWSXRay = require('aws-xray-sdk-core');

AWSXRay.captureAsyncFunc('callSoapService', subsegment => {
  doSomethingAsync(params, err => {
    if (err) {
      subsegment.close(err);
    } else {
      doSomethingElse().then(result => {
        console.info('all done, now close the segment');
        subsegment.close();
      }, subsegment.close);
    }
  });
});

Do I need to add it to the parent segment or something?

Nicholas Albion
  • 3,096
  • 7
  • 33
  • 56

2 Answers2

1

ugh. there seems to be a bug with AWSXRay.captureHTTPs() - if I remove that call captureAsyncFunc() starts working

Nicholas Albion
  • 3,096
  • 7
  • 33
  • 56
1

For the AWS X-Ray Node SDK, automatic mode is build on the continuation-local-storage (cls) package which has known compatibility issues with promise libraries. This is why your 'then' seems to be losing context. However, most of these libraries have various CLS shims available to provide the compatibility necessary to work.

Which promise library are you using? For bluebird, there's 'cls-bluebird' or for Q there's 'cls-q' that's available that will get it working.

They usually ask to pass in the CLS namespace, which is available from xray.getNamespace().

Hope this helps.

AWSSandra
  • 374
  • 1
  • 7