|
1 | 1 | import type { SerializedStreamedSpanContainer } from '@sentry/core'; |
2 | 2 | import { afterAll, describe, expect } from 'vitest'; |
| 3 | +import { RUNTIME } from '../../../utils'; |
3 | 4 | import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner'; |
4 | 5 |
|
| 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 | + |
5 | 9 | /** |
6 | 10 | * Streamed span attributes are `{ value, type }` objects, unlike transaction span `data`, |
7 | 11 | * which stores values directly. |
@@ -168,30 +172,34 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin |
168 | 172 | }, |
169 | 173 | }; |
170 | 174 |
|
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); |
177 | 184 |
|
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 | + ); |
195 | 203 | }); |
196 | 204 | }); |
197 | 205 |
|
@@ -228,10 +236,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin |
228 | 236 | __dirname, |
229 | 237 | 'scenario-requestHook.mjs', |
230 | 238 | '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 | + ); |
235 | 247 | }, |
236 | 248 | ); |
237 | 249 | }); |
@@ -262,10 +274,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin |
262 | 274 | ]), |
263 | 275 | }; |
264 | 276 |
|
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 | + ); |
269 | 285 | }); |
270 | 286 | }); |
271 | 287 |
|
@@ -296,10 +312,14 @@ describeWithDockerCompose('postgresjs auto instrumentation (streamed)', { workin |
296 | 312 | ]), |
297 | 313 | }; |
298 | 314 |
|
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 | + ); |
303 | 323 | }); |
304 | 324 | }); |
305 | 325 | }); |
0 commit comments