Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/instrumentation-pg/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ export class PgInstrumentation extends InstrumentationBase<PgInstrumentationConf
: firstArgIsQueryObjectWithText
? {
...(arg0 as any),
name: arg0.name,
text: arg0.text,
values:
(arg0 as any).values ??
(Array.isArray(args[1]) ? args[1] : undefined),
Expand Down
34 changes: 34 additions & 0 deletions packages/instrumentation-pg/test/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,40 @@ describe('pg', () => {
assert.strictEqual(resNoPromise, undefined);
});
});

it('should record class-instance query', done => {
class Statement {
get name() {
return 'get_pg_tables';
}
get text() {
return 'SELECT * FROM pg_tables WHERE schemaname = $1';
}
}
const queryConfig = new Statement();
const values = ['public'];

const expectedAttributes = {
...DEFAULT_ATTRIBUTES,
[ATTR_DB_STATEMENT]: queryConfig.text,
[AttributeNames.PG_PLAN]: queryConfig.name,
[AttributeNames.PG_VALUES]: values,
};

const span = tracer.startSpan('test span');
context.with(trace.setSpan(context.active(), span), () => {
(client.query as any)(
queryConfig,
values,
(err: Error | null, res: any) => {
assert.strictEqual(err, null);
assert.ok(res);
runCallbackTest(span, expectedAttributes, events);
done();
}
);
});
});
});

describe('when specifying a requestHook configuration', () => {
Expand Down