给aws xray添加采样规则
准备规则文件
rule-apigateway-dev-10pct.json
{"SamplingRule": {"RuleName": "apigateway-prod-10pct","ResourceARN": "*","Priority": 100,"FixedRate": 0.1,"ReservoirSize": 0,"ServiceName": "*","ServiceType": "*","Host": "*","HTTPMethod": "*","URLPath": "/prod/*","Version": 1,"Attributes": {}}
}
新增规则不会改变 Default,它仍然是 FixedRate=0.05、ReservoirSize=1。只有命中 /prod/* 的请求才会按 10% 采样。
添加采样规则
aws xray create-sampling-rule --region cn-north-1 --cli-input-json file://rule-apigateway-dev-10pct.json
查看所有规则
aws xray get-sampling-rules
参考
- 使用 AWS CLI 的 X-Ray 示例
- Configuring sampling rules
