Skip to content

Commit 87e5f8b

Browse files
authored
test(nuxt): Add tests for trace baggage (#16046)
Check whether the baggage data is propagated correctly in connected traces.
1 parent f1b8291 commit 87e5f8b

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

dev-packages/e2e-tests/test-applications/nuxt-3-dynamic-import/tests/tracing.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.describe('distributed tracing', () => {
2020
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2121
]);
2222

23+
const baggageMetaTagContent = await page.locator('meta[name="baggage"]').getAttribute('content');
24+
25+
expect(baggageMetaTagContent).toContain(`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`);
26+
expect(baggageMetaTagContent).toContain(`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`); // URL-encoded for 'GET /test-param/s0me-param'
27+
expect(baggageMetaTagContent).toContain('sentry-sampled=true');
28+
expect(baggageMetaTagContent).toContain('sentry-sample_rate=1');
29+
30+
const sentryTraceMetaTagContent = await page.locator('meta[name="sentry-trace"]').getAttribute('content');
31+
const [metaTraceId, metaParentSpanId, metaSampled] = sentryTraceMetaTagContent?.split('-') || [];
32+
33+
expect(metaSampled).toBe('1');
34+
2335
expect(clientTxnEvent).toMatchObject({
2436
transaction: '/test-param/:param()',
2537
transaction_info: { source: 'route' },
@@ -28,12 +40,14 @@ test.describe('distributed tracing', () => {
2840
trace: {
2941
op: 'pageload',
3042
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3145
},
3246
},
3347
});
3448

3549
expect(serverTxnEvent).toMatchObject({
36-
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3751
transaction_info: { source: 'url' },
3852
type: 'transaction',
3953
contexts: {
@@ -45,7 +59,11 @@ test.describe('distributed tracing', () => {
4559
});
4660

4761
// connected trace
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
64+
4865
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
4966
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
5068
});
5169
});

dev-packages/e2e-tests/test-applications/nuxt-3-min/tests/tracing.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.describe('distributed tracing', () => {
2020
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2121
]);
2222

23+
const baggageMetaTagContent = await page.locator('meta[name="baggage"]').getAttribute('content');
24+
25+
expect(baggageMetaTagContent).toContain(`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`);
26+
expect(baggageMetaTagContent).toContain(`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`); // URL-encoded for 'GET /test-param/s0me-param'
27+
expect(baggageMetaTagContent).toContain('sentry-sampled=true');
28+
expect(baggageMetaTagContent).toContain('sentry-sample_rate=1');
29+
30+
const sentryTraceMetaTagContent = await page.locator('meta[name="sentry-trace"]').getAttribute('content');
31+
const [metaTraceId, metaParentSpanId, metaSampled] = sentryTraceMetaTagContent?.split('-') || [];
32+
33+
expect(metaSampled).toBe('1');
34+
2335
expect(clientTxnEvent).toMatchObject({
2436
transaction: '/test-param/:param()',
2537
transaction_info: { source: 'route' },
@@ -28,12 +40,14 @@ test.describe('distributed tracing', () => {
2840
trace: {
2941
op: 'pageload',
3042
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3145
},
3246
},
3347
});
3448

3549
expect(serverTxnEvent).toMatchObject({
36-
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3751
transaction_info: { source: 'url' },
3852
type: 'transaction',
3953
contexts: {
@@ -45,7 +59,11 @@ test.describe('distributed tracing', () => {
4559
});
4660

4761
// connected trace
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
64+
4865
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
4966
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
5068
});
5169
});

dev-packages/e2e-tests/test-applications/nuxt-3-top-level-import/tests/tracing.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.describe('distributed tracing', () => {
2020
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2121
]);
2222

23+
const baggageMetaTagContent = await page.locator('meta[name="baggage"]').getAttribute('content');
24+
25+
expect(baggageMetaTagContent).toContain(`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`);
26+
expect(baggageMetaTagContent).toContain(`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`); // URL-encoded for 'GET /test-param/s0me-param'
27+
expect(baggageMetaTagContent).toContain('sentry-sampled=true');
28+
expect(baggageMetaTagContent).toContain('sentry-sample_rate=1');
29+
30+
const sentryTraceMetaTagContent = await page.locator('meta[name="sentry-trace"]').getAttribute('content');
31+
const [metaTraceId, metaParentSpanId, metaSampled] = sentryTraceMetaTagContent?.split('-') || [];
32+
33+
expect(metaSampled).toBe('1');
34+
2335
expect(clientTxnEvent).toMatchObject({
2436
transaction: '/test-param/:param()',
2537
transaction_info: { source: 'route' },
@@ -28,12 +40,14 @@ test.describe('distributed tracing', () => {
2840
trace: {
2941
op: 'pageload',
3042
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3145
},
3246
},
3347
});
3448

3549
expect(serverTxnEvent).toMatchObject({
36-
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3751
transaction_info: { source: 'url' },
3852
type: 'transaction',
3953
contexts: {
@@ -45,7 +59,11 @@ test.describe('distributed tracing', () => {
4559
});
4660

4761
// connected trace
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
64+
4865
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
4966
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
5068
});
5169
});

dev-packages/e2e-tests/test-applications/nuxt-3/tests/tracing.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.describe('distributed tracing', () => {
2020
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2121
]);
2222

23+
const baggageMetaTagContent = await page.locator('meta[name="baggage"]').getAttribute('content');
24+
25+
expect(baggageMetaTagContent).toContain(`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`);
26+
expect(baggageMetaTagContent).toContain(`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`); // URL-encoded for 'GET /test-param/s0me-param'
27+
expect(baggageMetaTagContent).toContain('sentry-sampled=true');
28+
expect(baggageMetaTagContent).toContain('sentry-sample_rate=1');
29+
30+
const sentryTraceMetaTagContent = await page.locator('meta[name="sentry-trace"]').getAttribute('content');
31+
const [metaTraceId, metaParentSpanId, metaSampled] = sentryTraceMetaTagContent?.split('-') || [];
32+
33+
expect(metaSampled).toBe('1');
34+
2335
expect(clientTxnEvent).toMatchObject({
2436
transaction: '/test-param/:param()',
2537
transaction_info: { source: 'route' },
@@ -28,12 +40,14 @@ test.describe('distributed tracing', () => {
2840
trace: {
2941
op: 'pageload',
3042
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3145
},
3246
},
3347
});
3448

3549
expect(serverTxnEvent).toMatchObject({
36-
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3751
transaction_info: { source: 'url' },
3852
type: 'transaction',
3953
contexts: {
@@ -45,7 +59,11 @@ test.describe('distributed tracing', () => {
4559
});
4660

4761
// connected trace
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
64+
4865
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
4966
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
5068
});
5169
});

dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.describe('distributed tracing', () => {
2020
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2121
]);
2222

23+
const baggageMetaTagContent = await page.locator('meta[name="baggage"]').getAttribute('content');
24+
25+
expect(baggageMetaTagContent).toContain(`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`);
26+
expect(baggageMetaTagContent).toContain(`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`); // URL-encoded for 'GET /test-param/s0me-param'
27+
expect(baggageMetaTagContent).toContain('sentry-sampled=true');
28+
expect(baggageMetaTagContent).toContain('sentry-sample_rate=1');
29+
30+
const sentryTraceMetaTagContent = await page.locator('meta[name="sentry-trace"]').getAttribute('content');
31+
const [metaTraceId, metaParentSpanId, metaSampled] = sentryTraceMetaTagContent?.split('-') || [];
32+
33+
expect(metaSampled).toBe('1');
34+
2335
expect(clientTxnEvent).toMatchObject({
2436
transaction: '/test-param/:param()',
2537
transaction_info: { source: 'route' },
@@ -28,12 +40,14 @@ test.describe('distributed tracing', () => {
2840
trace: {
2941
op: 'pageload',
3042
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3145
},
3246
},
3347
});
3448

3549
expect(serverTxnEvent).toMatchObject({
36-
transaction: 'GET /test-param/s0me-param', // todo: parametrize (nitro)
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3751
transaction_info: { source: 'url' },
3852
type: 'transaction',
3953
contexts: {
@@ -45,7 +59,11 @@ test.describe('distributed tracing', () => {
4559
});
4660

4761
// connected trace
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
64+
4865
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
4966
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
5068
});
5169
});

0 commit comments

Comments
 (0)