Skip to content

Commit 3ebd3d4

Browse files
committed
wip test
1 parent b9efbb1 commit 3ebd3d4

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

dev-packages/e2e-tests/test-applications/sveltekit/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"test:assert": "pnpm test:prod"
1515
},
1616
"dependencies": {
17-
"@sentry/sveltekit": "latest || *"
17+
"@sentry/sveltekit": "latest || *",
18+
"@sentry/node": "latest || *",
19+
"@sentry/core": "latest || *"
1820
},
1921
"devDependencies": {
2022
"@playwright/test": "^1.41.1",
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { env } from '$env/dynamic/private';
22
import * as Sentry from '@sentry/sveltekit';
3+
import { sequence } from '@sveltejs/kit/hooks';
34

45
Sentry.init({
56
environment: 'qa', // dynamic sampling bias to keep transactions
67
dsn: env.E2E_TEST_DSN,
78
debug: true,
89
tunnel: `http://localhost:3031/`, // proxy server
910
tracesSampleRate: 1.0,
11+
beforeSendTransaction: txn => {
12+
// console.log('beforeSendTransaction', txn);
13+
return txn;
14+
},
1015
});
1116

1217
// not logging anything to console to avoid noise in the test output
1318
const myErrorHandler = ({ error, event }: any) => {};
1419

1520
export const handleError = Sentry.handleErrorWithSentry(myErrorHandler);
1621

17-
export const handle = Sentry.sentryHandle();
22+
export const handle = sequence(async ({ event, resolve }) => {
23+
console.log('XX event issub', event.isSubRequest, Sentry.getActiveSpan());
24+
return resolve(event);
25+
}, Sentry.sentryHandle());

dev-packages/e2e-tests/test-applications/sveltekit/src/routes/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
<li>
2424
<a href="/universal-load-fetch">Route with fetch in universal load</a>
2525
</li>
26+
<li>
27+
<a href="/server-load-fetch">Route with nested fetch in server load</a>
2628
</ul>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script lang="ts">
2+
export let data;
3+
</script>
4+
5+
<main>
6+
<h1>Server Load Fetch</h1>
7+
<p>{JSON.stringify(data, null, 2)}</p>
8+
</main>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const load = async ({ fetch }) => {
2+
const res = await fetch('/api/users');
3+
const data = await res.json();
4+
return { data };
5+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '../event-proxy-server';
3+
4+
test('server pageload request span has nested request span', async ({ page }) => {
5+
const serverTxnEventPromise = waitForTransaction('sveltekit', txnEvent => {
6+
console.log('txnEvent', txnEvent);
7+
return txnEvent?.transaction === 'GET /server-load-fetch';
8+
});
9+
10+
await page.goto('/server-load-fetch');
11+
12+
const serverTxnEvent = await serverTxnEventPromise;
13+
const spans = serverTxnEvent.spans;
14+
15+
expect(serverTxnEvent).toMatchObject({
16+
transaction: 'GET /server-load-fetch',
17+
tags: { runtime: 'node' },
18+
transaction_info: { source: 'route' },
19+
type: 'transaction',
20+
contexts: {
21+
trace: {
22+
op: 'http.server',
23+
origin: 'auto.http.sveltekit',
24+
},
25+
},
26+
});
27+
28+
console.log(JSON.stringify(spans, null, 2));
29+
30+
expect(spans).toHaveLength(3);
31+
});

packages/core/src/tracing/trace.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export function startSpan<T>(context: StartSpanOptions, callback: (span: Span) =
5656
// eslint-disable-next-line deprecation/deprecation
5757
const parentSpan = scope.getSpan() as SentrySpan | undefined;
5858

59+
console.log(`xx startSpan ${context.op} ${context.name} parentSpan`, parentSpan);
60+
5961
const shouldSkipSpan = context.onlyIfParent && !parentSpan;
6062
const activeSpan = shouldSkipSpan
6163
? new SentryNonRecordingSpan()
@@ -250,6 +252,8 @@ function createChildSpanOrTransaction(
250252
// eslint-disable-next-line deprecation/deprecation
251253
span = parentSpan.startChild(spanContext);
252254
addChildSpanToSpan(parentSpan, span);
255+
256+
console.log('starting child span', spanContext.op);
253257
} else if (parentSpan) {
254258
// If we forced a transaction but have a parent span, make sure to continue from the parent span, not the scope
255259
const dsc = getDynamicSamplingContextFromSpan(parentSpan);
@@ -267,6 +271,7 @@ function createChildSpanOrTransaction(
267271
...spanContext.metadata,
268272
},
269273
});
274+
console.log('starting txn (forced)', spanContext.op);
270275
} else {
271276
const { traceId, dsc, parentSpanId, sampled } = {
272277
...isolationScope.getPropagationContext(),
@@ -284,6 +289,7 @@ function createChildSpanOrTransaction(
284289
...spanContext.metadata,
285290
},
286291
});
292+
console.log('starting txn', spanContext.op);
287293
}
288294

289295
// TODO v8: Technically `startTransaction` can return undefined, which is not reflected by the types

0 commit comments

Comments
 (0)