0

I am trying to generate an x-ray using aws x-ray but it is not generating. Currently I am generating it for a lambda function in node.js

async function geUser(event, context) {

    await someFunction();
    const segment = new AWSXRay.Segment('getUser');
    segment.close();
    return 'success';
};

I have tried below example but still it's not generating

async function getUser(event, context) {

    await someFunction();
    AWSXRay.captureFunc('annotations', function(subsegment){
        console.log('xraysubsegment', subsegment);
        subsegment.addAnnotation('LambdaFunction', 'getUser');
        subsegment.addAnnotation('UserID', id);
    });
    return 'success';
};

and in serverless.yml

iamRoleStatements:
    - Effect: "Allow" 
      Action:
        - "xray:PutTraceSegments"
        - "xray:PutTelemetryRecords"
      Resource: "*"

Is there anything I am missing

JN_newbie
  • 5,492
  • 14
  • 59
  • 97

1 Answers1

0

To use X-Ray in a Lambda function, you need to enable X-Ray for that Lambda function.
In the console this is done under the "Debuggin and error handling configuration section", the configuration is called "Enable active tracing".

See the documentation for further details.

morras
  • 1,102
  • 9
  • 24
  • I need to understand one thing, it means that the code will work after checking the "Enable active tracing", or will the aws will add the tracing on its own? – JN_newbie Apr 10 '19 at 16:56
  • I would say so, but I haven't tried it with nodejs yet – morras Apr 10 '19 at 18:40