gpt4 book ai didi

node.js - aws xray 采样不适用于 http 状态代码

转载 作者:行者123 更新时间:2023-12-02 18:25:41 26 4
gpt4 key购买 nike

我们如何根据http状态代码对aws xray中的数据进行采样,例如,我会对状态代码为200的40%的记录和状态代码为500的100%的记录进行采样。下面是示例json,但我无法对数据进行采样

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
};

最佳答案

X-Ray SDK 目前不支持您需要的功能。
AWS 在文档 [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.

查看AWS X-Ray SDK for Node.js中的采样规则的源代码时,您还可以看到它不受支持。 [2]

我认为您只能从 AWS 管理控制台(而不是开发工具包)指定 Attributes 属性,并且只能针对 Amazon API Gateway。

解决方案

  1. 将样本计数增加到 100%(不建议这样做,因为这实际上破坏了采样的目的 - 尽管对于一小部分 HTTP 端点来说可能可行)。
  2. 使用 API 网关(可能成本较高)。
  3. 在 GitHub 上提出一个包含功能请求 (FR) 的问题,如果您有支持计划(根据我对 AWS X-Ray 开发速度的经验,这不是很有希望),请写信给 AWS 支持来提交 FR。

引用文献

[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

关于node.js - aws xray 采样不适用于 http 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57326144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com