Search code examples
node.jsamazon-web-servicesaws-xray

Exclude Path from being traced in AWS X-Ray


Tracing certain paths, like a health check, don't provide much value to us. We want to ensure we aren't paying for AWS XRay traces against health endpoints. I am trying to exclude such paths with sampling rules, but it is not working.I have attempted to use rules and setSamplingRules() without luck. I have tried using the specific url path I want to exclude as well as a wildcard like below.

var rules = {
"rules": [ { "description": "PostTest", "service_name": "*", 
"http_method": "*", "url_path": "*", "fixed_target": 0, "rate": 0.0 } 
],
"default": { "fixed_target": 1, "rate": 0.1 },
"version": 1
}

AWSXRay.middleware.setSamplingRules(rules);
app.use(AWSXRay.express.openSegment('app-1'));

....path
....path
....path

app.use(AWSXRay.express.closeSegment());

I am using the latest version of aws-xray-sdk (1.1.6).


Solution

  • Update: Adding debugging, I discovered that locally the rule is being matched. However, when deployed, the rule is not being matched. The issue is that the health endpoint is being called via the Rancher healthcheck container, which does not provide a service name - it is undefined. Thus, it does not match the rule with the 'service_name'='*'.

    Reply: This seems to be a bug with the AWS X-Ray SDK for Node.js. An undefined host header should indeed match the wildcard character.

    This has been fixed in the latest version.

    Forums post addressing issue here: https://forums.aws.amazon.com/thread.jspa?threadID=269425&tstart=0