3

How can we sample the data in aws xray on the basis of http status code, e.g I would to sample 40% of records with status code 200 and 100% of records with status code 500. Below is the sample json but I cannot sample the data

const rules = {
    "rules": [{
        "description": "get users",
        "service_name": "*",
        "http_method": "GET",
        "url_path": "*",
        "fixed_target": 0,
        "rate": 0.25
        "attributes": {
            "status": 200
         }
    }],
    "default": { "fixed_target": 1, "rate": 0.1},
    "version": 1
};
JN_newbie
  • 5,492
  • 14
  • 59
  • 97

1 Answers1

0

The feature you require is currently not supported by the X-Ray SDK.
AWS mentions this in the docs [1]:

  • (optional) Attributes (key and value) – Segment attributes that are known when the sampling decision is made.

    • X-Ray SDK – Not supported. The SDK ignores rules that specify attributes.

    • Amazon API Gateway – Headers from the original HTTP request.

You can also see that it is not supported when looking at the source code of the sampling rule in the AWS X-Ray SDK for Node.js. [2]

I think that you can only specify the Attributes property from the AWS Management Console (not the SDK) and only for the Amazon API Gateway.

Solutions

  1. Increase the sample count to 100% (not recommended because it effectively destroys the purpose of sampling - although maybe feasible for a small portion of HTTP endpoints).
  2. Use an API Gateway (possibly costly).
  3. Open an Issue on GitHub with a feature request (FR) and write to the AWS support to submit a FR if you are on a support plan (not very promising according to my experience with AWS X-Ray development speed).

References

[1] https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html#xray-console-sampling-options
[2] https://github.com/aws/aws-xray-sdk-node/blob/6bade5ad006a47f19a5352a40f1ad2823f404e63/packages/core/lib/middleware/sampling/sampling_rule.js

Community
  • 1
  • 1
Martin Löper
  • 6,471
  • 1
  • 16
  • 40