简体   繁体   English

AWS XRay 与 AWS SDK v3 for NodeJS

[英]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.

相关问题 aws-xray-sdk nodejs lambda 到 lambda xray 没有在第二个 lambda 上采样痕迹 - aws-xray-sdk nodejs lambda to lambda xray is not sampling the traces on second lambda Aws SDK:集成 AWS v3 时出现 CredentialsProviderError Javascript SDK - Aws SDK: CredentialsProviderError while integrating AWS v3 Javascript SDK 用于 nodejs 的 AWS SDK v3,如何获取 s3 存储桶的标签? - AWS SDK v3 for nodejs, how to get tags of an s3 bucket? aws xray 不监控 nodejs 中的 dynamo dax 客户端 - aws xray not monitoring dynamo dax client in nodejs 将 CognitoIdentityCredentials 迁移到模块化 AWS SDK for JavaScript (v3) - Migrating CognitoIdentityCredentials to modular AWS SDK for JavaScript (v3) 使用 aws sdk v3 调试 ENOTFOUND 错误 - Debugging ENOTFOUND error using aws sdk v3 AWS SDK v3 TransactWriteItemsCommand 类型错误:无法读取未定义的属性“0” - AWS SDK v3 TransactWriteItemsCommand TypeError: Cannot read property '0' of undefined 如何获取 cognito 用户组(在 AWS JS SDK V3 中) - How to get a cognito users' group (in AWS JS SDK V3) node.js sdk v3 中的 AWS 更新凭证 - AWS update credentials in node js sdk v3 将带有预签名 url 的分段上传从 aws javascript sdk v2 迁移到 v3 - migrate multipart upload with presigned urls from aws javascript sdk v2 to v3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM