Skip to content

Commit 2d4bccc

Browse files
committed
Fix integration tests, add more representative e2e test
1 parent c2baa79 commit 2d4bccc

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

dev-packages/e2e-tests/test-applications/node-otel-without-tracing/src/app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ app.get('/test-exception/:id', function (req, _res) {
6262
throw new Error(`This is an exception with id ${id}`);
6363
});
6464

65+
app.get('/test-logs/:id', function (req, res) {
66+
const id = req.params.id;
67+
68+
Sentry.startSpan({ name: `log-operation-${id}` }, () => {
69+
Sentry.logger.info(`test-log-${id}`, { requestId: id });
70+
});
71+
72+
res.send({ ok: true, id });
73+
});
74+
6575
Sentry.setupExpressErrorHandler(app);
6676

6777
app.use(function onError(err: unknown, req: any, res: any, next: any) {

dev-packages/e2e-tests/test-applications/node-otel-without-tracing/src/instrument.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Sentry.init({
1717
// Tracing is completely disabled
1818
// Custom OTEL setup
1919
skipOpenTelemetrySetup: true,
20+
enableLogs: true,
2021
});
2122

2223
// Create and configure NodeTracerProvider
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForEnvelopeItem } from '@sentry-internal/test-utils';
3+
4+
test('Logs from different requests have different trace IDs', async ({ baseURL }) => {
5+
const logEnvelopePromise1 = waitForEnvelopeItem('node-otel-without-tracing', async envelopeItem => {
6+
const [itemHeader, itemPayload] = envelopeItem;
7+
if (itemHeader.type === 'log') {
8+
const logItems = itemPayload as { items: Array<{ body: string; trace_id?: string }> };
9+
return logItems.items.some(item => item.body === 'test-log-1');
10+
}
11+
return false;
12+
});
13+
14+
const logEnvelopePromise2 = waitForEnvelopeItem('node-otel-without-tracing', async envelopeItem => {
15+
const [itemHeader, itemPayload] = envelopeItem;
16+
if (itemHeader.type === 'log') {
17+
const logItems = itemPayload as { items: Array<{ body: string; trace_id?: string }> };
18+
return logItems.items.some(item => item.body === 'test-log-2');
19+
}
20+
return false;
21+
});
22+
23+
// Make two requests to different routes (each Express route is an isolation scope)
24+
await fetch(`${baseURL}/test-logs/1`);
25+
await fetch(`${baseURL}/test-logs/2`);
26+
27+
const logEnvelope1 = await logEnvelopePromise1;
28+
const logEnvelope2 = await logEnvelopePromise2;
29+
30+
const logPayload1 = logEnvelope1[1] as { items: Array<{ body: string; trace_id?: string }> };
31+
const logPayload2 = logEnvelope2[1] as { items: Array<{ body: string; trace_id?: string }> };
32+
33+
const log1 = logPayload1.items.find(item => item.body === 'test-log-1');
34+
const log2 = logPayload2.items.find(item => item.body === 'test-log-2');
35+
36+
const traceId1 = log1?.trace_id;
37+
const traceId2 = log2?.trace_id;
38+
39+
expect(traceId1).toMatch(/[a-f0-9]{32}/);
40+
expect(traceId2).toMatch(/[a-f0-9]{32}/);
41+
expect(traceId1).not.toBe(traceId2);
42+
});

dev-packages/node-integration-tests/suites/pino/instrument-auto-off.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Sentry from '@sentry/node';
33
Sentry.init({
44
dsn: process.env.SENTRY_DSN,
55
release: '1.0',
6+
tracesSampleRate: 1.0,
67
enableLogs: true,
78
integrations: [Sentry.pinoIntegration({ autoInstrument: false })],
89
});

dev-packages/node-integration-tests/suites/pino/instrument.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Sentry from '@sentry/node';
33
Sentry.init({
44
dsn: process.env.SENTRY_DSN,
55
release: '1.0',
6+
tracesSampleRate: 1.0,
67
enableLogs: true,
78
integrations: [Sentry.pinoIntegration({ error: { levels: ['error', 'fatal'] } })],
89
});

dev-packages/node-integration-tests/suites/pino/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ conditionalTest({ min: 20 })('Pino integration', () => {
1111
.withMockSentryServer()
1212
.withInstrument(instrumentPath)
1313
.ignore('event')
14+
.ignore('transaction')
1415
.expect({
1516
log: log => {
1617
const traceId1 = log.items?.[0]?.trace_id;
@@ -28,6 +29,7 @@ conditionalTest({ min: 20 })('Pino integration', () => {
2829
await createRunner(__dirname, 'scenario.mjs')
2930
.withMockSentryServer()
3031
.withInstrument(instrumentPath)
32+
.ignore('transaction')
3133
.expect({
3234
event: {
3335
exception: {
@@ -105,6 +107,7 @@ conditionalTest({ min: 20 })('Pino integration', () => {
105107
await createRunner(__dirname, 'scenario-next.mjs')
106108
.withMockSentryServer()
107109
.withInstrument(instrumentPath)
110+
.ignore('transaction')
108111
.expect({
109112
event: {
110113
exception: {
@@ -182,6 +185,7 @@ conditionalTest({ min: 20 })('Pino integration', () => {
182185
await createRunner(__dirname, 'scenario-track.mjs')
183186
.withMockSentryServer()
184187
.withInstrument(instrumentPath)
188+
.ignore('transaction')
185189
.expect({
186190
log: {
187191
items: [

0 commit comments

Comments
 (0)