2

I've started using AWS Synthetics Canaries with the Active Tracing option on, and correct me if I'm wrong, it's not very useful without nodejs code instrumentation like if I was making AWS SDK calls:

const AWSXRay = require('aws-xray-sdk');
const awsSdk = AWSXRay.captureAWS(require('aws-sdk'));

and at the very least to trace errors in downstream:

const AWSXRay = require('aws-xray-sdk');
AWSXRay.captureHTTPsGlobal(require('https'));

Is in place.

My concern is, that adding X-ray will increase the weight of complexity of the functions. Unless this instrumentation is somehow toggled off when not in use?

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
hendry
  • 9,725
  • 18
  • 81
  • 139

1 Answers1

3

const awsSdk = AWSXRay.captureAWS(require('aws-sdk')); enables instrumentation of all AWS SDK clients, which actually shouldn't affect the complexity of any of your functions.

You may add "complexity" if you decided to enable instrumentation per client (note that you can only use one or the other):

const AWSXRay = require('aws-xray-sdk');
...
var ddb = AWSXRay.captureAWSClient(new AWS.DynamoDB());

Active tracing enabled on a Lambda function, will only allow one thing - tracing of requests that don't have a tracing header. If you've enabled X-Ray tracing in a service that invokes your function e.g. API Gateway or calling the Lambda via an instrumented EC2 instance, you do not need active tracing. The service doing the tracing will sample incoming requests according to your settings & then add the tracing header where needed. Tracing AWS SDK calls just provides more granularity in the service map.


However, to answer your question, the AWS X-Ray SDK has two modes: manual and automatic.

It is in automatic mode by default (e.g. in a Lambda function), however, you can toggle the manual mode on the X-Ray SDK, like so.

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

This however will require you to pass around segment references as shown here.

For example, to capture function calls, this is one example:

import { S3, PutObjectCommand } from '@aws-sdk/client-s3';

var AWSXRay = require('aws-xray-sdk');
const s3 = AWSXRay.captureAWSv3Client(new S3({}), subsegment);

await s3.send(new PutObjectCommand({
  Bucket: bucketName,
  Key: keyName,
  Body: 'Hello!',
}));

This then becomes very complex in my opinion, and I would just recommend turning it on per client as opposed to "per function" if you're worried about too much data.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44