Skip to content

Commit c8d5d1a

Browse files
committed
ref(browser): Store browser metrics as attributes instead of tags
1 parent 4b7deee commit c8d5d1a

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
@@ -448,15 +448,11 @@ function _trackNavigator(transaction: Transaction): void {
448448
const connection = navigator.connection;
449449
if (connection) {
450450
if (connection.effectiveType) {
451-
// TODO: Can we rewrite this to an attribute?
452-
// eslint-disable-next-line deprecation/deprecation
453-
transaction.setTag('effectiveConnectionType', connection.effectiveType);
451+
transaction.setAttribute('effectiveConnectionType', connection.effectiveType);
454452
}
455453

456454
if (connection.type) {
457-
// TODO: Can we rewrite this to an attribute?
458-
// eslint-disable-next-line deprecation/deprecation
459-
transaction.setTag('connectionType', connection.type);
455+
transaction.setAttribute('connectionType', connection.type);
460456
}
461457

462458
if (isMeasurementValue(connection.rtt)) {
@@ -465,15 +461,11 @@ function _trackNavigator(transaction: Transaction): void {
465461
}
466462

467463
if (isMeasurementValue(navigator.deviceMemory)) {
468-
// TODO: Can we rewrite this to an attribute?
469-
// eslint-disable-next-line deprecation/deprecation
470-
transaction.setTag('deviceMemory', `${navigator.deviceMemory} GB`);
464+
transaction.setAttribute('deviceMemory', `${navigator.deviceMemory} GB`);
471465
}
472466

473467
if (isMeasurementValue(navigator.hardwareConcurrency)) {
474-
// TODO: Can we rewrite this to an attribute?
475-
// eslint-disable-next-line deprecation/deprecation
476-
transaction.setTag('hardwareConcurrency', String(navigator.hardwareConcurrency));
468+
transaction.setAttribute('hardwareConcurrency', String(navigator.hardwareConcurrency));
477469
}
478470
}
479471

@@ -485,36 +477,26 @@ function _tagMetricInfo(transaction: Transaction): void {
485477
// Capture Properties of the LCP element that contributes to the LCP.
486478

487479
if (_lcpEntry.element) {
488-
// TODO: Can we rewrite this to an attribute?
489-
// eslint-disable-next-line deprecation/deprecation
490-
transaction.setTag('lcp.element', htmlTreeAsString(_lcpEntry.element));
480+
transaction.setAttribute('lcp.element', htmlTreeAsString(_lcpEntry.element));
491481
}
492482

493483
if (_lcpEntry.id) {
494-
// TODO: Can we rewrite this to an attribute?
495-
// eslint-disable-next-line deprecation/deprecation
496-
transaction.setTag('lcp.id', _lcpEntry.id);
484+
transaction.setAttribute('lcp.id', _lcpEntry.id);
497485
}
498486

499487
if (_lcpEntry.url) {
500488
// Trim URL to the first 200 characters.
501-
// TODO: Can we rewrite this to an attribute?
502-
// eslint-disable-next-line deprecation/deprecation
503-
transaction.setTag('lcp.url', _lcpEntry.url.trim().slice(0, 200));
489+
transaction.setAttribute('lcp.url', _lcpEntry.url.trim().slice(0, 200));
504490
}
505491

506-
// TODO: Can we rewrite this to an attribute?
507-
// eslint-disable-next-line deprecation/deprecation
508-
transaction.setTag('lcp.size', _lcpEntry.size);
492+
transaction.setAttribute('lcp.size', _lcpEntry.size);
509493
}
510494

511495
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
512496
if (_clsEntry && _clsEntry.sources) {
513497
DEBUG_BUILD && logger.log('[Measurements] Adding CLS Data');
514498
_clsEntry.sources.forEach((source, index) =>
515-
// TODO: Can we rewrite this to an attribute?
516-
// eslint-disable-next-line deprecation/deprecation
517-
transaction.setTag(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
499+
transaction.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
518500
);
519501
}
520502
}

0 commit comments

Comments
 (0)