Skip to content

Commit 48d16a8

Browse files
JPeer264claude
andcommitted
fixup! test(bun): Run the auto-instrumentation suites with bundled scenarios
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent afe0e26 commit 48d16a8

9 files changed

Lines changed: 117 additions & 69 deletions

File tree

‎dev-packages/bun-integration-tests/node-suites/bun-build.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const result = await Bun.build({
2121
outdir: join(BUILD_ROOT, relative(NODE_SUITES_ROOT, dirname(entry))),
2222
sourcemap: 'linked',
2323
// The instrument file is preloaded unbundled, so the bundle must share its `@sentry/*` packages.
24-
external: ['@sentry/*', '@sentry-internal/*'],
24+
// knex requires the drivers of all its dialects, and the ones that are not installed must stay
25+
// external so the bundle still builds.
26+
external: ['@sentry/*', '@sentry-internal/*', 'better-sqlite3', 'oracledb', 'pg-query-stream', 'sqlite3'],
2527
plugins: [sentryBunPlugin()],
2628
});
2729

‎dev-packages/node-integration-tests/suites/tracing/ioredis-dc/test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
22
import type { SerializedStreamedSpanContainer } from '@sentry/core';
33
import { afterAll, describe, expect } from 'vitest';
4+
import { EXPECTED_SDK_NAME } from '../../../utils';
45
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
56

67
describeWithDockerCompose(
@@ -135,7 +136,7 @@ describeWithDockerCompose(
135136
'sentry.op': op,
136137
'sentry.origin': ORIGIN,
137138
'sentry.release': '1.0',
138-
'sentry.sdk.name': 'sentry.javascript.node',
139+
'sentry.sdk.name': EXPECTED_SDK_NAME,
139140
'sentry.segment.name': SEGMENT_NAME,
140141
'server.address': HOST,
141142
'server.port': PORT,

‎dev-packages/node-integration-tests/suites/tracing/postgres-streamed/test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
22
import type { SerializedStreamedSpanContainer } from '@sentry/core';
33
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
44
import { afterAll, describe, expect } from 'vitest';
5-
import { conditionalTest, RUNTIME } from '../../../utils';
5+
import { conditionalTest, EXPECTED_SDK_NAME, RUNTIME } from '../../../utils';
66
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
77

88
// Query-span origin depends on which instrumentation is active. Blocks driving the SDK's default
@@ -58,7 +58,7 @@ const COMMON_DB_ATTRIBUTES = {
5858
},
5959
'sentry.sdk.name': {
6060
type: 'string',
61-
value: 'sentry.javascript.node',
61+
value: EXPECTED_SDK_NAME,
6262
},
6363
'sentry.sdk.version': {
6464
type: 'string',
@@ -228,7 +228,8 @@ describeWithDockerCompose('postgres auto instrumentation (streamed)', { workingD
228228
});
229229

230230
// Deno: with a module load hook installed, Deno compiles a native addon (`libpq`) as JavaScript.
231-
(RUNTIME === 'deno' ? describe.skip : conditionalTest({ max: 25 }))('pg-native', () => {
231+
// Bun: the `libpq` addon needs the Node symbol `node::EmitAsyncInit`, which Bun does not provide.
232+
(RUNTIME !== 'node' ? describe.skip : conditionalTest({ max: 25 }))('pg-native', () => {
232233
createEsmAndCjsTests(
233234
__dirname,
234235
'scenario-native.mjs',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
277277
});
278278

279279
// Deno: with a module load hook installed, Deno compiles a native addon (`libpq`) as JavaScript.
280-
(RUNTIME === 'deno' ? describe.skip : conditionalTest({ max: 25 }))('pg-native', () => {
280+
// Bun: the `libpq` addon needs the Node symbol `node::EmitAsyncInit`, which Bun does not provide.
281+
(RUNTIME !== 'node' ? describe.skip : conditionalTest({ max: 25 }))('pg-native', () => {
281282
const EXPECTED_TRANSACTION = {
282283
transaction: 'Test Transaction',
283284
spans: expect.arrayContaining([

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

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { SerializedStreamedSpanContainer } from '@sentry/core';
22
import { afterAll, describe, expect } from 'vitest';
3+
import { RUNTIME } from '../../../utils';
34
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
45

6+
// On Bun, `postgres` resolves to its ESM build through the `bun` export condition, so
7+
// `require('postgres')` returns the module namespace instead of the `postgres` function.
8+
59
/**
610
* Streamed span attributes are `{ value, type }` objects, unlike transaction span `data`,
711
* which stores values directly.
@@ -168,30 +172,34 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin
168172
},
169173
};
170174

171-
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => {
172-
test('should auto-instrument `postgres` package', { timeout: 90_000 }, async () => {
173-
await createTestRunner()
174-
.expect({
175-
span: container => {
176-
expect(container).toMatchObject(EXPECTED_SPANS);
175+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
176+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
177+
'should auto-instrument `postgres` package',
178+
{ timeout: 90_000 },
179+
async () => {
180+
await createTestRunner()
181+
.expect({
182+
span: container => {
183+
expect(container).toMatchObject(EXPECTED_SPANS);
177184

178-
// The assertions above only cover the queries the scenario issues itself. postgres.js
179-
// also runs internal ones (e.g. the `pg_catalog` type lookup), so guard the invariant
180-
// across every query span: the name is the summary, never the statement.
181-
const dbSpans = getDbSpans(container);
182-
expect(dbSpans.length).toBeGreaterThan(0);
183-
for (const span of dbSpans) {
184-
expect(span.name).toBe(span.attributes['db.query.summary']?.value);
185-
}
186-
},
187-
})
188-
.expect({ event: EXPECTED_ERROR_EVENT })
189-
// The error event is captured via an unhandled rejection processed on a later tick than
190-
// the spans, so the two envelopes can reach the transport in either order.
191-
.unordered()
192-
.start()
193-
.completed();
194-
});
185+
// The assertions above only cover the queries the scenario issues itself. postgres.js
186+
// also runs internal ones (e.g. the `pg_catalog` type lookup), so guard the invariant
187+
// across every query span: the name is the summary, never the statement.
188+
const dbSpans = getDbSpans(container);
189+
expect(dbSpans.length).toBeGreaterThan(0);
190+
for (const span of dbSpans) {
191+
expect(span.name).toBe(span.attributes['db.query.summary']?.value);
192+
}
193+
},
194+
})
195+
.expect({ event: EXPECTED_ERROR_EVENT })
196+
// The error event is captured via an unhandled rejection processed on a later tick than
197+
// the spans, so the two envelopes can reach the transport in either order.
198+
.unordered()
199+
.start()
200+
.completed();
201+
},
202+
);
195203
});
196204
});
197205

@@ -228,10 +236,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin
228236
__dirname,
229237
'scenario-requestHook.mjs',
230238
'instrument-requestHook.mjs',
231-
(createTestRunner, test) => {
232-
test('should call requestHook when provided', { timeout: 90_000 }, async () => {
233-
await createTestRunner().expect({ span: EXPECTED_SPANS }).start().completed();
234-
});
239+
(createTestRunner, test, mode) => {
240+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
241+
'should call requestHook when provided',
242+
{ timeout: 90_000 },
243+
async () => {
244+
await createTestRunner().expect({ span: EXPECTED_SPANS }).start().completed();
245+
},
246+
);
235247
},
236248
);
237249
});
@@ -262,10 +274,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin
262274
]),
263275
};
264276

265-
createEsmAndCjsTests(__dirname, 'scenario-url.mjs', 'instrument.mjs', (createTestRunner, test) => {
266-
test('should instrument postgres package with URL initialization', { timeout: 90_000 }, async () => {
267-
await createTestRunner().ignore('event').expect({ span: EXPECTED_SPANS }).start().completed();
268-
});
277+
createEsmAndCjsTests(__dirname, 'scenario-url.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
278+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
279+
'should instrument postgres package with URL initialization',
280+
{ timeout: 90_000 },
281+
async () => {
282+
await createTestRunner().ignore('event').expect({ span: EXPECTED_SPANS }).start().completed();
283+
},
284+
);
269285
});
270286
});
271287

@@ -296,10 +312,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin
296312
]),
297313
};
298314

299-
createEsmAndCjsTests(__dirname, 'scenario-unsafe.mjs', 'instrument.mjs', (createTestRunner, test) => {
300-
test('should instrument sql.unsafe() queries', { timeout: 90_000 }, async () => {
301-
await createTestRunner().ignore('event').expect({ span: EXPECTED_SPANS }).start().completed();
302-
});
315+
createEsmAndCjsTests(__dirname, 'scenario-unsafe.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
316+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
317+
'should instrument sql.unsafe() queries',
318+
{ timeout: 90_000 },
319+
async () => {
320+
await createTestRunner().ignore('event').expect({ span: EXPECTED_SPANS }).start().completed();
321+
},
322+
);
303323
});
304324
});
305325
});

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

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { afterAll, describe, expect } from 'vitest';
2+
import { RUNTIME } from '../../../utils';
23
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
34

5+
// On Bun, `postgres` resolves to its ESM build through the `bun` export condition, so
6+
// `require('postgres')` returns the module namespace instead of the `postgres` function.
7+
48
describeWithDockerCompose('postgresjs auto instrumentation', { workingDirectory: [__dirname] }, () => {
59
afterAll(() => {
610
cleanupChildProcesses();
@@ -223,17 +227,21 @@ describeWithDockerCompose('postgresjs auto instrumentation', { workingDirectory:
223227
},
224228
};
225229

226-
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => {
227-
test('should auto-instrument `postgres` package', { timeout: 60_000 }, async () => {
228-
await createTestRunner()
229-
.expect({ transaction: EXPECTED_TRANSACTION })
230-
.expect({ event: EXPECTED_ERROR_EVENT })
231-
// The error event is captured via an unhandled rejection processed on a later tick than
232-
// the transaction, so the two envelopes can reach the transport in either order.
233-
.unordered()
234-
.start()
235-
.completed();
236-
});
230+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
231+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
232+
'should auto-instrument `postgres` package',
233+
{ timeout: 60_000 },
234+
async () => {
235+
await createTestRunner()
236+
.expect({ transaction: EXPECTED_TRANSACTION })
237+
.expect({ event: EXPECTED_ERROR_EVENT })
238+
// The error event is captured via an unhandled rejection processed on a later tick than
239+
// the transaction, so the two envelopes can reach the transport in either order.
240+
.unordered()
241+
.start()
242+
.completed();
243+
},
244+
);
237245
});
238246
});
239247

@@ -326,10 +334,14 @@ describeWithDockerCompose('postgresjs auto instrumentation', { workingDirectory:
326334
__dirname,
327335
'scenario-requestHook.mjs',
328336
'instrument-requestHook.mjs',
329-
(createTestRunner, test) => {
330-
test('should call requestHook when provided', { timeout: 60_000 }, async () => {
331-
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
332-
});
337+
(createTestRunner, test, mode) => {
338+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
339+
'should call requestHook when provided',
340+
{ timeout: 60_000 },
341+
async () => {
342+
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
343+
},
344+
);
333345
},
334346
);
335347
});
@@ -407,10 +419,14 @@ describeWithDockerCompose('postgresjs auto instrumentation', { workingDirectory:
407419
]),
408420
};
409421

410-
createEsmAndCjsTests(__dirname, 'scenario-url.mjs', 'instrument.mjs', (createTestRunner, test) => {
411-
test('should instrument postgres package with URL initialization', { timeout: 90_000 }, async () => {
412-
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
413-
});
422+
createEsmAndCjsTests(__dirname, 'scenario-url.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
423+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
424+
'should instrument postgres package with URL initialization',
425+
{ timeout: 90_000 },
426+
async () => {
427+
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
428+
},
429+
);
414430
});
415431
});
416432

@@ -486,12 +502,16 @@ describeWithDockerCompose('postgresjs auto instrumentation', { workingDirectory:
486502
]),
487503
};
488504

489-
createEsmAndCjsTests(__dirname, 'scenario-unsafe.mjs', 'instrument.mjs', (createTestRunner, test) => {
490-
test('should instrument sql.unsafe() queries', { timeout: 90_000 }, async () => {
491-
// The last query fails on purpose, and its unhandled rejection also sends an error event, which can
492-
// arrive before the transaction.
493-
await createTestRunner().ignore('event').expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
494-
});
505+
createEsmAndCjsTests(__dirname, 'scenario-unsafe.mjs', 'instrument.mjs', (createTestRunner, test, mode) => {
506+
test.skipIf(RUNTIME === 'bun' && mode === 'cjs')(
507+
'should instrument sql.unsafe() queries',
508+
{ timeout: 90_000 },
509+
async () => {
510+
// The last query fails on purpose, and its unhandled rejection also sends an error event, which can
511+
// arrive before the transaction.
512+
await createTestRunner().ignore('event').expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
513+
},
514+
);
495515
});
496516
});
497517
});

‎dev-packages/node-integration-tests/suites/tracing/redis-cache/test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
22
import type { SerializedStreamedSpanContainer } from '@sentry/core';
33
import { afterAll, describe, expect } from 'vitest';
4+
import { EXPECTED_SDK_NAME } from '../../../utils';
45
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
56

67
describeWithDockerCompose('redis cache auto instrumentation', { workingDirectory: [__dirname] }, () => {
@@ -705,7 +706,7 @@ describeWithDockerCompose('redis cache auto instrumentation', { workingDirectory
705706
'sentry.kind': 'client',
706707
'sentry.origin': redisOrigin,
707708
'sentry.release': '1.0',
708-
'sentry.sdk.name': 'sentry.javascript.node',
709+
'sentry.sdk.name': EXPECTED_SDK_NAME,
709710
'sentry.segment.name': segmentName,
710711
[SENTRY_TRACE_LIFECYCLE]: 'stream',
711712
}),

‎dev-packages/node-integration-tests/suites/tracing/redis-dc/test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
22
import type { SerializedStreamedSpanContainer } from '@sentry/core';
33
import { afterAll, describe, expect } from 'vitest';
4+
import { EXPECTED_SDK_NAME } from '../../../utils';
45
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
56

67
describeWithDockerCompose(
@@ -183,7 +184,7 @@ describeWithDockerCompose(
183184
'sentry.op': op,
184185
'sentry.origin': ORIGIN,
185186
'sentry.release': '1.0',
186-
'sentry.sdk.name': 'sentry.javascript.node',
187+
'sentry.sdk.name': EXPECTED_SDK_NAME,
187188
'sentry.segment.name': SEGMENT_NAME,
188189
'server.address': HOST,
189190
'server.port': PORT,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SENTRY_TRACE_LIFECYCLE } from '@sentry/conventions/attributes';
22
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, type SerializedStreamedSpanContainer } from '@sentry/core';
33
import { afterAll, describe, expect } from 'vitest';
4+
import { EXPECTED_SDK_NAME } from '../../../utils';
45
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
56

67
describeWithDockerCompose('redis auto instrumentation', { workingDirectory: [__dirname] }, () => {
@@ -85,7 +86,7 @@ describeWithDockerCompose('redis auto instrumentation', { workingDirectory: [__d
8586
'sentry.op': { type: 'string', value: redisSpanOp },
8687
'sentry.origin': { type: 'string', value: origin },
8788
'sentry.release': { type: 'string', value: '1.0' },
88-
'sentry.sdk.name': { type: 'string', value: 'sentry.javascript.node' },
89+
'sentry.sdk.name': { type: 'string', value: EXPECTED_SDK_NAME },
8990
'sentry.sdk.version': { type: 'string', value: expect.any(String) },
9091
'sentry.segment.id': { type: 'string', value: expect.stringMatching(/^[\da-f]{16}$/) },
9192
'sentry.segment.name': { type: 'string', value: 'Test Span' },

0 commit comments

Comments
 (0)