Skip to content

Commit b8524b1

Browse files
committed
test(pg-instrumentation): Add separate test for class-instance query
1 parent 36f605d commit b8524b1

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

packages/instrumentation-pg/test/pg.test.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,10 @@ describe('pg', () => {
583583
});
584584

585585
it('should record query and values for prepared statements', done => {
586-
class Statement {
587-
get name() {
588-
return 'get_pg_tables';
589-
}
590-
get text() {
591-
return 'SELECT * FROM pg_tables WHERE schemaname = $1';
592-
}
593-
}
594-
const queryConfig = new Statement();
586+
const queryConfig = {
587+
name: 'get_pg_tables',
588+
text: 'SELECT * FROM pg_tables WHERE schemaname = $1',
589+
};
595590
const values = ['public'];
596591

597592
const expectedAttributes = {
@@ -639,6 +634,40 @@ describe('pg', () => {
639634
assert.strictEqual(resNoPromise, undefined);
640635
});
641636
});
637+
638+
it('should record class-instance query', done => {
639+
class Statement {
640+
get name() {
641+
return 'get_pg_tables';
642+
}
643+
get text() {
644+
return 'SELECT * FROM pg_tables WHERE schemaname = $1';
645+
}
646+
}
647+
const queryConfig = new Statement();
648+
const values = ['public'];
649+
650+
const expectedAttributes = {
651+
...DEFAULT_ATTRIBUTES,
652+
[ATTR_DB_STATEMENT]: queryConfig.text,
653+
[AttributeNames.PG_PLAN]: queryConfig.name,
654+
[AttributeNames.PG_VALUES]: values,
655+
};
656+
657+
const span = tracer.startSpan('test span');
658+
context.with(trace.setSpan(context.active(), span), () => {
659+
(client.query as any)(
660+
queryConfig,
661+
values,
662+
(err: Error | null, res: any) => {
663+
assert.strictEqual(err, null);
664+
assert.ok(res);
665+
runCallbackTest(span, expectedAttributes, events);
666+
done();
667+
}
668+
);
669+
});
670+
});
642671
});
643672

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

0 commit comments

Comments
 (0)