Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
test(node): Automatically run all node-integration tests with orchestrion#21911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| 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 |
|---|---|---|
| @@ -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 | ||
| @@ -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 | ||
| @@ -137,7 +140,11 @@ describe('mysql auto instrumentation', () => { | ||
| .completed(); | ||
| }); | ||
| }, | ||
| { failsOnEsm }, | ||
| { | ||
| failsOnEsm, | ||
| // We handle injection ourselves here | ||
| injectOrchestrion: false, | ||
| }, | ||
| ); | ||
| } | ||
| @@ -174,7 +181,11 @@ describe('mysql auto instrumentation', () => { | ||
| .completed(); | ||
| }); | ||
| }, | ||
| { failsOnEsm }, | ||
| { | ||
| failsOnEsm, | ||
| // We handle injection ourselves here | ||
| injectOrchestrion: false, | ||
| }, | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
| }); | ||
| } | ||
| @@ -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', | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.tsThere was a problem hiding this comment.
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 😅