Skip to content
Draft
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
482 changes: 482 additions & 0 deletions ORCHESTRIONJS_PLAN.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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
@@ -0,0 +1,14 @@
import '@sentry/node/orchestrion';
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
_experimentalUseOrchestrion: true,
debug: true,
});

Sentry._experimentalSetupOrchestrion(client);
35 changes: 18 additions & 17 deletions dev-packages/node-integration-tests/suites/tracing/mysql/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,46 @@ describe('mysql auto instrumentation', () => {
]),
};

describe('with connection.connect()', () => {
describe.each([
['opentelemetry-based', 'instrument.mjs'],
['orchestrion-based', 'instrument-orchestrion.mjs'],
])('%s', (instrumentation, instrumentFile) => {
// esm is not supported for the otel instrumentation
const failsOnEsm = instrumentation === 'opentelemetry-based';
createEsmAndCjsTests(
__dirname,
'scenario-withConnect.mjs',
'instrument.mjs',
(createTestRunner, test) => {
instrumentFile,
(createRunner, test) => {
test('should auto-instrument `mysql` package when using connection.connect()', async () => {
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});
},
{ failsOnEsm: true },
{ failsOnEsm },
);
});

describe('query without callback', () => {
createEsmAndCjsTests(
__dirname,
'scenario-withoutCallback.mjs',
'instrument.mjs',
(createTestRunner, test) => {
instrumentFile,
(createRunner, test) => {
test('should auto-instrument `mysql` package when using query without callback', async () => {
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});
},
{ failsOnEsm: true },
{ failsOnEsm },
);
});

describe('without connection.connect()', () => {
createEsmAndCjsTests(
__dirname,
'scenario-withoutConnect.mjs',
'instrument.mjs',
(createTestRunner, test) => {
instrumentFile,
(createRunner, test) => {
test('should auto-instrument `mysql` package without connection.connect()', async () => {
await createTestRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});
},
{ failsOnEsm: true },
{ failsOnEsm },
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('mysql2 auto instrumentation', () => {
};

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => {
test('should auto-instrument `mysql` package without connection.connect()', { timeout: 75_000 }, async () => {
test('should auto-instrument `mysql2` package without connection.connect()', { timeout: 75_000 }, async () => {
await createTestRunner()
.withDockerCompose({ workingDirectory: [__dirname] })
.expect({ transaction: EXPECTED_TRANSACTION })
Expand Down
53 changes: 51 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@
"require": {
"default": "./build/cjs/preload.js"
}
},
"./orchestrion": {
"import": {
"default": "./build/orchestrion/import-hook.mjs"
},
"require": {
"default": "./build/orchestrion/require-hook.cjs"
}
},
"./orchestrion/config": {
"import": {
"types": "./build/types/orchestrion/config.d.ts",
"default": "./build/esm/orchestrion/config.js"
},
"require": {
"types": "./build/types/orchestrion/config.d.ts",
"default": "./build/cjs/orchestrion/config.js"
}
},
"./orchestrion/vite": {
"import": {
"types": "./build/types/orchestrion/bundler/vite.d.ts",
"default": "./build/esm/orchestrion/bundler/vite.js"
}
}
},
"typesVersions": {
Expand All @@ -65,6 +89,9 @@
"access": "public"
},
"dependencies": {
"@apm-js-collab/code-transformer": "^0.13.0",
"@apm-js-collab/code-transformer-bundler-plugins": "^0.1.0",
"@apm-js-collab/tracing-hooks": "^0.8.0",
"@opentelemetry/api": "^1.9.1",
"@opentelemetry/core": "^2.6.1",
"@opentelemetry/instrumentation": "^0.214.0",
Expand All @@ -90,7 +117,16 @@
"import-in-the-middle": "^3.0.0"
},
"devDependencies": {
"@types/node": "^18.19.1"
"@types/node": "^18.19.1",
"vite": "^5.0.0"
},
"peerDependencies": {
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"vite": {
"optional": true
}
},
"scripts": {
"build": "run-p build:transpile build:types",
Expand All @@ -116,5 +152,18 @@
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
"sideEffects": false,
"nx": {
"targets": {
"build:transpile": {
"outputs": [
"{projectRoot}/build/esm",
"{projectRoot}/build/cjs",
"{projectRoot}/build/npm/esm",
"{projectRoot}/build/npm/cjs",
"{projectRoot}/build/orchestrion"
]
}
}
}
}
34 changes: 33 additions & 1 deletion packages/node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
import { defineConfig } from 'rollup';
import { makeBaseNPMConfig, makeNPMConfigVariants, makeOtelLoaders } from '@sentry-internal/rollup-utils';

// EXPERIMENTAL — orchestrion.js runtime hooks. Each one is a tiny hand-written
// `.mjs`/`.cjs` shim that the user references via `node --import` or
// `node --require`. We pass them through rollup only to copy them into `build/`
// at the path the package.json `exports` map expects; `external: /.*/` keeps
// every import (e.g. `@sentry/node/orchestrion/config`) as a runtime resolution
// against the installed package.
const orchestrionRuntimeHooks = [
defineConfig({
input: 'src/orchestrion/runtime/import-hook.mjs',
external: /.*/,
output: { format: 'esm', file: 'build/orchestrion/import-hook.mjs' },
}),
defineConfig({
input: 'src/orchestrion/runtime/require-hook.cjs',
external: /.*/,
output: { format: 'cjs', file: 'build/orchestrion/require-hook.cjs', strict: false },
}),
];

export default [
...makeOtelLoaders('./build', 'otel'),
...orchestrionRuntimeHooks,
...makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.ts', 'src/init.ts', 'src/preload.ts'],
// `src/orchestrion/config.ts` and `src/orchestrion/bundler/vite.ts` are
// loaded via dedicated subpath exports (`@sentry/node/orchestrion/config`,
// `@sentry/node/orchestrion/vite`) — neither is reachable from `src/index.ts`,
// so we list them as separate entrypoints to guarantee they end up in
// build/esm and build/cjs.
entrypoints: [
'src/index.ts',
'src/init.ts',
'src/preload.ts',
'src/orchestrion/config.ts',
'src/orchestrion/bundler/vite.ts',
],
packageSpecificConfig: {
external: [/^@sentry\/opentelemetry/],
output: {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {
getDefaultIntegrationsWithoutPerformance,
initWithoutDefaultIntegrations,
} from './sdk';
export { _experimentalSetupOrchestrion, mysqlChannelIntegration } from './orchestrion';
export { initOpenTelemetry, preloadOpenTelemetry } from './sdk/initOtel';
export { getAutoPerformanceIntegrations } from './integrations/tracing';

Expand Down
Loading
Loading