如何将查询 dynamodb xray 作为自定义段的子段?
How to make querying dynamodb xray as a subsegment of a customised segment?
我有一个多次查询 dynamodb 的 lambda 函数。我想使用 xray
来获得有关查询的性能。
我在 nodejs 中创建了 lambda:
this.documentClient = new DocumentClient({
service: new DynamoDB(),
});
AWSXray.captureAWSClient((this.documentClient as any).service);
查询dynamodb时,我使用的是代码:
const segment = AWSXRay.getSegment();
const subsegment = segment.addNewSubsegment('query dynamodb');
await this.documentClient.query(...).promise();
await this.documentClient.query(...).promise();
await this.documentClient.query(...).promise();
...
subsegment.close();
我可以看到跟踪数据:
但问题是 query dynamodb
段不是其他 dynamodb 查询子段的父段。如何将所有 dynamodb 查询包装在我的自定义段中?
我认为这里的问题是 query dynamodb
子段没有设置在 DynamoDB
子段的上下文中。因此,所有子分段的父级都是 Lambda FacadeSegment。您可以尝试使用 Manual Mode to manually pass around the subsegment
to the DDB calls. Refer to the example 了解详细信息。
我有一个多次查询 dynamodb 的 lambda 函数。我想使用 xray
来获得有关查询的性能。
我在 nodejs 中创建了 lambda:
this.documentClient = new DocumentClient({
service: new DynamoDB(),
});
AWSXray.captureAWSClient((this.documentClient as any).service);
查询dynamodb时,我使用的是代码:
const segment = AWSXRay.getSegment();
const subsegment = segment.addNewSubsegment('query dynamodb');
await this.documentClient.query(...).promise();
await this.documentClient.query(...).promise();
await this.documentClient.query(...).promise();
...
subsegment.close();
我可以看到跟踪数据:
但问题是 query dynamodb
段不是其他 dynamodb 查询子段的父段。如何将所有 dynamodb 查询包装在我的自定义段中?
我认为这里的问题是 query dynamodb
子段没有设置在 DynamoDB
子段的上下文中。因此,所有子分段的父级都是 Lambda FacadeSegment。您可以尝试使用 Manual Mode to manually pass around the subsegment
to the DDB calls. Refer to the example 了解详细信息。