[英]AWS XRay with AWS SDK v3 for NodeJS
Is there any way how to use XRay instrumentation for AWS NodeJS SDK v3?有什么方法可以为 AWS NodeJS SDK v3 使用 XRay 检测? In SDK v2, AWSXray was able to capture any client and instrument it for tracing into XRay.在 SDK v2 中,AWSXray 能够捕获任何客户端并对其进行检测以跟踪 XRay。 I have been trying the same thing with v3 with following snippet我一直在尝试使用以下代码段对 v3 进行同样的操作
const {DynamoDBClient, ScanCommand} = require("@aws-sdk/client-dynamodb");
const AWSXRay = require("aws-xray-sdk");
// if uncommented, this throws an exception
// AWSXRay.captureAWSClient(DynamoDBClient);
const client = new DynamoDBClient({region: process.env.AWS_REGION});
// if uncommented, this throws an exception
// AWSXRay.captureAWSClient(client);
const scan = new ScanCommand({
TableName: 'xxx',
});
await client.send(scan) //?
but both commented lines throw service.customizeRequests is not a function
.但是两条注释行都抛出service.customizeRequests is not a function
。 This seems like AWS SDK s3 is not backward-compatible with original AWSXRay library.这似乎 AWS SDK s3 不向后兼容原始 AWSXRay 库。
I found that SDK v3 contains XRay client, but this is just a client that can send spans and traces into AWS, not an instrumentation agent.我发现 SDK v3 包含 XRay 客户端,但这只是一个可以将跨度和跟踪发送到 AWS 的客户端,而不是检测代理。
What's recommended pattern of using XRay instrumentation with AWS SDK v3 for NodeJS?对于 NodeJS,将 XRay 检测与 AWS SDK v3 结合使用的推荐模式是什么?
You need to use v3
compatible x-ray-sdk
capture function captureAWSv3Client
您需要使用v3
兼容x-ray-sdk
捕获 function captureAWSv3Client
Here is working snippet:这是工作片段:
const {DynamoDBClient, ScanCommand} = require("@aws-sdk/client-dynamodb");
const AWSXRay = require("aws-xray-sdk-core");
const dynamoClient = AWSXRay.captureAWSv3Client(
new DynamoDBClient({})
)
const scan = new ScanCommand({
TableName: 'xxx',
});
const response = await dynamoClient.send(scan)
It is also important to have permissions to write into X-Ray eg:拥有写入 X-Ray 的权限也很重要,例如:
Policies:
- AWSXrayWriteOnlyAccess
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.