Skip to content

Commit aa5f78a

Browse files
mydeaclaude
andauthored
test(node): Migrate tracing integration tests to createEsmAndCjsTests (#20961)
## Summary Migrates the remaining integration-specific tracing tests under `dev-packages/node-integration-tests/suites/tracing/` to use the `createEsmAndCjsTests` helper, which auto-runs each scenario in both ESM and CJS mode from a single `.mjs` source. For each folder: - `scenario*.js` → `scenario*.mjs` (ESM imports) - Sentry.init extracted into a separate `instrument.mjs` - `test.ts` switched to `createEsmAndCjsTests(__dirname, scenarioPath, instrumentPath, callback, options?)` - `failsOnEsm: true` added only where CJS passed and ESM legitimately fails (i.e. instrumentation only patches the CJS module shape) ## Migrated folders | Folder | Notes | |---|---| | `lru-memoizer` | `failsOnEsm: true` — OTel `instrumentation-lru-memoizer` only patches the CJS function-shaped export. | | `mongodb` | mongodb v3 is CJS-only and has no named ESM exports — uses `import mongodb from 'mongodb'` + destructure. | | `mongoose` | Straight migration. | | `mysql2` | Straight migration (docker). | | `mysql` | `failsOnEsm: true` on all 3 scenarios — mysql v2 is CJS-only. Three scenarios kept (`withConnect`, `withoutCallback`, `withoutConnect`). | | `postgres` | 3 scenarios. `ignoreConnectSpans` reuses the default scenario but with a separate `instrument-ignoreConnect.mjs`. `pg-native` scenario migrated as-is (still relies on local `setupCommand: 'yarn'` to build the native bindings). | | `postgresjs` | Consolidated previously-parallel `.cjs`/`.mjs` scenarios into a single `.mjs` each. The `wait-for-postgres.js` helper is still required from the scenarios via `createRequire(import.meta.url)` (revert of the .mjs-helper conversion approach — see notes below). The error stacktrace assertion uses `expect.stringMatching(/postgres(\.cjs)?\.src:connection/)` so the same expectation matches both modes. | | `redis` | Straight migration (docker). | | `redis-cache` | 2 scenarios (`ioredis`, `redis-4`). Each scenario has its own `instrument-*.mjs` because they pass different `cachePrefixes` to `redisIntegration`. | | `redis-dc` | Uses `await import('redis-5')` inside `run()` to preserve the comment-documented ordering where the DC subscriber must be registered (via `Promise.resolve().then`) before node-redis eagerly creates its native TracingChannels on require/import. | | `tedious` | Migrated but kept `describe.skip` (the test was previously skipped as flaky in #15798). Manually verified both modes pass when un-skipped. | | `apollo-graphql` | 3 scenarios (query, mutation, error). Shared `apollo-server.mjs` helper copied into the tmp dir via `copyPaths: ['apollo-server.mjs']` and loaded with `await import('./apollo-server.mjs')` from each scenario. | | `apollo-graphql/useOperationNameForRootSpan` | 6 scenarios. Reuses the parent `apollo-server.mjs` via `../../apollo-server.mjs` (the scenarios run from `useOperationNameForRootSpan/tmp_xxx/`, so this resolves back to the apollo-graphql folder). Scenarios use `Sentry.getClient().tracer` instead of capturing the client returned by `Sentry.init` (since init now lives in `instrument.mjs`). | ## Out of scope The following folders under `tracing/` are still using `createRunner` directly — they are not integrations for a specific package but general tracing-behavior tests, so they're intentionally left alone: - `meta-tags*`, `meta-tags-twp*` - `sample-rate-propagation/*`, `sample-rand-propagation` - `tracePropagationTargets/*` - `traceid-recycling*` - `dsc-txn-name-update` - `http-client-spans/*` - `maxSpans`, `envelope-header/*`, `linking` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fb23878 commit aa5f78a

63 files changed

Lines changed: 898 additions & 1690 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/apollo-server.js renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/apollo-server.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { ApolloServer } = require('@apollo/server');
2-
const gql = require('graphql-tag');
3-
const Sentry = require('@sentry/node');
1+
import { ApolloServer } from '@apollo/server';
2+
import * as Sentry from '@sentry/node';
3+
import gql from 'graphql-tag';
44

5-
module.exports = () => {
5+
export function createApolloServer() {
66
return Sentry.startSpan({ name: 'Test Server Start' }, () => {
77
return new ApolloServer({
88
typeDefs: gql`
@@ -32,4 +32,4 @@ module.exports = () => {
3232
introspection: false,
3333
});
3434
});
35-
};
35+
}

dev-packages/node-integration-tests/suites/tracing/postgresjs/instrument.cjs renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/instrument.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Sentry = require('@sentry/node');
2-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
55
dsn: 'https://public@dsn.ingest.sentry.io/1337',

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-error.js renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-error.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
const Sentry = require('@sentry/node');
2-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3-
4-
Sentry.init({
5-
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6-
release: '1.0',
7-
tracesSampleRate: 1.0,
8-
transport: loggingTransport,
9-
});
1+
import * as Sentry from '@sentry/node';
2+
import gql from 'graphql-tag';
103

114
async function run() {
12-
const gql = require('graphql-tag');
13-
const server = require('./apollo-server')();
5+
const { createApolloServer } = await import('./apollo-server.mjs');
6+
const server = createApolloServer();
147

158
await Sentry.startSpan(
169
{

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-mutation.js renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-mutation.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
const Sentry = require('@sentry/node');
2-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3-
4-
Sentry.init({
5-
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6-
release: '1.0',
7-
tracesSampleRate: 1.0,
8-
transport: loggingTransport,
9-
});
1+
import * as Sentry from '@sentry/node';
2+
import gql from 'graphql-tag';
103

114
async function run() {
12-
const gql = require('graphql-tag');
13-
const server = require('./apollo-server')();
5+
const { createApolloServer } = await import('./apollo-server.mjs');
6+
const server = createApolloServer();
147

158
await Sentry.startSpan(
169
{

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-query.js renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-query.mjs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
const Sentry = require('@sentry/node');
2-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3-
4-
Sentry.init({
5-
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6-
release: '1.0',
7-
tracesSampleRate: 1.0,
8-
transport: loggingTransport,
9-
});
1+
import * as Sentry from '@sentry/node';
102

113
async function run() {
12-
const server = require('./apollo-server')();
4+
const { createApolloServer } = await import('./apollo-server.mjs');
5+
const server = createApolloServer();
136

147
await Sentry.startSpan(
158
{

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/test.ts

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { describe, expect, test } from 'vitest';
2-
import { createRunner } from '../../../utils/runner';
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

44
// Server start transaction (Apollo Server v5 no longer runs introspection query on start)
55
const EXPECTED_START_SERVER_TRANSACTION = {
66
transaction: 'Test Server Start',
77
};
88

99
describe('GraphQL/Apollo Tests', () => {
10-
test('should instrument GraphQL queries used from Apollo Server.', async () => {
10+
afterAll(() => {
11+
cleanupChildProcesses();
12+
});
13+
14+
describe('query', () => {
1115
const EXPECTED_TRANSACTION = {
1216
transaction: 'Test Transaction (query)',
1317
spans: expect.arrayContaining([
@@ -24,14 +28,24 @@ describe('GraphQL/Apollo Tests', () => {
2428
]),
2529
};
2630

27-
await createRunner(__dirname, 'scenario-query.js')
28-
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
29-
.expect({ transaction: EXPECTED_TRANSACTION })
30-
.start()
31-
.completed();
31+
createEsmAndCjsTests(
32+
__dirname,
33+
'scenario-query.mjs',
34+
'instrument.mjs',
35+
(createTestRunner, test) => {
36+
test('should instrument GraphQL queries used from Apollo Server.', async () => {
37+
await createTestRunner()
38+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
39+
.expect({ transaction: EXPECTED_TRANSACTION })
40+
.start()
41+
.completed();
42+
});
43+
},
44+
{ copyPaths: ['apollo-server.mjs'] },
45+
);
3246
});
3347

34-
test('should instrument GraphQL mutations used from Apollo Server.', async () => {
48+
describe('mutation', () => {
3549
const EXPECTED_TRANSACTION = {
3650
transaction: 'Test Transaction (mutation Mutation)',
3751
spans: expect.arrayContaining([
@@ -49,14 +63,24 @@ describe('GraphQL/Apollo Tests', () => {
4963
]),
5064
};
5165

52-
await createRunner(__dirname, 'scenario-mutation.js')
53-
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
54-
.expect({ transaction: EXPECTED_TRANSACTION })
55-
.start()
56-
.completed();
66+
createEsmAndCjsTests(
67+
__dirname,
68+
'scenario-mutation.mjs',
69+
'instrument.mjs',
70+
(createTestRunner, test) => {
71+
test('should instrument GraphQL mutations used from Apollo Server.', async () => {
72+
await createTestRunner()
73+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
74+
.expect({ transaction: EXPECTED_TRANSACTION })
75+
.start()
76+
.completed();
77+
});
78+
},
79+
{ copyPaths: ['apollo-server.mjs'] },
80+
);
5781
});
5882

59-
test('should handle GraphQL errors.', async () => {
83+
describe('error', () => {
6084
const EXPECTED_TRANSACTION = {
6185
transaction: 'Test Transaction (mutation Mutation)',
6286
spans: expect.arrayContaining([
@@ -74,10 +98,20 @@ describe('GraphQL/Apollo Tests', () => {
7498
]),
7599
};
76100

77-
await createRunner(__dirname, 'scenario-error.js')
78-
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
79-
.expect({ transaction: EXPECTED_TRANSACTION })
80-
.start()
81-
.completed();
101+
createEsmAndCjsTests(
102+
__dirname,
103+
'scenario-error.mjs',
104+
'instrument.mjs',
105+
(createTestRunner, test) => {
106+
test('should handle GraphQL errors.', async () => {
107+
await createTestRunner()
108+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
109+
.expect({ transaction: EXPECTED_TRANSACTION })
110+
.start()
111+
.completed();
112+
});
113+
},
114+
{ copyPaths: ['apollo-server.mjs'] },
115+
);
82116
});
83117
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
9+
transport: loggingTransport,
10+
});

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-invalid-root-span.js

Lines changed: 0 additions & 30 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
const tracer = Sentry.getClient().tracer;
4+
5+
async function run() {
6+
const { createApolloServer } = await import('../../apollo-server.mjs');
7+
const server = createApolloServer();
8+
9+
await tracer.startActiveSpan('test span name', async span => {
10+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
11+
await server.executeOperation({
12+
query: 'query GetHello {hello}',
13+
});
14+
15+
setTimeout(() => {
16+
span.end();
17+
server.stop();
18+
}, 500);
19+
});
20+
}
21+
22+
run();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations-many.js renamed to dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations-many.mjs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
const Sentry = require('@sentry/node');
2-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
1+
import * as Sentry from '@sentry/node';
32

4-
const client = Sentry.init({
5-
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6-
release: '1.0',
7-
tracesSampleRate: 1.0,
8-
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
9-
transport: loggingTransport,
10-
});
11-
12-
const tracer = client.tracer;
3+
const tracer = Sentry.getClient().tracer;
134

145
async function run() {
15-
const server = require('../apollo-server')();
6+
const { createApolloServer } = await import('../../apollo-server.mjs');
7+
const server = createApolloServer();
168

179
await tracer.startActiveSpan(
1810
'test span name',

0 commit comments

Comments
 (0)