You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using connection pools, the pool.query method can be called directly as a shortcut instead of calling pool.getConnection, then querying (doc):
[pool.query] is a shortcut for the pool.getConnection() -> connection.query() -> connection.release() code flow.
As a result, the subsegments for that query are duplicated because both pool.query and pool.getConnection().query have been captured to create subsegments, and both are called.
Here's an example:
constAWSXRay=require('aws-xray-sdk')AWSXRay.captureMySQL(require('mysql2'))constmysqlPromise=require('mysql2/promise')constns=AWSXRay.getNamespace()asyncfunctiontestPromisePoolQuery(){try{constpool=mysqlPromise.createPool({host: 'localhost',user: 'user',password: 'password',database: 'test',connectionLimit: 10,queueLimit: 0,})awaitpool.query('SELECT 1')awaitpool.end()}catch(err){console.error('Error connecting to database:',err)}}ns.run(async()=>{letsegment=newAWSXRay.Segment('testPromisePoolQuery')AWSXRay.setSegment(segment)awaittestPromisePoolQuery()console.log(`testPromisePoolQuery # of subsegments: ${AWSXRay.getSegment().subsegments?.length}`)segment.close()})
The result printed from this is testPromisePoolQuery # of subsegments: 2, and if you view the subsegment you can see that the queries are the same, and timings are almost exactly the same.
The text was updated successfully, but these errors were encountered:
I'm hacking around this by patching createPoolbefore calling captureMySQL to prevent it from capturing pool.query and pool.execute. This way it only captures the connections returned from pool.getConnection within the query/execute calls.
When using connection pools, the
pool.query
method can be called directly as a shortcut instead of callingpool.getConnection
, then querying (doc):As a result, the subsegments for that query are duplicated because both
pool.query
andpool.getConnection().query
have been captured to create subsegments, and both are called.Here's an example:
The result printed from this is
testPromisePoolQuery # of subsegments: 2
, and if you view the subsegment you can see that the queries are the same, and timings are almost exactly the same.The text was updated successfully, but these errors were encountered: