Skip to content

test(nuxt): Add test for distributed server request #16788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</div>
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
import { useFetch } from '#imports';

const fetchData = async () => {
const fetchError = async () => {
await useFetch('/api/server-error');
}
};
</script>
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', { exact: true }).click();
await page.getByText('Fetch Server Error', { exact: true }).click();

const error = await errorPromise;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</div>
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
import { useFetch } from '#imports';

const fetchData = async () => {
const fetchError = async () => {
await useFetch('/api/server-error');
}
};
</script>
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', { exact: true }).click();
await page.getByText('Fetch Server Error', { exact: true }).click();

const error = await errorPromise;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</div>
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
import { useFetch } from '#imports';

const fetchData = async () => {
const fetchError = async () => {
await useFetch('/api/server-error');
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.describe('server-side errors', async () => {
});

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

const transactionEvent = await transactionEventPromise;
const error = await errorPromise;
Expand Down Expand Up @@ -40,7 +40,7 @@ test.describe('server-side errors', async () => {
});

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

const transactionEvent = await transactionEventPromise;
const error = await errorPromise;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</div>
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
import { useFetch } from '#imports';

const fetchData = async () => {
const fetchError = async () => {
await useFetch('/api/server-error');
}
};
</script>
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', { exact: true }).click();
await page.getByText('Fetch Server Error', { exact: true }).click();

const error = await errorPromise;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div>
<button @click="fetchData">Fetch Server Data</button>
<button @click="fetchError">Fetch Server Error</button>
</div>
</template>

<script setup lang="ts">
import { useFetch} from '#imports'
import { useFetch } from '#imports';

const fetchData = async () => {
const fetchError = async () => {
await useFetch('/api/server-error');
}
};
</script>
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', { exact: true }).click();
await page.getByText('Fetch Server Error', { exact: true }).click();

const error = await errorPromise;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,70 @@ test.describe('distributed tracing', () => {
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
});

test('capture a distributed server request with parametrization', async ({ page }) => {
const clientTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
return txnEvent.transaction === '/test-param/:param()';
});

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

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

const [, clientTxnEvent, ssrTxnEvent, , , serverReqTxnEvent] = await Promise.all([
page.goto(`/test-param/${PARAM}`),
clientTxnEventPromise,
ssrTxnEventPromise,
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
page.getByText('Fetch Server Data', { exact: true }).click(),
serverReqTxnEventPromise,
]);

const httpClientSpan = clientTxnEvent?.spans?.find(span => span.description === `GET /api/test-param/${PARAM}`);

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

expect(httpClientSpan).toMatchObject({
description: `GET /api/test-param/${PARAM}`, // todo: parametrize (nitro)
parent_span_id: clientTxnEvent.contexts?.trace?.span_id, // pageload span is parent
data: expect.objectContaining({
'sentry.op': 'http.client',
'sentry.origin': 'auto.http.browser',
'http.request_method': 'GET',
}),
});

expect(serverReqTxnEvent).toMatchObject({
transaction: `GET /api/test-param/${PARAM}`, // todo: parametrize (nitro)
transaction_info: { source: 'url' },
type: 'transaction',
contexts: {
trace: {
op: 'http.server',
origin: 'auto.http.otel.http',
parent_span_id: httpClientSpan?.span_id, // http.client span is parent
},
},
});

// All share the same trace_id
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(httpClientSpan?.trace_id);
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(ssrTxnEvent.contexts?.trace?.trace_id);
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverReqTxnEvent.contexts?.trace?.trace_id);
});
});
Loading