Skip to content

Commit

Permalink
Merge branch 'develop' into esm/again
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Mar 7, 2024
2 parents 1945f73 + 4b261ce commit 0fe7370
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ sentryTest(
expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.lcp?.value).toBeDefined();

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

const lcp = await (await page.waitForFunction('window._LCP')).jsonValue();
const lcp2 = await (await page.waitForFunction('window._LCP2')).jsonValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ get
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.03);
expect(eventData.measurements?.cls?.value).toBeLessThan(0.07);

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

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

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

sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ getLocalTestPath, page }) => {
Expand All @@ -50,5 +50,5 @@ sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ get
// Flakey value dependent on timings -> we check for a range
expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.34);
expect(eventData.measurements?.cls?.value).toBeLessThan(0.36);
expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p');
expect(eventData.contexts?.trace?.data?.['cls.source.1']).toBe('body > div#content > p');
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN
sentryTest.skip();
}

await page.route('**/path/to/image.png', (route: Route) =>
route.fulfill({ path: `${__dirname}/assets/sentry-logo-600x179.png` }),
);
page.route('**', route => route.continue());
page.route('**/path/to/image.png', async (route: Route) => {
return route.fulfill({ path: `${__dirname}/assets/sentry-logo-600x179.png` });
});

const url = await getLocalTestPath({ testDir: __dirname });
const [eventData] = await Promise.all([
Expand All @@ -24,7 +25,7 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN
expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.lcp?.value).toBeDefined();

expect(eventData.tags?.['lcp.element']).toBe('body > img');
expect(eventData.tags?.['lcp.size']).toBe(107400);
expect(eventData.tags?.['lcp.url']).toBe('https://example.com/path/to/image.png');
expect(eventData.contexts?.trace?.data?.['lcp.element']).toBe('body > img');
expect(eventData.contexts?.trace?.data?.['lcp.size']).toBe(107400);
expect(eventData.contexts?.trace?.data?.['lcp.url']).toBe('https://example.com/path/to/image.png');
});
28 changes: 0 additions & 28 deletions packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
Primitive,
Span,
SpanAttributeValue,
SpanAttributes,
Expand Down Expand Up @@ -65,12 +64,6 @@ export class SpanRecorder {
* Span contains all data about a span
*/
export class SentrySpan implements Span {
/**
* Tags for the span.
* @deprecated Use `spanToJSON(span).atttributes` instead.
*/
public tags: { [key: string]: Primitive };

/**
* Data for the span.
* @deprecated Use `spanToJSON(span).atttributes` instead.
Expand Down Expand Up @@ -117,8 +110,6 @@ export class SentrySpan implements Span {
this._spanId = spanContext.spanId || uuid4().substring(16);
this._startTime = spanContext.startTimestamp || timestampInSeconds();
// eslint-disable-next-line deprecation/deprecation
this.tags = spanContext.tags ? { ...spanContext.tags } : {};
// eslint-disable-next-line deprecation/deprecation
this.data = spanContext.data ? { ...spanContext.data } : {};

this._attributes = {};
Expand Down Expand Up @@ -328,21 +319,6 @@ export class SentrySpan implements Span {
return childSpan;
}

/**
* Sets the tag attribute on the current span.
*
* Can also be used to unset a tag, by passing `undefined`.
*
* @param key Tag key
* @param value Tag value
* @deprecated Use `setAttribute()` instead.
*/
public setTag(key: string, value: Primitive): this {
// eslint-disable-next-line deprecation/deprecation
this.tags = { ...this.tags, [key]: value };
return this;
}

/**
* Sets the data attribute on the current span
* @param key Data key
Expand Down Expand Up @@ -439,8 +415,6 @@ export class SentrySpan implements Span {
spanId: this._spanId,
startTimestamp: this._startTime,
status: this._status,
// eslint-disable-next-line deprecation/deprecation
tags: this.tags,
traceId: this._traceId,
});
}
Expand Down Expand Up @@ -471,8 +445,6 @@ export class SentrySpan implements Span {
span_id: this._spanId,
start_timestamp: this._startTime,
status: getStatusMessage(this._status),
// eslint-disable-next-line deprecation/deprecation
tags: Object.keys(this.tags).length > 0 ? this.tags : undefined,
timestamp: this._endTime,
trace_id: this._traceId,
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
},
spans,
start_timestamp: this._startTime,
// eslint-disable-next-line deprecation/deprecation
tags: this.tags,
timestamp: this._endTime,
transaction: this._name,
type: 'transaction',
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/utils/spanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ export const TRACE_FLAG_SAMPLED = 0x1;
*/
export function spanToTraceContext(span: Span): TraceContext {
const { spanId: span_id, traceId: trace_id } = span.spanContext();
const { data, op, parent_span_id, status, tags, origin } = spanToJSON(span);
const { data, op, parent_span_id, status, origin } = spanToJSON(span);

return dropUndefinedKeys({
data,
op,
parent_span_id,
span_id,
status,
tags,
trace_id,
origin,
});
Expand Down
5 changes: 0 additions & 5 deletions packages/profiling-node/test/hubextensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { __PRIVATE__wrapStartTransactionWithProfiling } from '../src/hubextensio
function makeTransactionMock(options = {}): Transaction {
return {
metadata: {},
tags: {},
sampled: true,
contexts: {},
startChild: () => ({ end: () => void 0 }),
Expand All @@ -29,10 +28,6 @@ function makeTransactionMock(options = {}): Transaction {
// @ts-expect-error - contexts is private
this.contexts[key] = context;
},
setTag(this: Transaction, key: string, value: any) {
// eslint-disable-next-line deprecation/deprecation
this.tags[key] = value;
},
setMetadata(this: Transaction, metadata: Partial<TransactionMetadata>) {
// eslint-disable-next-line deprecation/deprecation
this.metadata = { ...metadata } as TransactionMetadata;
Expand Down
37 changes: 9 additions & 28 deletions packages/tracing-internal/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable max-lines */
import type { SentrySpan } from '@sentry/core';
import { getActiveSpan, startInactiveSpan } from '@sentry/core';
import { setMeasurement } from '@sentry/core';
import type { Measurements, Span, StartSpanOptions } from '@sentry/types';
Expand Down Expand Up @@ -445,15 +444,11 @@ function _trackNavigator(span: Span): void {
const connection = navigator.connection;
if (connection) {
if (connection.effectiveType) {
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag('effectiveConnectionType', connection.effectiveType);
span.setAttribute('effectiveConnectionType', connection.effectiveType);
}

if (connection.type) {
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag('connectionType', connection.type);
span.setAttribute('connectionType', connection.type);
}

if (isMeasurementValue(connection.rtt)) {
Expand All @@ -462,15 +457,11 @@ function _trackNavigator(span: Span): void {
}

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

if (isMeasurementValue(navigator.hardwareConcurrency)) {
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag('hardwareConcurrency', String(navigator.hardwareConcurrency));
span.setAttribute('hardwareConcurrency', String(navigator.hardwareConcurrency));
}
}

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

if (_lcpEntry.element) {
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag('lcp.element', htmlTreeAsString(_lcpEntry.element));
span.setAttribute('lcp.element', htmlTreeAsString(_lcpEntry.element));
}

if (_lcpEntry.id) {
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag('lcp.id', _lcpEntry.id);
span.setAttribute('lcp.id', _lcpEntry.id);
}

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

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

// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift
if (_clsEntry && _clsEntry.sources) {
DEBUG_BUILD && logger.log('[Measurements] Adding CLS Data');
_clsEntry.sources.forEach((source, index) =>
// TODO: Can we rewrite this to an attribute?
// eslint-disable-next-line deprecation/deprecation
(span as SentrySpan).setTag(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
span.setAttribute(`cls.source.${index + 1}`, htmlTreeAsString(source.node)),
);
}
}
Expand Down
7 changes: 0 additions & 7 deletions packages/types/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export interface SpanJSON {
span_id: string;
start_timestamp: number;
status?: string;
tags?: { [key: string]: Primitive };
timestamp?: number;
trace_id: string;
origin?: SpanOrigin;
Expand Down Expand Up @@ -132,12 +131,6 @@ export interface SpanContext {
*/
traceId?: string | undefined;

/**
* Tags of the Span.
* @deprecated Pass `attributes` instead.
*/
tags?: { [key: string]: Primitive };

/**
* Data of the Span.
* @deprecated Pass `attributes` instead.
Expand Down
8 changes: 1 addition & 7 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Context } from './context';
import type { DynamicSamplingContext } from './envelope';
import type { MeasurementUnit } from './measurement';
import type { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
import type { ExtractedNodeRequestData, WorkerLocation } from './misc';
import type { PolymorphicRequest } from './polymorphics';
import type { Span, SpanAttributes, SpanContext } from './span';

Expand Down Expand Up @@ -81,12 +81,6 @@ export interface Transaction extends Omit<TransactionContext, 'name' | 'op'>, Sp
*/
startTimestamp: number;

/**
* Tags for the transaction.
* @deprecated Use `getSpanAttributes(transaction)` instead.
*/
tags: { [key: string]: Primitive };

/**
* Data for the transaction.
* @deprecated Use `getSpanAttributes(transaction)` instead.
Expand Down

0 comments on commit 0fe7370

Please sign in to comment.