Skip to content

Commit

Permalink
test(nuxt): Add E2E test for distributed tracing (#13752)
Browse files Browse the repository at this point in the history
Test for pageload. Tests for distributed tracing for navigations are
still coming (waiting for next Nuxt version which includes the new
version of ofetch with [this
PR](unjs/ofetch#377))
  • Loading branch information
s1gr1d authored Sep 26, 2024
1 parent 3714d60 commit 5e2bc47
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<template>
<p>{{ $route.params.param }} - {{ $route.params.param }}</p>

<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" />
<button @click="fetchData">Fetch Server Data</button>
</template>

<script setup lang="ts">
import { useRoute, useFetch } from '#imports'
const route = useRoute();
const param = route.params.param;
const fetchData = async () => {
const fetchError = async () => {
await useFetch(`/api/param-error/${param}`);
}
const fetchData = async () => {
await useFetch(`/api/test-param/${param}`);
};
</script>

<template>
<p>Param: {{ $route.params.param }}</p>

<ErrorButton id="errorBtn" errorText="Error thrown from Param Route Button" />
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</template>

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test.describe('server-side errors', async () => {
});

await page.goto(`/fetch-server-error`);
await page.getByText('Fetch Server Data').click();
await page.getByText('Fetch Server Data', { exact: true }).click();

const error = await errorPromise;

Expand All @@ -26,7 +26,7 @@ test.describe('server-side errors', async () => {
});

await page.goto(`/test-param/1234`);
await page.getByText('Fetch Server Data').click();
await page.getByRole('button', { name: 'Fetch Server Error', exact: true }).click();

const error = await errorPromise;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test.describe('distributed tracing', () => {
const PARAM = 's0me-param';

test('capture a distributed pageload trace', async ({ page }) => {
const clientTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => {
return txnEvent.transaction === '/test-param/:param()';
});

const serverTxnEventPromise = waitForTransaction('nuxt-3', txnEvent => {
return txnEvent.transaction.includes('GET /test-param/');
});

const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
page.goto(`/test-param/${PARAM}`),
clientTxnEventPromise,
serverTxnEventPromise,
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
]);

expect(clientTxnEvent).toMatchObject({
transaction: '/test-param/:param()',
transaction_info: { source: 'route' },
type: 'transaction',
contexts: {
trace: {
op: 'pageload',
origin: 'auto.pageload.vue',
},
},
});

expect(serverTxnEvent).toMatchObject({
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
transaction_info: { source: 'url' },
type: 'transaction',
contexts: {
trace: {
op: 'http.server',
origin: 'auto.http.otel.http',
},
},
});

// connected trace
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
});
});

0 comments on commit 5e2bc47

Please sign in to comment.