aws / aws/aws-xray-sdk-node

XRay has problems recording subsegments when await keyword is used

Open
#219 4 comments 4 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
280
Forks
157
PR merge metrics
No merged PRs in 30d

Description

I have a method with a code similar to the code below were I used await method when calling pool.query() which is a pg pool method. The subsegment that is after the pool.query() never gets recorded but the code execute correctly. It returns that actual rows without any problem.


import {Pool} from 'pg';
import format from "pg-format"

const poolConfig = {
database:
host: ,
port: ,
user: ,
password:
}

pool = new Pool(poolConfig)

export const getDynamicLinkStats = async () => {
return await AWSXRay.captureAsyncFunc('Query-creation-and-postgres-call', async
function(subsegment){
const textQuery = ;

subsegment.addAnnotation('test', '1');

try {
const { rows } = await pool.query(textQuery);
subsegment.addAnnotation('test2', '2');

return rows;
} catch(error) {
return [];
} finally {
subsegment.close();
}
});
};

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example through AWSXRay.captureAsyncFunc with a pg Pool query, then inspect how the async callback and subsegment lifecycle behave across await. Done means the annotation after pool.query() and the surrounding subsegment are recorded reliably while the query still returns its rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js, postgresql
Domain
backend, databases, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.