Skip to content

Commit 60a7d65

Browse files
authored
Revert "feat(core): Add metric summaries to spans (#10432)" (#10495)
This reverts commit 94cdd8b. I mistakenly merged this - we have to fix the metric summaries format. Summaries are typed as `pub type MetricSummaryMapping = Object<Array<MetricSummary>>;` Which means that the `_metrics_summary` type needs to be `_metrics_summary?: Record<string, Array<MetricSummary>>;`. This is because we need to create separate entries if the tags have changed. ``` "c:processor.item_processed": [ { "min": 1, "max": 1, "count": 3, "sum": 3, "tags": {"success": true} }, { "min": 1, "max": 1, "count": 2, "sum": 2, "tags": {"success": false} } ], ```
1 parent 2227b27 commit 60a7d65

File tree

10 files changed

+15
-250
lines changed

10 files changed

+15
-250
lines changed

dev-packages/node-integration-tests/suites/tracing/metric-summaries/scenario.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

dev-packages/node-integration-tests/suites/tracing/metric-summaries/test.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

packages/core/src/metrics/aggregator.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import type {
66
Primitive,
77
} from '@sentry/types';
88
import { timestampInSeconds } from '@sentry/utils';
9-
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
9+
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
1010
import { METRIC_MAP } from './instance';
11-
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
1211
import type { MetricBucket, MetricType } from './types';
1312
import { getBucketKey, sanitizeTags } from './utils';
1413

@@ -63,11 +62,7 @@ export class MetricsAggregator implements MetricsAggregatorBase {
6362
const tags = sanitizeTags(unsanitizedTags);
6463

6564
const bucketKey = getBucketKey(metricType, name, unit, tags);
66-
6765
let bucketItem = this._buckets.get(bucketKey);
68-
// If this is a set metric, we need to calculate the delta from the previous weight.
69-
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;
70-
7166
if (bucketItem) {
7267
bucketItem.metric.add(value);
7368
// TODO(abhi): Do we need this check?
@@ -87,10 +82,6 @@ export class MetricsAggregator implements MetricsAggregatorBase {
8782
this._buckets.set(bucketKey, bucketItem);
8883
}
8984

90-
// If value is a string, it's a set metric so calculate the delta from the previous weight.
91-
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
92-
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);
93-
9485
// We need to keep track of the total weight of the buckets so that we can
9586
// flush them when we exceed the max weight.
9687
this._bucketsTotalWeight += bucketItem.metric.weight;

packages/core/src/metrics/browser-aggregator.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import type { Client, ClientOptions, MeasurementUnit, MetricsAggregator, Primitive } from '@sentry/types';
1+
import type {
2+
Client,
3+
ClientOptions,
4+
MeasurementUnit,
5+
MetricBucketItem,
6+
MetricsAggregator,
7+
Primitive,
8+
} from '@sentry/types';
29
import { timestampInSeconds } from '@sentry/utils';
3-
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
10+
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
411
import { METRIC_MAP } from './instance';
5-
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
612
import type { MetricBucket, MetricType } from './types';
713
import { getBucketKey, sanitizeTags } from './utils';
814

@@ -40,33 +46,24 @@ export class BrowserMetricsAggregator implements MetricsAggregator {
4046
const tags = sanitizeTags(unsanitizedTags);
4147

4248
const bucketKey = getBucketKey(metricType, name, unit, tags);
43-
44-
let bucketItem = this._buckets.get(bucketKey);
45-
// If this is a set metric, we need to calculate the delta from the previous weight.
46-
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;
47-
49+
const bucketItem: MetricBucketItem | undefined = this._buckets.get(bucketKey);
4850
if (bucketItem) {
4951
bucketItem.metric.add(value);
5052
// TODO(abhi): Do we need this check?
5153
if (bucketItem.timestamp < timestamp) {
5254
bucketItem.timestamp = timestamp;
5355
}
5456
} else {
55-
bucketItem = {
57+
this._buckets.set(bucketKey, {
5658
// @ts-expect-error we don't need to narrow down the type of value here, saves bundle size.
5759
metric: new METRIC_MAP[metricType](value),
5860
timestamp,
5961
metricType,
6062
name,
6163
unit,
6264
tags,
63-
};
64-
this._buckets.set(bucketKey, bucketItem);
65+
});
6566
}
66-
67-
// If value is a string, it's a set metric so calculate the delta from the previous weight.
68-
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
69-
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);
7067
}
7168

7269
/**

packages/core/src/metrics/metric-summary.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

packages/core/src/tracing/span.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
1717

1818
import { DEBUG_BUILD } from '../debug-build';
19-
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
2019
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
2120
import { getRootSpan } from '../utils/getRootSpan';
2221
import {
@@ -625,7 +624,6 @@ export class Span implements SpanInterface {
625624
timestamp: this._endTime,
626625
trace_id: this._traceId,
627626
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
628-
_metrics_summary: getMetricSummaryJsonForSpan(this),
629627
});
630628
}
631629

packages/core/src/tracing/transaction.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { dropUndefinedKeys, logger } from '@sentry/utils';
1515
import { DEBUG_BUILD } from '../debug-build';
1616
import type { Hub } from '../hub';
1717
import { getCurrentHub } from '../hub';
18-
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
1918
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
2019
import { spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
2120
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
@@ -332,7 +331,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
332331
capturedSpanIsolationScope,
333332
dynamicSamplingContext: getDynamicSamplingContextFromSpan(this),
334333
},
335-
_metrics_summary: getMetricSummaryJsonForSpan(this),
336334
...(source && {
337335
transaction_info: {
338336
source,

packages/types/src/event.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { Request } from './request';
1111
import type { CaptureContext } from './scope';
1212
import type { SdkInfo } from './sdkinfo';
1313
import type { Severity, SeverityLevel } from './severity';
14-
import type { MetricSummary, Span, SpanJSON } from './span';
14+
import type { Span, SpanJSON } from './span';
1515
import type { Thread } from './thread';
1616
import type { TransactionSource } from './transaction';
1717
import type { User } from './user';
@@ -73,7 +73,6 @@ export interface ErrorEvent extends Event {
7373
}
7474
export interface TransactionEvent extends Event {
7575
type: 'transaction';
76-
_metrics_summary?: Record<string, MetricSummary>;
7776
}
7877

7978
/** JSDoc */

packages/types/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export type {
9999
SpanJSON,
100100
SpanContextData,
101101
TraceFlag,
102-
MetricSummary,
103102
} from './span';
104103
export type { StackFrame } from './stackframe';
105104
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
@@ -151,9 +150,5 @@ export type {
151150

152151
export type { BrowserClientReplayOptions, BrowserClientProfilingOptions } from './browseroptions';
153152
export type { CheckIn, MonitorConfig, FinishedCheckIn, InProgressCheckIn, SerializedCheckIn } from './checkin';
154-
export type {
155-
MetricsAggregator,
156-
MetricBucketItem,
157-
MetricInstance,
158-
} from './metrics';
153+
export type { MetricsAggregator, MetricBucketItem, MetricInstance } from './metrics';
159154
export type { ParameterizedString } from './parameterize';

packages/types/src/span.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ export type SpanAttributes = Partial<{
3131
}> &
3232
Record<string, SpanAttributeValue | undefined>;
3333

34-
export type MetricSummary = {
35-
min: number;
36-
max: number;
37-
count: number;
38-
sum: number;
39-
tags?: Record<string, Primitive> | undefined;
40-
};
41-
4234
/** This type is aligned with the OpenTelemetry TimeInput type. */
4335
export type SpanTimeInput = HrTime | number | Date;
4436

@@ -55,7 +47,6 @@ export interface SpanJSON {
5547
timestamp?: number;
5648
trace_id: string;
5749
origin?: SpanOrigin;
58-
_metrics_summary?: Record<string, MetricSummary>;
5950
}
6051

6152
// These are aligned with OpenTelemetry trace flags

0 commit comments

Comments
 (0)