Skip to content

Commit d803dd7

Browse files
msonnbcodex
andcommitted
test(e2e): Update live ingestion verification for span streaming
Co-Authored-By: GPT-6 <codex@openai.com>
1 parent 37118dd commit d803dd7

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

‎dev-packages/e2e-tests/test-applications/node-express-send-to-sentry/src/app.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import * as Sentry from '@sentry/node';
22

3-
let lastTransactionId: string | undefined;
4-
let lastTransactionTraceId: string | undefined;
3+
let lastSpanTraceId: string | undefined;
54
let lastErrorTraceId: string | undefined;
65

76
Sentry.init({
8-
traceLifecycle: 'static',
9-
environment: 'qa', // dynamic sampling bias to keep transactions
7+
environment: 'qa', // dynamic sampling bias to keep traces
108
dsn: process.env.E2E_TEST_DSN,
119
includeLocalVariables: true,
1210
tracesSampleRate: 1,
1311
beforeSend(event) {
1412
lastErrorTraceId = event.contexts?.trace?.trace_id;
1513
return event;
1614
},
17-
beforeSendTransaction(event) {
18-
lastTransactionId = event.event_id;
19-
lastTransactionTraceId = event.contexts?.trace?.trace_id;
20-
return event;
15+
beforeSendSpan(span) {
16+
if (span.name === 'test-transaction') {
17+
lastSpanTraceId = span.trace_id;
18+
}
19+
return span;
2120
},
2221
});
2322

@@ -43,8 +42,7 @@ app.get('/test-transaction', function (req, res) {
4342
await Sentry.flush();
4443

4544
res.send({
46-
transactionId: lastTransactionId,
47-
traceId: lastTransactionTraceId,
45+
traceId: lastSpanTraceId,
4846
});
4947
});
5048
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { EVENT_POLLING_OPTIONS, findErrorInTrace, findTransactionInTrace } from './utils/sentry-api';
2+
import { EVENT_POLLING_OPTIONS, findErrorInTrace, findSpanInTrace } from './utils/sentry-api';
33

44
test('Sends exception to Sentry', async ({ baseURL }) => {
55
const response = await fetch(`${baseURL}/test-error`);
@@ -10,13 +10,13 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1010
await expect.poll(() => findErrorInTrace(traceId, exceptionId), EVENT_POLLING_OPTIONS).toBeDefined();
1111
});
1212

13-
test('Sends transaction to Sentry', async ({ baseURL }) => {
13+
test('Sends streamed span to Sentry', async ({ baseURL }) => {
1414
const response = await fetch(`${baseURL}/test-transaction`);
15-
const { transactionId, traceId } = await response.json();
15+
const { traceId } = await response.json();
1616

17-
console.log(`Polling for transaction eventId: ${transactionId} in trace: ${traceId}`);
17+
console.log(`Polling for streamed span in trace: ${traceId}`);
1818

1919
await expect
20-
.poll(() => findTransactionInTrace(traceId, transactionId), EVENT_POLLING_OPTIONS)
20+
.poll(() => findSpanInTrace(traceId, 'e2e-test'), EVENT_POLLING_OPTIONS)
2121
.toMatchObject({ op: 'e2e-test' });
2222
});

‎dev-packages/e2e-tests/test-applications/node-express-send-to-sentry/tests/utils/sentry-api.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ export const EVENT_POLLING_OPTIONS = { timeout: 180_000, intervals: [5_000] };
1313
*/
1414
export interface TraceItem {
1515
event_id?: string;
16-
/** On spans this is the event id of the transaction the span belongs to. */
17-
transaction_id?: string;
1816
event_type?: 'span' | 'error' | 'occurrence' | 'uptime_check';
1917
op?: string;
20-
is_transaction?: boolean;
2118
children?: TraceItem[];
2219
errors?: TraceItem[];
2320
occurrences?: TraceItem[];
@@ -67,6 +64,6 @@ export async function findErrorInTrace(traceId: string, eventId: string): Promis
6764
return flattenTrace(await fetchTrace(traceId)).find(item => item.event_type === 'error' && item.event_id === eventId);
6865
}
6966

70-
export async function findTransactionInTrace(traceId: string, eventId: string): Promise<TraceItem | undefined> {
71-
return flattenTrace(await fetchTrace(traceId)).find(item => item.is_transaction && item.transaction_id === eventId);
67+
export async function findSpanInTrace(traceId: string, op: string): Promise<TraceItem | undefined> {
68+
return flattenTrace(await fetchTrace(traceId)).find(item => item.op === op);
7269
}

0 commit comments

Comments
 (0)