Skip to content

Commit d9a0dfa

Browse files
committed
Revert unrelated Astro changes, add ESM test for sql.unsafe()
1 parent 9266b95 commit d9a0dfa

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

dev-packages/e2e-tests/test-applications/cloudflare-astro/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const dsn = process.env.E2E_TEST_DSN;
66

77
// https://astro.build/config
88
export default defineConfig({
9+
output: 'hybrid',
910
adapter: cloudflare({
1011
imageService: 'passthrough',
1112
}),

dev-packages/e2e-tests/test-applications/cloudflare-astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"test:assert": "pnpm -v"
1818
},
1919
"dependencies": {
20-
"@astrojs/cloudflare": "12.6.11",
20+
"@astrojs/cloudflare": "8.1.0",
2121
"@sentry/astro": "latest || *",
2222
"astro": "5.15.9"
2323
},
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as Sentry from '@sentry/node';
2+
import postgres from 'postgres';
3+
4+
// Stop the process from exiting before the transaction is sent
5+
setInterval(() => {}, 1000);
6+
7+
// Test with plain object options
8+
const sql = postgres({ port: 5444, user: 'test', password: 'test', database: 'test_db' });
9+
10+
async function run() {
11+
await Sentry.startSpan(
12+
{
13+
name: 'Test Transaction',
14+
op: 'transaction',
15+
},
16+
async () => {
17+
try {
18+
// Test sql.unsafe() - this was not being instrumented before the fix
19+
await sql.unsafe('CREATE TABLE "User" ("id" SERIAL NOT NULL, "email" TEXT NOT NULL, PRIMARY KEY ("id"))');
20+
21+
await sql.unsafe('INSERT INTO "User" ("email") VALUES ($1)', ['test@example.com']);
22+
23+
await sql.unsafe('SELECT * FROM "User" WHERE "email" = $1', ['test@example.com']);
24+
25+
await sql.unsafe('DROP TABLE "User"');
26+
27+
// This will be captured as an error as the table no longer exists
28+
await sql.unsafe('SELECT * FROM "User"');
29+
} finally {
30+
await sql.end();
31+
}
32+
},
33+
);
34+
}
35+
36+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
37+
run();

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,23 @@ describe('postgresjs auto instrumentation', () => {
625625
.start()
626626
.completed();
627627
});
628+
629+
test('should instrument sql.unsafe() queries (ESM)', { timeout: 90_000 }, async () => {
630+
const EXPECTED_TRANSACTION = {
631+
transaction: 'Test Transaction',
632+
spans: expect.arrayContaining([
633+
createDbSpanMatcher('CREATE TABLE'),
634+
createDbSpanMatcher('INSERT'),
635+
createDbSpanMatcher('SELECT'),
636+
createDbSpanMatcher('DROP TABLE'),
637+
]),
638+
};
639+
640+
await createRunner(__dirname, 'scenario-unsafe.mjs')
641+
.withFlags('--import', `${__dirname}/instrument.mjs`)
642+
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] })
643+
.expect({ transaction: EXPECTED_TRANSACTION })
644+
.start()
645+
.completed();
646+
});
628647
});

0 commit comments

Comments
 (0)