Skip to content

Commit ce1a098

Browse files
committed
ref(browser): Store browser metrics as attributes instead of tags
1 parent b636963 commit ce1a098

File tree

4 files changed

+18
-36
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/metrics
  • packages/tracing-internal/src/browser/metrics

4 files changed

+18
-36
lines changed

dev-packages/browser-integration-tests/suites/tracing/metrics/handlers-lcp/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ sentryTest(
2929
expect(eventData.measurements).toBeDefined();
3030
expect(eventData.measurements?.lcp?.value).toBeDefined();
3131

32-
expect(eventData.tags?.['lcp.element']).toBe('body > img');
33-
expect(eventData.tags?.['lcp.size']).toBe(107400);
34-
expect(eventData.tags?.['lcp.url']).toBe('https://example.com/path/to/image.png');
32+
expect(eventData.contexts.trace?.data?.['lcp.element']).toBe('body > img');
33+
expect(eventData.contexts.trace?.data?.['lcp.size']).toBe(107400);
34+
expect(eventData.contexts.trace?.data?.['lcp.url']).toBe('https://example.com/path/to/image.png');
3535

3636
const lcp = await (await page.waitForFunction('window._LCP')).jsonValue();
3737
const lcp2 = await (await page.waitForFunction('window._LCP2')).jsonValue();

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ get
2323
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.03);
2424
expect(eventData.measurements?.cls?.value).toBeLessThan(0.07);
2525

26-
expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p#partial');
26+
expect(eventData.contexts.trace?.data?.['cls.source.1']).toBe('body > div#content > p#partial');
2727
});
2828

2929
sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
@@ -37,7 +37,7 @@ sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getL
3737
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.18);
3838
expect(eventData.measurements?.cls?.value).toBeLessThan(0.23);
3939

40-
expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p');
40+
expect(eventData.contexts.trace?.data?.['cls.source.1']).toBe('body > div#content > p');
4141
});
4242

4343
sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
@@ -50,5 +50,5 @@ sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ get
5050
// Flakey value dependent on timings -> we check for a range
5151
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.34);
5252
expect(eventData.measurements?.cls?.value).toBeLessThan(0.36);
53-
expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p');
53+
expect(eventData.contexts.trace?.data?.['cls.source.1']).toBe('body > div#content > p');
5454
});

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-lcp/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN
2424
expect(eventData.measurements).toBeDefined();
2525
expect(eventData.measurements?.lcp?.value).toBeDefined();
2626

27-
expect(eventData.tags?.['lcp.element']).toBe('body > img');
28-
expect(eventData.tags?.['lcp.size']).toBe(107400);
29-
expect(eventData.tags?.['lcp.url']).toBe('https://example.com/path/to/image.png');
27+
expect(eventData.contexts.trace?.data?.['lcp.element']).toBe('body > img');
28+
expect(eventData.contexts.trace?.data?.['lcp.size']).toBe(107400);
29+
expect(eventData.contexts.trace?.data?.['lcp.url']).toBe('https://example.com/path/to/image.png');
3030
});

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,11 @@ function _trackNavigator(span: Span): void {
445445
const connection = navigator.connection;
446446
if (connection) {
447447
if (connection.effectiveType) {
448-
// TODO: Can we rewrite this to an attribute?
449-
// eslint-disable-next-line deprecation/deprecation
450-
(span as SentrySpan).setTag('effectiveConnectionType', connection.effectiveType);
448+
transaction.setAttribute('effectiveConnectionType', connection.effectiveType);
451449
}
452450

453451
if (connection.type) {
454-
// TODO: Can we rewrite this to an attribute?
455-
// eslint-disable-next-line deprecation/deprecation
456-
(span as SentrySpan).setTag('connectionType', connection.type);
452+
transaction.setAttribute('connectionType', connection.type);
457453
}
458454

459455
if (isMeasurementValue(connection.rtt)) {
@@ -462,15 +458,11 @@ function _trackNavigator(span: Span): void {
462458
}
463459

464460
if (isMeasurementValue(navigator.deviceMemory)) {
465-
// TODO: Can we rewrite this to an attribute?
466-
// eslint-disable-next-line deprecation/deprecation
467-
(span as SentrySpan).setTag('deviceMemory', `${navigator.deviceMemory} GB`);
461+
transaction.setAttribute('deviceMemory', `${navigator.deviceMemory} GB`);
468462
}
469463

470464
if (isMeasurementValue(navigator.hardwareConcurrency)) {
471-
// TODO: Can we rewrite this to an attribute?
472-
// eslint-disable-next-line deprecation/deprecation
473-
(span as SentrySpan).setTag('hardwareConcurrency', String(navigator.hardwareConcurrency));
465+
transaction.setAttribute('hardwareConcurrency', String(navigator.hardwareConcurrency));
474466
}
475467
}
476468

@@ -482,36 +474,26 @@ function _tagMetricInfo(span: Span): void {
482474
// Capture Properties of the LCP element that contributes to the LCP.
483475

484476
if (_lcpEntry.element) {
485-
// TODO: Can we rewrite this to an attribute?
486-
// eslint-disable-next-line deprecation/deprecation
487-
(span as SentrySpan).setTag('lcp.element', htmlTreeAsString(_lcpEntry.element));
477+
transaction.setAttribute('lcp.element', htmlTreeAsString(_lcpEntry.element));
488478
}
489479

490480
if (_lcpEntry.id) {
491-
// TODO: Can we rewrite this to an attribute?
492-
// eslint-disable-next-line deprecation/deprecation
493-
(span as SentrySpan).setTag('lcp.id', _lcpEntry.id);
481+
transaction.setAttribute('lcp.id', _lcpEntry.id);
494482
}
495483

496484
if (_lcpEntry.url) {
497485
// Trim URL to the first 200 characters.
498-
// TODO: Can we rewrite this to an attribute?
499-
// eslint-disable-next-line deprecation/deprecation
500-
(span as SentrySpan).setTag('lcp.url', _lcpEntry.url.trim().slice(0, 200));
486+
transaction.setAttribute('lcp.url', _lcpEntry.url.trim().slice(0, 200));
501487
}
502488

503-
// TODO: Can we rewrite this to an attribute?
504-
// eslint-disable-next-line deprecation/deprecation
505-
(span as SentrySpan).setTag('lcp.size', _lcpEntry.size);
489+
transaction.setAttribute('lcp.size', _lcpEntry.size);
506490
}
507491

508492
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
509493
if (_clsEntry && _clsEntry.sources) {
510494
DEBUG_BUILD && logger.log('[Measurements] Adding CLS Data');
511495
_clsEntry.sources.forEach((source, index) =>
512-
// TODO: Can we rewrite this to an attribute?
513-
// eslint-disable-next-line deprecation/deprecation
514-
(span as SentrySpan).setTag(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
496+
transaction.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
515497
);
516498
}
517499
}

0 commit comments

Comments
 (0)