Skip to content

Commit e687a79

Browse files
committed
Explicitly test query properties
1 parent efd789d commit e687a79

File tree

1 file changed

+264
-38
lines changed
  • dev-packages/node-integration-tests/suites/tracing/postgresjs

1 file changed

+264
-38
lines changed

dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts

Lines changed: 264 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
44
const EXISTING_TEST_EMAIL = '[email protected]';
55
const NON_EXISTING_TEST_EMAIL = '[email protected]';
66

7-
// Helper function to create basic span matcher (reduces duplication in new tests)
8-
function createDbSpanMatcher(operationName: string, descriptionMatcher: unknown = expect.any(String)) {
9-
return expect.objectContaining({
10-
data: expect.objectContaining({
11-
'db.namespace': 'test_db',
12-
'db.system.name': 'postgres',
13-
'db.operation.name': operationName,
14-
'sentry.op': 'db',
15-
'sentry.origin': 'auto.db.postgresjs',
16-
'server.address': 'localhost',
17-
'server.port': 5444,
18-
}),
19-
description: descriptionMatcher,
20-
op: 'db',
21-
origin: 'auto.db.postgresjs',
22-
});
23-
}
24-
257
describe('postgresjs auto instrumentation', () => {
268
afterAll(() => {
279
cleanupChildProcesses();
@@ -124,13 +106,13 @@ describe('postgresjs auto instrumentation', () => {
124106
'db.namespace': 'test_db',
125107
'db.system.name': 'postgres',
126108
'db.operation.name': 'SELECT',
127-
'db.query.text': `SELECT * FROM "User" WHERE "email" = ? AND "name" = ?`,
109+
'db.query.text': 'SELECT * FROM "User" WHERE "email" = ? AND "name" = ?',
128110
'sentry.op': 'db',
129111
'sentry.origin': 'auto.db.postgresjs',
130112
'server.address': 'localhost',
131113
'server.port': 5444,
132114
}),
133-
description: `SELECT * FROM "User" WHERE "email" = ? AND "name" = ?`,
115+
description: 'SELECT * FROM "User" WHERE "email" = ? AND "name" = ?',
134116
op: 'db',
135117
status: 'ok',
136118
origin: 'auto.db.postgresjs',
@@ -342,13 +324,13 @@ describe('postgresjs auto instrumentation', () => {
342324
'db.namespace': 'test_db',
343325
'db.system.name': 'postgres',
344326
'db.operation.name': 'SELECT',
345-
'db.query.text': `SELECT * FROM "User" WHERE "email" = ? AND "name" = ?`,
327+
'db.query.text': 'SELECT * FROM "User" WHERE "email" = ? AND "name" = ?',
346328
'sentry.op': 'db',
347329
'sentry.origin': 'auto.db.postgresjs',
348330
'server.address': 'localhost',
349331
'server.port': 5444,
350332
}),
351-
description: `SELECT * FROM "User" WHERE "email" = ? AND "name" = ?`,
333+
description: 'SELECT * FROM "User" WHERE "email" = ? AND "name" = ?',
352334
op: 'db',
353335
status: 'ok',
354336
origin: 'auto.db.postgresjs',
@@ -621,10 +603,72 @@ describe('postgresjs auto instrumentation', () => {
621603
const EXPECTED_TRANSACTION = {
622604
transaction: 'Test Transaction',
623605
spans: expect.arrayContaining([
624-
createDbSpanMatcher('CREATE TABLE'),
625-
createDbSpanMatcher('INSERT'),
626-
createDbSpanMatcher('UPDATE'),
627-
createDbSpanMatcher('SELECT'),
606+
expect.objectContaining({
607+
data: expect.objectContaining({
608+
'db.namespace': 'test_db',
609+
'db.system.name': 'postgres',
610+
'db.operation.name': 'CREATE TABLE',
611+
'db.query.text':
612+
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
613+
'sentry.op': 'db',
614+
'sentry.origin': 'auto.db.postgresjs',
615+
'server.address': 'localhost',
616+
'server.port': 5444,
617+
}),
618+
description:
619+
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
620+
op: 'db',
621+
status: 'ok',
622+
origin: 'auto.db.postgresjs',
623+
}),
624+
expect.objectContaining({
625+
data: expect.objectContaining({
626+
'db.namespace': 'test_db',
627+
'db.system.name': 'postgres',
628+
'db.operation.name': 'INSERT',
629+
'db.query.text': `INSERT INTO "User" ("email", "name") VALUES ('Foo', '${EXISTING_TEST_EMAIL}')`,
630+
'sentry.op': 'db',
631+
'sentry.origin': 'auto.db.postgresjs',
632+
'server.address': 'localhost',
633+
'server.port': 5444,
634+
}),
635+
description: `INSERT INTO "User" ("email", "name") VALUES ('Foo', '${EXISTING_TEST_EMAIL}')`,
636+
op: 'db',
637+
status: 'ok',
638+
origin: 'auto.db.postgresjs',
639+
}),
640+
expect.objectContaining({
641+
data: expect.objectContaining({
642+
'db.namespace': 'test_db',
643+
'db.system.name': 'postgres',
644+
'db.operation.name': 'UPDATE',
645+
'db.query.text': `UPDATE "User" SET "name" = 'Foo' WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
646+
'sentry.op': 'db',
647+
'sentry.origin': 'auto.db.postgresjs',
648+
'server.address': 'localhost',
649+
'server.port': 5444,
650+
}),
651+
description: `UPDATE "User" SET "name" = 'Foo' WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
652+
op: 'db',
653+
status: 'ok',
654+
origin: 'auto.db.postgresjs',
655+
}),
656+
expect.objectContaining({
657+
data: expect.objectContaining({
658+
'db.namespace': 'test_db',
659+
'db.system.name': 'postgres',
660+
'db.operation.name': 'SELECT',
661+
'db.query.text': `SELECT * FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
662+
'sentry.op': 'db',
663+
'sentry.origin': 'auto.db.postgresjs',
664+
'server.address': 'localhost',
665+
'server.port': 5444,
666+
}),
667+
description: `SELECT * FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
668+
op: 'db',
669+
status: 'ok',
670+
origin: 'auto.db.postgresjs',
671+
}),
628672
]),
629673
};
630674

@@ -639,10 +683,72 @@ describe('postgresjs auto instrumentation', () => {
639683
const EXPECTED_TRANSACTION = {
640684
transaction: 'Test Transaction',
641685
spans: expect.arrayContaining([
642-
createDbSpanMatcher('CREATE TABLE'),
643-
createDbSpanMatcher('INSERT'),
644-
createDbSpanMatcher('SELECT'),
645-
createDbSpanMatcher('DELETE'),
686+
expect.objectContaining({
687+
data: expect.objectContaining({
688+
'db.namespace': 'test_db',
689+
'db.system.name': 'postgres',
690+
'db.operation.name': 'CREATE TABLE',
691+
'db.query.text':
692+
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
693+
'sentry.op': 'db',
694+
'sentry.origin': 'auto.db.postgresjs',
695+
'server.address': 'localhost',
696+
'server.port': 5444,
697+
}),
698+
description:
699+
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
700+
op: 'db',
701+
status: 'ok',
702+
origin: 'auto.db.postgresjs',
703+
}),
704+
expect.objectContaining({
705+
data: expect.objectContaining({
706+
'db.namespace': 'test_db',
707+
'db.system.name': 'postgres',
708+
'db.operation.name': 'INSERT',
709+
'db.query.text': `INSERT INTO "User" ("email", "name") VALUES ('Foo', '${EXISTING_TEST_EMAIL}')`,
710+
'sentry.op': 'db',
711+
'sentry.origin': 'auto.db.postgresjs',
712+
'server.address': 'localhost',
713+
'server.port': 5444,
714+
}),
715+
description: `INSERT INTO "User" ("email", "name") VALUES ('Foo', '${EXISTING_TEST_EMAIL}')`,
716+
op: 'db',
717+
status: 'ok',
718+
origin: 'auto.db.postgresjs',
719+
}),
720+
expect.objectContaining({
721+
data: expect.objectContaining({
722+
'db.namespace': 'test_db',
723+
'db.system.name': 'postgres',
724+
'db.operation.name': 'SELECT',
725+
'db.query.text': `SELECT * FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
726+
'sentry.op': 'db',
727+
'sentry.origin': 'auto.db.postgresjs',
728+
'server.address': 'localhost',
729+
'server.port': 5444,
730+
}),
731+
description: `SELECT * FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
732+
op: 'db',
733+
status: 'ok',
734+
origin: 'auto.db.postgresjs',
735+
}),
736+
expect.objectContaining({
737+
data: expect.objectContaining({
738+
'db.namespace': 'test_db',
739+
'db.system.name': 'postgres',
740+
'db.operation.name': 'DELETE',
741+
'db.query.text': `DELETE FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
742+
'sentry.op': 'db',
743+
'sentry.origin': 'auto.db.postgresjs',
744+
'server.address': 'localhost',
745+
'server.port': 5444,
746+
}),
747+
description: `DELETE FROM "User" WHERE "email" = '${EXISTING_TEST_EMAIL}'`,
748+
op: 'db',
749+
status: 'ok',
750+
origin: 'auto.db.postgresjs',
751+
}),
646752
]),
647753
};
648754

@@ -658,10 +764,70 @@ describe('postgresjs auto instrumentation', () => {
658764
const EXPECTED_TRANSACTION = {
659765
transaction: 'Test Transaction',
660766
spans: expect.arrayContaining([
661-
createDbSpanMatcher('CREATE TABLE'),
662-
createDbSpanMatcher('INSERT'),
663-
createDbSpanMatcher('SELECT'),
664-
createDbSpanMatcher('DROP TABLE'),
767+
expect.objectContaining({
768+
data: expect.objectContaining({
769+
'db.namespace': 'test_db',
770+
'db.system.name': 'postgres',
771+
'db.operation.name': 'CREATE TABLE',
772+
'db.query.text': 'CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))',
773+
'sentry.op': 'db',
774+
'sentry.origin': 'auto.db.postgresjs',
775+
'server.address': 'localhost',
776+
'server.port': 5444,
777+
}),
778+
description: 'CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))',
779+
op: 'db',
780+
status: 'ok',
781+
origin: 'auto.db.postgresjs',
782+
}),
783+
expect.objectContaining({
784+
data: expect.objectContaining({
785+
'db.namespace': 'test_db',
786+
'db.system.name': 'postgres',
787+
'db.operation.name': 'INSERT',
788+
'db.query.text': 'INSERT INTO "User" ("email") VALUES (?)',
789+
'sentry.op': 'db',
790+
'sentry.origin': 'auto.db.postgresjs',
791+
'server.address': 'localhost',
792+
'server.port': 5444,
793+
}),
794+
description: 'INSERT INTO "User" ("email") VALUES (?)',
795+
op: 'db',
796+
status: 'ok',
797+
origin: 'auto.db.postgresjs',
798+
}),
799+
expect.objectContaining({
800+
data: expect.objectContaining({
801+
'db.namespace': 'test_db',
802+
'db.system.name': 'postgres',
803+
'db.operation.name': 'SELECT',
804+
'db.query.text': 'SELECT * FROM "User" WHERE "email" = ?',
805+
'sentry.op': 'db',
806+
'sentry.origin': 'auto.db.postgresjs',
807+
'server.address': 'localhost',
808+
'server.port': 5444,
809+
}),
810+
description: 'SELECT * FROM "User" WHERE "email" = ?',
811+
op: 'db',
812+
status: 'ok',
813+
origin: 'auto.db.postgresjs',
814+
}),
815+
expect.objectContaining({
816+
data: expect.objectContaining({
817+
'db.namespace': 'test_db',
818+
'db.system.name': 'postgres',
819+
'db.operation.name': 'DROP TABLE',
820+
'db.query.text': 'DROP TABLE "User"',
821+
'sentry.op': 'db',
822+
'sentry.origin': 'auto.db.postgresjs',
823+
'server.address': 'localhost',
824+
'server.port': 5444,
825+
}),
826+
description: 'DROP TABLE "User"',
827+
op: 'db',
828+
status: 'ok',
829+
origin: 'auto.db.postgresjs',
830+
}),
665831
]),
666832
};
667833

@@ -676,10 +842,70 @@ describe('postgresjs auto instrumentation', () => {
676842
const EXPECTED_TRANSACTION = {
677843
transaction: 'Test Transaction',
678844
spans: expect.arrayContaining([
679-
createDbSpanMatcher('CREATE TABLE'),
680-
createDbSpanMatcher('INSERT'),
681-
createDbSpanMatcher('SELECT'),
682-
createDbSpanMatcher('DROP TABLE'),
845+
expect.objectContaining({
846+
data: expect.objectContaining({
847+
'db.namespace': 'test_db',
848+
'db.system.name': 'postgres',
849+
'db.operation.name': 'CREATE TABLE',
850+
'db.query.text': 'CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))',
851+
'sentry.op': 'db',
852+
'sentry.origin': 'auto.db.postgresjs',
853+
'server.address': 'localhost',
854+
'server.port': 5444,
855+
}),
856+
description: 'CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))',
857+
op: 'db',
858+
status: 'ok',
859+
origin: 'auto.db.postgresjs',
860+
}),
861+
expect.objectContaining({
862+
data: expect.objectContaining({
863+
'db.namespace': 'test_db',
864+
'db.system.name': 'postgres',
865+
'db.operation.name': 'INSERT',
866+
'db.query.text': 'INSERT INTO "User" ("email") VALUES (?)',
867+
'sentry.op': 'db',
868+
'sentry.origin': 'auto.db.postgresjs',
869+
'server.address': 'localhost',
870+
'server.port': 5444,
871+
}),
872+
description: 'INSERT INTO "User" ("email") VALUES (?)',
873+
op: 'db',
874+
status: 'ok',
875+
origin: 'auto.db.postgresjs',
876+
}),
877+
expect.objectContaining({
878+
data: expect.objectContaining({
879+
'db.namespace': 'test_db',
880+
'db.system.name': 'postgres',
881+
'db.operation.name': 'SELECT',
882+
'db.query.text': 'SELECT * FROM "User" WHERE "email" = ?',
883+
'sentry.op': 'db',
884+
'sentry.origin': 'auto.db.postgresjs',
885+
'server.address': 'localhost',
886+
'server.port': 5444,
887+
}),
888+
description: 'SELECT * FROM "User" WHERE "email" = ?',
889+
op: 'db',
890+
status: 'ok',
891+
origin: 'auto.db.postgresjs',
892+
}),
893+
expect.objectContaining({
894+
data: expect.objectContaining({
895+
'db.namespace': 'test_db',
896+
'db.system.name': 'postgres',
897+
'db.operation.name': 'DROP TABLE',
898+
'db.query.text': 'DROP TABLE "User"',
899+
'sentry.op': 'db',
900+
'sentry.origin': 'auto.db.postgresjs',
901+
'server.address': 'localhost',
902+
'server.port': 5444,
903+
}),
904+
description: 'DROP TABLE "User"',
905+
op: 'db',
906+
status: 'ok',
907+
origin: 'auto.db.postgresjs',
908+
}),
683909
]),
684910
};
685911

0 commit comments

Comments
 (0)