Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,8 @@ module.exports = [
disablePlugins: ['@size-limit/esbuild'],
},
{
name: '@sentry/node (with Orchestrion)',
path: 'packages/node/build/esm/index.js',
import: createImport('init', '_experimentalSetupOrchestrion'),
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '173 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
name: '@sentry/node/orchestrion (ESM hook)',
path: ['node_modules/@apm-js-collab/tracing-hooks/hook.mjs', 'packages/node/build/orchestrion/import-hook.mjs'],
name: '@sentry/node/import (ESM hook with diagnostics-channel injection)',
path: ['node_modules/@apm-js-collab/tracing-hooks/hook.mjs', 'packages/node/build/import-hook.mjs'],
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '100 KB',
Expand Down
486 changes: 0 additions & 486 deletions ORCHESTRIONJS_PLAN.md

This file was deleted.

3 changes: 2 additions & 1 deletion dev-packages/bun-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"dependencies": {
"@sentry/bun": "10.58.0",
"@sentry/hono": "10.58.0",
"hono": "^4.12.25"
"hono": "^4.12.25",
"mysql": "^2.18.1"
},
"devDependencies": {
"@sentry-internal/test-utils": "10.58.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Builds the smoke scenario with the orchestrion `bun build` plugin and writes
// the bundle to a temp dir, printing the output path for test.ts to execute.
//
// A successful build proves `bun build` runs with the plugin; running the bundle
// (see test.ts) then proves the bundled `mysql` is actually instrumented.

// @ts-ignore -- subpath export resolved by Bun at runtime; the package
// tsconfig's node module resolution can't see `exports` subpaths.
import { sentryBunPlugin } from '@sentry/bun/plugin';
import { tmpdir } from 'os';
import { join } from 'path';

void (async () => {
const outdir = join(tmpdir(), `sentry-bun-orchestrion-${process.pid}-${Date.now()}`);
const result = await Bun.build({
entrypoints: [join(__dirname, 'scenario.ts')],
target: 'bun',
outdir,
plugins: [sentryBunPlugin()],
});

if (!result.success) {
// eslint-disable-next-line no-console
console.error('BUILD_FAILED', result.logs);
process.exit(1);
}

const output = result.outputs[0];
if (!output) {
// eslint-disable-next-line no-console
console.error('BUILD_FAILED no outputs');
process.exit(1);
}

// eslint-disable-next-line no-console
console.log(`BUILD_OK outfile=${output.path}`);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Bundled entry for the `bun build` smoke test.
//
// Once `Bun.build` (with the orchestrion plugin) has transformed `mysql`,
// calling `connection.query()` publishes to the `orchestrion:mysql:query`
// tracing channel.
//
// `start` fires synchronously on the call, so no live database is needed.
//
// We subscribe, run a query, and report which channel events fired
// (plus the detection marker the plugin's banner sets at boot).

import { tracingChannel } from 'node:diagnostics_channel';

// @ts-ignore -- `mysql` ships no type declarations; only needed at runtime.
import mysql from 'mysql';

interface QueryContext {
arguments?: unknown[];
}
interface Connection {
query(sql: string, cb: () => void): void;
destroy(): void;
}
interface MysqlModule {
createConnection(opts: { host: string; user: string }): Connection;
}

const events: string[] = [];
let statement = '';

tracingChannel('orchestrion:mysql:query').subscribe({
start(message: unknown) {
events.push('start');
const first = (message as QueryContext).arguments?.[0];
statement = typeof first === 'string' ? first : '';
},
end() {
events.push('end');
},
asyncStart() {},
asyncEnd() {
events.push('asyncEnd');
},
error() {},
});

const conn = (mysql as MysqlModule).createConnection({ host: '127.0.0.1', user: 'root' });
try {
conn.query('SELECT 1 AS solution', () => {});
} catch {
// No live server — `start` has already published synchronously by this point.
}
try {
conn.destroy();
} catch {
// ignore
}

const marker = (globalThis as { __SENTRY_ORCHESTRION__?: { runtime?: boolean; bundler?: boolean } })
.__SENTRY_ORCHESTRION__;

setTimeout(() => {
// eslint-disable-next-line no-console
console.log(`SCENARIO events=${events.join(',')} statement=${statement} marker=${JSON.stringify(marker ?? null)}`);
process.exit(0);
}, 200);
Comment thread
cursor[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { spawnSync } from 'child_process';
import { rmSync } from 'fs';
import { dirname, join } from 'path';
import { describe, expect, it } from 'vitest';

const dir = __dirname;

// Cap each `bun` subprocess. The test runs two of them sequentially, so its own
// timeout (see the `it(...)` below) must exceed `2 * SUBPROCESS_TIMEOUT_MS` —
// otherwise the suite's default `testTimeout` (20s) fails the test before these
// caps do, e.g. on a slow CI runner where the build+run legitimately takes >20s.
const SUBPROCESS_TIMEOUT_MS = 60_000;

function runBun(args: string[]): { stdout: string; stderr: string; status: number | null } {
const res = spawnSync('bun', args, { cwd: dir, encoding: 'utf8', timeout: SUBPROCESS_TIMEOUT_MS });
return { stdout: res.stdout ?? '', stderr: res.stderr ?? '', status: res.status };
}

// Bun orchestrion instrumentation is BUILD-ONLY (`@sentry/bun/plugin` is a
// `Bun.build` plugin; there is no `bun run` preload).
//
// A `bun run` runtime plugin cannot instrument CommonJS dependencies like
// `mysql`: any module returned by a runtime `onLoad` plugin in Bun loses its
// CommonJS named exports
//
// When https://github.com/oven-sh/bun/pull/31770 lands, we can revisit an
// auto-load plugin for `bun run`.
describe('orchestrion mysql instrumentation (Bun)', () => {
it('bundles `mysql` with the plugin, and the built output fires the mysql channel when run', () => {
// Build the scenario with the orchestrion `bun build` plugin.
const build = runBun(['run', join(dir, 'build.ts')]);
expect(build.status, `build failed:\nstderr:\n${build.stderr}\nstdout:\n${build.stdout}`).toBe(0);

const outfile = build.stdout.match(/BUILD_OK outfile=(.+)/)?.[1]?.trim();
expect(outfile, `no outfile in build output:\n${build.stdout}`).toBeTruthy();

try {
// Run the built bundle. The bundled (transformed) `mysql` should publish
// to the `orchestrion:mysql:query` channel when `connection.query()` is
// called, and the plugin's banner should set the `bundler` marker at boot.
const run = runBun(['run', outfile as string]);
expect(run.status, `run failed:\nstderr:\n${run.stderr}\nstdout:\n${run.stdout}`).toBe(0);
Comment thread
cursor[bot] marked this conversation as resolved.

const line = run.stdout.split('\n').find(l => l.startsWith('SCENARIO')) ?? '';
// channel `start` fired on `connection.query()`
expect(line).toContain('events=start');
// with the expected SQL
expect(line).toContain('statement=SELECT 1 AS solution');
// injected banner ran at bundle boot
expect(line).toContain('"bundler":true');
} finally {
if (outfile) {
rmSync(dirname(outfile), { recursive: true, force: true });
}
}
// Allow for both sequential `runBun` calls hitting their subprocess cap, so
// the `spawnSync` timeouts — not Vitest's 20s default — are the binding limit.
}, 2 * SUBPROCESS_TIMEOUT_MS);
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const NODE_EXPORTS_IGNORE = [
'preloadOpenTelemetry',
// Internal helper only needed within integrations (e.g. bunRuntimeMetricsIntegration)
'_INTERNAL_normalizeCollectionInterval',
// Experimental
'_experimentalSetupOrchestrion',
'mysqlChannelIntegration',
];

const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "commonjs",
"scripts": {
"start": "node --import @sentry/node/orchestrion ./src/app.js",
"start": "node --import @sentry/node/import ./src/app.js",
"test": "playwright test",
"clean": "npx rimraf node_modules pnpm-lock.yaml dist",
"test:build": "pnpm install",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const Sentry = require('@sentry/node');

const client = Sentry.init({
// The channels are injected by `node --import @sentry/node/import` (see the
// `start` script); opting in via this method makes the SDK subscribe to
// them instead of using the OTel instrumentation.
Sentry.experimentalUseDiagnosticsChannelInjection();

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
_experimentalUseOrchestrion: true,
});

Sentry._experimentalSetupOrchestrion(client);

const express = require('express');
const mysql = require('mysql');

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading