Skip to content
Merged
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
17 changes: 15 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ jobs:

job_node_integration_tests:
name:
Node (${{ matrix.node }})${{ (matrix.typescript && format(' (TS {0})', matrix.typescript)) || '' }} Integration
Tests
Node (${{ matrix.node }})${{ (matrix.typescript && format(' (TS {0})', matrix.typescript)) || '' }}${{
(matrix.use_orchestrion && format(' (Orchestrion)', matrix.use_orchestrion)) || '' }} Integration Tests
needs: [job_get_metadata, job_build]
if: needs.job_build.outputs.changed_node_integration == 'true' || github.event_name != 'pull_request'
runs-on: ubuntu-24.04
Expand All @@ -785,10 +785,21 @@ jobs:
node: [18, 20, 22, 24, 26]
typescript:
- false
use_orchestrion:
- false
include:
# Only check typescript for latest version (to streamline CI)
- node: 24
typescript: '3.8'
# No need to test orchestrion for v18
- node: 20
use_orchestrion: 'true'
- node: 22
use_orchestrion: 'true'
- node: 24
use_orchestrion: 'true'
- node: 26
use_orchestrion: 'true'
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v6
Expand All @@ -811,6 +822,8 @@ jobs:
- name: Run integration tests
working-directory: dev-packages/node-integration-tests
run: yarn test
env:
INJECT_ORCHESTRION: ${{ matrix.use_orchestrion }}

job_node_v18_compat:
name: Node v18.0.0 Compatibility Check
Expand Down
1 change: 1 addition & 0 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lint:fix": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --fix --type-aware",
"type-check": "tsc",
"test": "vitest run",
"test:orchestrion": "INJECT_ORCHESTRION=true yarn test",
"test:watch": "yarn test --watch"
},
"dependencies": {
Expand Down
5 changes: 5 additions & 0 deletions dev-packages/node-integration-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ export function getPortAppIsRunningOn(app: Express): number | undefined {
// @ts-expect-error It's not defined in the types but we'd like to read it.
return app.port;
}

/** Returns true if orchestrion is enabled in env vars. */
export function isOrchestrionEnabled(): boolean {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: This can be removed, seems to be a duplicate from the utils/index.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed for usage in scenario usage where you need to do e.g. import { isOrchestrionEnabled } from '@sentry-internal/node-integration-tests' while the one in utils is for in-test usage. at least this is our current differentiation, not 100% sure if we need this 😅

return process.env.INJECT_ORCHESTRION === 'true' || process.env.INJECT_ORCHESTRION === '1';
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,103 +1,59 @@
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
import { createCjsTests } from '../../../utils/runner/createEsmAndCjsTests';
import { isOrchestrionEnabled } from '../../../utils';

describe('lru-memoizer', () => {
afterAll(() => {
cleanupChildProcesses();
});

// Each case maps to the OpenTelemetry default and the diagnostics-channel opt-in
// variants, mirroring the mysql suite. `flags` are extra Node CLI flags; the
// instrument file is always loaded via `--import` (esm) / `--require` (cjs).
//
// lru-memoizer creates no spans, so there's no `sentry.origin` to
// assert: the opt-in cases prove the channel ran because the opt-in removes the
// OTel integration via `replacedOtelIntegrationNames`.
const CASES = [
// OpenTelemetry default — no opt-in, no injection. (OTel does not support ESM.)
{ label: 'opentelemetry (default)', instrument: 'instrument.mjs', flags: [], failsOnEsm: true },
// Opt-in via init only. `Sentry.init()` injects the channels synchronously.
{
label: 'diagnostics-channel (init opt-in)',
instrument: 'instrument-orchestrion.mjs',
flags: [],
failsOnEsm: false,
},
// Opt-in and rely on `node --import @sentry/node/import`.
{
label: 'diagnostics-channel (--import @sentry/node/import opt-in)',
instrument: 'instrument-orchestrion.mjs',
flags: ['--import', '@sentry/node/import'],
failsOnEsm: false,
},
// Without opt-in: channels are injected unconditionally but not subscribed to,
// so the OTel instrumentation does the work — proves injecting the channels has
// no downside. (OTel does not support ESM.)
{
label: 'opentelemetry (channels injected, no opt-in)',
instrument: 'instrument.mjs',
flags: ['--import', '@sentry/node/import'],
failsOnEsm: true,
},
] as const;

for (const { label, instrument, flags, failsOnEsm } of CASES) {
describe(label, () => {
createEsmAndCjsTests(
__dirname,
'scenario.mjs',
instrument,
(createTestRunner, test) => {
test('keeps outer context inside the memoized inner functions', async () => {
await createTestRunner()
.withFlags(...flags)
.expect({
transaction: {
transaction: '<unknown>',
contexts: {
trace: expect.objectContaining({
op: 'run',
data: expect.objectContaining({
'sentry.op': 'run',
'sentry.origin': 'manual',
'memoized.context_preserved': true,
}),
}),
},
},
})
.start()
.completed();
});
},
{ failsOnEsm },
);

// CJS-only: the parallel scenario is flaky in ESM (see #21729).
createCjsTests(__dirname, 'scenario-parallel.mjs', instrument, (createTestRunner, test) => {
test('keeps each span context across parallel memoized requests', async () => {
// Each parallel request emits a transaction whose callback must have run in its own context.
// Two identical expectations keep this order-independent.
const expectation = {
createEsmAndCjsTests(
__dirname,
'scenario.mjs',
'instrument.mjs',
(createTestRunner, test) => {
test('keeps outer context inside the memoized inner functions', async () => {
await createTestRunner()
.expect({
transaction: {
transaction: '<unknown>',
contexts: {
trace: expect.objectContaining({
op: expect.stringMatching(/^(first|second)$/),
data: expect.objectContaining({ 'memoized.context_preserved': true }),
op: 'run',
data: expect.objectContaining({
'sentry.op': 'run',
'sentry.origin': 'manual',
'memoized.context_preserved': true,
}),
}),
},
},
};

await createTestRunner()
.withFlags(...flags)
.expect(expectation)
.expect(expectation)
.start()
.completed();
});
})
.start()
.completed();
});
},
{ failsOnEsm: !isOrchestrionEnabled() },
);

// CJS-only: the parallel scenario is flaky in ESM (see #21729).
createCjsTests(__dirname, 'scenario-parallel.mjs', 'instrument.mjs', (createTestRunner, test) => {
test('keeps each span context across parallel memoized requests', async () => {
// Each parallel request emits a transaction whose callback must have run in its own context.
// Two identical expectations keep this order-independent.
const expectation = {
transaction: {
contexts: {
trace: expect.objectContaining({
op: expect.stringMatching(/^(first|second)$/),
data: expect.objectContaining({ 'memoized.context_preserved': true }),
}),
},
},
};

await createTestRunner().expect(expectation).expect(expectation).start().completed();
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cleanupChildProcesses, createCjsTests, createEsmAndCjsTests } from '../
import { startMysqlTestServer } from './mysql-test-server';
import type { SerializedStreamedSpanContainer } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
import { isOrchestrionEnabled } from '../../../utils';

describe('mysql auto instrumentation', () => {
// A minimal in-process MySQL server (on a random free port) so the client's
Expand Down Expand Up @@ -58,6 +59,8 @@ describe('mysql auto instrumentation', () => {
};
}

// Note: here specifically, we want to ignore the generic orchestrion testing define via INJECT_ORCHESTRION,
// but instead test various different ways to run orchestrion manually
const CHANNEL_ORIGIN = 'auto.db.orchestrion.mysql';

// Each case maps to one of the two documented use cases, in opt-in and
Expand Down Expand Up @@ -137,7 +140,11 @@ describe('mysql auto instrumentation', () => {
.completed();
});
},
{ failsOnEsm },
{
failsOnEsm,
// We handle injection ourselves here
injectOrchestrion: false,
},
);
}

Expand Down Expand Up @@ -174,7 +181,11 @@ describe('mysql auto instrumentation', () => {
.completed();
});
},
{ failsOnEsm },
{
failsOnEsm,
// We handle injection ourselves here
injectOrchestrion: false,
},
Comment thread
cursor[bot] marked this conversation as resolved.
);
});
}
Expand Down Expand Up @@ -225,7 +236,7 @@ describe('mysql auto instrumentation', () => {
},
'sentry.origin': {
type: 'string',
value: 'auto.db.otel.mysql',
value: isOrchestrionEnabled() ? 'auto.db.orchestrion.mysql' : 'auto.db.otel.mysql',
},
'sentry.release': {
type: 'string',
Expand Down
5 changes: 5 additions & 0 deletions dev-packages/node-integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ export function conditionalTest(allowedVersion: {
export const parseEnvelope = (body: string): Array<Record<string, unknown>> => {
return body.split('\n').map(e => JSON.parse(e));
};

/** Returns true if orchestrion is enabled in env vars. */
export function isOrchestrionEnabled(): boolean {
return process.env.INJECT_ORCHESTRION === 'true' || process.env.INJECT_ORCHESTRION === '1';
}
Loading
Loading