|
| 1 | +// Spawned by test.ts via `deno run`, in a fresh process so nothing else has |
| 2 | +// installed the AsyncLocalStorage context strategy. |
| 3 | +// |
| 4 | +// This builds a `DenoClient` DIRECTLY — `new DenoClient(...)` + `client.init()` |
| 5 | +// instead of calling `Sentry.init()`, then drives the mysql orchestrion channel |
| 6 | +// The mysql subscriber only binds once the ALS context strategy is installed |
| 7 | +// (it waits for the tracing-channel binding), so a nested db span here proves |
| 8 | +// `DenoClient.init()` installs that strategy on the direct-construction path. |
| 9 | +// Without it, the subscriber never binds and no span is produced. |
| 10 | +import { createStackParser, nodeStackLineParser } from '@sentry/core'; |
| 11 | +import { DenoClient, getCurrentScope, getDefaultIntegrations, startSpan } from '@sentry/deno'; |
| 12 | +import { tracingChannel } from 'node:diagnostics_channel'; |
| 13 | + |
| 14 | +let nested = false; |
| 15 | + |
| 16 | +const client = new DenoClient({ |
| 17 | + dsn: 'https://username@domain/123', |
| 18 | + tracesSampleRate: 1, |
| 19 | + integrations: getDefaultIntegrations({}), |
| 20 | + stackParser: createStackParser(nodeStackLineParser()), |
| 21 | + beforeSendTransaction(event) { |
| 22 | + const spans = event.spans ?? []; |
| 23 | + if (spans.some(s => s.op === 'db' && s.data?.['sentry.origin'] === 'auto.db.orchestrion.mysql')) { |
| 24 | + nested = true; |
| 25 | + } |
| 26 | + return null; |
| 27 | + }, |
| 28 | + transport: () => ({ send: () => Promise.resolve({}), flush: () => Promise.resolve(true) }), |
| 29 | +}); |
| 30 | + |
| 31 | +client.init(); |
| 32 | +getCurrentScope().setClient(client); |
| 33 | + |
| 34 | +const channel = tracingChannel('orchestrion:mysql:query'); |
| 35 | +const ctx = { |
| 36 | + arguments: ['SELECT 1 AS solution'], |
| 37 | + self: { config: { host: '127.0.0.1', port: 3306, database: 'mydb', user: 'root' } }, |
| 38 | +}; |
| 39 | + |
| 40 | +startSpan({ name: 'parent', op: 'test' }, () => { |
| 41 | + channel.start.runStores(ctx, () => { |
| 42 | + channel.end.publish(ctx); |
| 43 | + }); |
| 44 | + channel.asyncStart.runStores(ctx, () => { |
| 45 | + channel.asyncEnd.publish(ctx); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +await client.flush(2000); |
| 50 | + |
| 51 | +// eslint-disable-next-line no-console |
| 52 | +console.log(`SCENARIO nested=${nested}`); |
0 commit comments