Skip to content

Commit 0b60751

Browse files
authored
fix(pg-instrumentation): capture query props when passed as class instance (#3249)
1 parent 53a6c94 commit 0b60751

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

packages/instrumentation-pg/src/instrumentation.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,24 +333,21 @@ export class PgInstrumentation extends InstrumentationBase<PgInstrumentationConf
333333
// TODO: remove the `as ...` casts below when the TS version is upgraded.
334334
// Newer TS versions will use the result of firstArgIsQueryObjectWithText
335335
// to properly narrow arg0, but TS 4.3.5 does not.
336-
let queryConfig: any;
337-
338-
if (firstArgIsString) {
339-
queryConfig = {
340-
text: arg0 as string,
341-
values: Array.isArray(args[1]) ? args[1] : undefined,
342-
};
343-
} else if (firstArgIsQueryObjectWithText) {
344-
const q = arg0 as any;
345-
346-
if (q.values === undefined && Array.isArray(args[1])) {
347-
q.values = args[1];
348-
}
349-
350-
queryConfig = q;
351-
} else {
352-
queryConfig = undefined;
353-
}
336+
const queryConfig = firstArgIsString
337+
? {
338+
text: arg0 as string,
339+
values: Array.isArray(args[1]) ? args[1] : undefined,
340+
}
341+
: firstArgIsQueryObjectWithText
342+
? {
343+
...(arg0 as any),
344+
name: arg0.name,
345+
text: arg0.text,
346+
values:
347+
(arg0 as any).values ??
348+
(Array.isArray(args[1]) ? args[1] : undefined),
349+
}
350+
: undefined;
354351

355352
const attributes: Attributes = {
356353
[ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_POSTGRESQL,

0 commit comments

Comments
 (0)