Skip to content

Commit b9c476a

Browse files
committed
get baggage from meta tags
1 parent bce0c01 commit b9c476a

File tree

5 files changed

+96
-86
lines changed

5 files changed

+96
-86
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ test.describe('distributed tracing', () => {
1313
return txnEvent.transaction.includes('GET /test-param/');
1414
});
1515

16-
const res = await page.goto(`/test-param/${PARAM}`);
17-
const data = await res.json();
18-
19-
const [clientTxnEvent, serverTxnEvent] = await Promise.all([
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
2018
clientTxnEventPromise,
2119
serverTxnEventPromise,
2220
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2321
]);
2422

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.0');
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+
2535
expect(clientTxnEvent).toMatchObject({
2636
transaction: '/test-param/:param()',
2737
transaction_info: { source: 'route' },
@@ -30,6 +40,8 @@ test.describe('distributed tracing', () => {
3040
trace: {
3141
op: 'pageload',
3242
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3345
},
3446
},
3547
});
@@ -46,22 +58,12 @@ test.describe('distributed tracing', () => {
4658
},
4759
});
4860

49-
const baggage = (data.headers.baggage || null).split(',');
50-
5161
// connected trace
52-
expect(clientTxnEvent.contexts?.trace?.trace_id).not.toBeUndefined();
53-
expect(clientTxnEvent.contexts?.trace?.parent_span_id).not.toBeUndefined();
54-
expect(baggage).not.toBeNull();
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
5564

5665
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
5766
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
58-
expect(baggage).toEqual(
59-
expect.arrayContaining([
60-
'sentry-sample-rate=1.0',
61-
'sentry-sampled=true',
62-
`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`,
63-
`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`,
64-
]),
65-
);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6668
});
6769
});

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ test.describe('distributed tracing', () => {
1313
return txnEvent.transaction.includes('GET /test-param/');
1414
});
1515

16-
const res = await page.goto(`/test-param/${PARAM}`);
17-
const data = await res.json();
18-
19-
const [clientTxnEvent, serverTxnEvent] = await Promise.all([
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
2018
clientTxnEventPromise,
2119
serverTxnEventPromise,
2220
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2321
]);
2422

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.0');
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+
2535
expect(clientTxnEvent).toMatchObject({
2636
transaction: '/test-param/:param()',
2737
transaction_info: { source: 'route' },
@@ -30,6 +40,8 @@ test.describe('distributed tracing', () => {
3040
trace: {
3141
op: 'pageload',
3242
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3345
},
3446
},
3547
});
@@ -46,22 +58,12 @@ test.describe('distributed tracing', () => {
4658
},
4759
});
4860

49-
const baggage = (data.headers.baggage || null).split(',');
50-
5161
// connected trace
52-
expect(clientTxnEvent.contexts?.trace?.trace_id).not.toBeUndefined();
53-
expect(clientTxnEvent.contexts?.trace?.parent_span_id).not.toBeUndefined();
54-
expect(baggage).not.toBeNull();
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
5564

5665
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
5766
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
58-
expect(baggage).toEqual(
59-
expect.arrayContaining([
60-
'sentry-sample-rate=1.0',
61-
'sentry-sampled=true',
62-
`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`,
63-
`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`,
64-
]),
65-
);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6668
});
6769
});

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ test.describe('distributed tracing', () => {
1313
return txnEvent.transaction.includes('GET /test-param/');
1414
});
1515

16-
const res = await page.goto(`/test-param/${PARAM}`);
17-
const data = await res.json();
18-
19-
const [clientTxnEvent, serverTxnEvent] = await Promise.all([
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
2018
clientTxnEventPromise,
2119
serverTxnEventPromise,
2220
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2321
]);
2422

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.0');
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+
2535
expect(clientTxnEvent).toMatchObject({
2636
transaction: '/test-param/:param()',
2737
transaction_info: { source: 'route' },
@@ -30,12 +40,14 @@ test.describe('distributed tracing', () => {
3040
trace: {
3141
op: 'pageload',
3242
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3345
},
3446
},
3547
});
3648

3749
expect(serverTxnEvent).toMatchObject({
38-
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)`
50+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
3951
transaction_info: { source: 'url' },
4052
type: 'transaction',
4153
contexts: {
@@ -46,22 +58,12 @@ test.describe('distributed tracing', () => {
4658
},
4759
});
4860

49-
const baggage = (data.headers.baggage || null).split(',');
50-
5161
// connected trace
52-
expect(clientTxnEvent.contexts?.trace?.trace_id).not.toBeUndefined();
53-
expect(clientTxnEvent.contexts?.trace?.parent_span_id).not.toBeUndefined();
54-
expect(baggage).not.toBeNull();
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
5564

5665
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
5766
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
58-
expect(baggage).toEqual(
59-
expect.arrayContaining([
60-
'sentry-sample-rate=1.0',
61-
'sentry-sampled=true',
62-
`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`,
63-
`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`,
64-
]),
65-
);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6668
});
6769
});

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ test.describe('distributed tracing', () => {
1313
return txnEvent.transaction.includes('GET /test-param/');
1414
});
1515

16-
const res = await page.goto(`/test-param/${PARAM}`);
17-
const data = await res.json();
18-
19-
const [clientTxnEvent, serverTxnEvent] = await Promise.all([
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
2018
clientTxnEventPromise,
2119
serverTxnEventPromise,
2220
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2321
]);
2422

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.0');
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+
2535
expect(clientTxnEvent).toMatchObject({
2636
transaction: '/test-param/:param()',
2737
transaction_info: { source: 'route' },
@@ -30,6 +40,8 @@ test.describe('distributed tracing', () => {
3040
trace: {
3141
op: 'pageload',
3242
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3345
},
3446
},
3547
});
@@ -46,22 +58,12 @@ test.describe('distributed tracing', () => {
4658
},
4759
});
4860

49-
const baggage = (data.headers.baggage || null).split(',');
50-
5161
// connected trace
52-
expect(clientTxnEvent.contexts?.trace?.trace_id).not.toBeUndefined();
53-
expect(clientTxnEvent.contexts?.trace?.parent_span_id).not.toBeUndefined();
54-
expect(baggage).not.toBeNull();
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
5564

5665
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
5766
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
58-
expect(baggage).toEqual(
59-
expect.arrayContaining([
60-
'sentry-sample-rate=1.0',
61-
'sentry-sampled=true',
62-
`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`,
63-
`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`,
64-
]),
65-
);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6668
});
6769
});

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ test.describe('distributed tracing', () => {
1313
return txnEvent.transaction.includes('GET /test-param/');
1414
});
1515

16-
const res = await page.goto(`/test-param/${PARAM}`);
17-
const data = await res.json();
18-
19-
const [clientTxnEvent, serverTxnEvent] = await Promise.all([
16+
const [_, clientTxnEvent, serverTxnEvent] = await Promise.all([
17+
page.goto(`/test-param/${PARAM}`),
2018
clientTxnEventPromise,
2119
serverTxnEventPromise,
2220
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
2321
]);
2422

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.0');
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+
2535
expect(clientTxnEvent).toMatchObject({
2636
transaction: '/test-param/:param()',
2737
transaction_info: { source: 'route' },
@@ -30,6 +40,8 @@ test.describe('distributed tracing', () => {
3040
trace: {
3141
op: 'pageload',
3242
origin: 'auto.pageload.vue',
43+
trace_id: metaTraceId,
44+
parent_span_id: metaParentSpanId,
3345
},
3446
},
3547
});
@@ -46,22 +58,12 @@ test.describe('distributed tracing', () => {
4658
},
4759
});
4860

49-
const baggage = (data.headers.baggage || null).split(',');
50-
5161
// connected trace
52-
expect(clientTxnEvent.contexts?.trace?.trace_id).not.toBeUndefined();
53-
expect(clientTxnEvent.contexts?.trace?.parent_span_id).not.toBeUndefined();
54-
expect(baggage).not.toBeNull();
62+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
63+
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBeDefined();
5564

5665
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverTxnEvent.contexts?.trace?.trace_id);
5766
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
58-
expect(baggage).toEqual(
59-
expect.arrayContaining([
60-
'sentry-sample-rate=1.0',
61-
'sentry-sampled=true',
62-
`sentry-trace_id=${serverTxnEvent.contexts?.trace?.trace_id}`,
63-
`sentry-transaction=GET%20%2Ftest-param%2F${PARAM}`,
64-
]),
65-
);
67+
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6668
});
6769
});

0 commit comments

Comments
 (0)