Skip to content

Commit

Permalink
Revert "feat(core): Add metric summaries to spans (#10432)"
Browse files Browse the repository at this point in the history
This reverts commit 94cdd8b.
  • Loading branch information
AbhiPrasad committed Feb 5, 2024
1 parent 94cdd8b commit da8e9b6
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 250 deletions.

This file was deleted.

This file was deleted.

11 changes: 1 addition & 10 deletions packages/core/src/metrics/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type {
Primitive,
} from '@sentry/types';
import { timestampInSeconds } from '@sentry/utils';
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
import { DEFAULT_FLUSH_INTERVAL, MAX_WEIGHT, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
import { METRIC_MAP } from './instance';
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
import type { MetricBucket, MetricType } from './types';
import { getBucketKey, sanitizeTags } from './utils';

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

const bucketKey = getBucketKey(metricType, name, unit, tags);

let bucketItem = this._buckets.get(bucketKey);
// If this is a set metric, we need to calculate the delta from the previous weight.
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;

if (bucketItem) {
bucketItem.metric.add(value);
// TODO(abhi): Do we need this check?
Expand All @@ -87,10 +82,6 @@ export class MetricsAggregator implements MetricsAggregatorBase {
this._buckets.set(bucketKey, bucketItem);
}

// If value is a string, it's a set metric so calculate the delta from the previous weight.
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);

// We need to keep track of the total weight of the buckets so that we can
// flush them when we exceed the max weight.
this._bucketsTotalWeight += bucketItem.metric.weight;
Expand Down
27 changes: 12 additions & 15 deletions packages/core/src/metrics/browser-aggregator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type { Client, ClientOptions, MeasurementUnit, MetricsAggregator, Primitive } from '@sentry/types';
import type {
Client,
ClientOptions,
MeasurementUnit,
MetricBucketItem,
MetricsAggregator,
Primitive,
} from '@sentry/types';
import { timestampInSeconds } from '@sentry/utils';
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX, SET_METRIC_TYPE } from './constants';
import { DEFAULT_BROWSER_FLUSH_INTERVAL, NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants';
import { METRIC_MAP } from './instance';
import { updateMetricSummaryOnActiveSpan } from './metric-summary';
import type { MetricBucket, MetricType } from './types';
import { getBucketKey, sanitizeTags } from './utils';

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

const bucketKey = getBucketKey(metricType, name, unit, tags);

let bucketItem = this._buckets.get(bucketKey);
// If this is a set metric, we need to calculate the delta from the previous weight.
const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem.metric.weight : 0;

const bucketItem: MetricBucketItem | undefined = this._buckets.get(bucketKey);
if (bucketItem) {
bucketItem.metric.add(value);
// TODO(abhi): Do we need this check?
if (bucketItem.timestamp < timestamp) {
bucketItem.timestamp = timestamp;
}
} else {
bucketItem = {
this._buckets.set(bucketKey, {
// @ts-expect-error we don't need to narrow down the type of value here, saves bundle size.
metric: new METRIC_MAP[metricType](value),
timestamp,
metricType,
name,
unit,
tags,
};
this._buckets.set(bucketKey, bucketItem);
});
}

// If value is a string, it's a set metric so calculate the delta from the previous weight.
const val = typeof value === 'string' ? bucketItem.metric.weight - previousWeight : value;
updateMetricSummaryOnActiveSpan(metricType, name, val, unit, unsanitizedTags, bucketKey);
}

/**
Expand Down
87 changes: 0 additions & 87 deletions packages/core/src/metrics/metric-summary.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';

import { DEBUG_BUILD } from '../debug-build';
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
import { getRootSpan } from '../utils/getRootSpan';
import {
Expand Down Expand Up @@ -625,7 +624,6 @@ export class Span implements SpanInterface {
timestamp: this._endTime,
trace_id: this._traceId,
origin: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined,
_metrics_summary: getMetricSummaryJsonForSpan(this),
});
}

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 @@ -15,7 +15,6 @@ import { dropUndefinedKeys, logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../debug-build';
import type { Hub } from '../hub';
import { getCurrentHub } from '../hub';
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
import { spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
Expand Down Expand Up @@ -332,7 +331,6 @@ export class Transaction extends SpanClass implements TransactionInterface {
capturedSpanIsolationScope,
dynamicSamplingContext: getDynamicSamplingContextFromSpan(this),
},
_metrics_summary: getMetricSummaryJsonForSpan(this),
...(source && {
transaction_info: {
source,
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Request } from './request';
import type { CaptureContext } from './scope';
import type { SdkInfo } from './sdkinfo';
import type { Severity, SeverityLevel } from './severity';
import type { MetricSummary, Span, SpanJSON } from './span';
import type { Span, SpanJSON } from './span';
import type { Thread } from './thread';
import type { TransactionSource } from './transaction';
import type { User } from './user';
Expand Down Expand Up @@ -73,7 +73,6 @@ export interface ErrorEvent extends Event {
}
export interface TransactionEvent extends Event {
type: 'transaction';
_metrics_summary?: Record<string, MetricSummary>;
}

/** JSDoc */
Expand Down
7 changes: 1 addition & 6 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export type {
SpanJSON,
SpanContextData,
TraceFlag,
MetricSummary,
} from './span';
export type { StackFrame } from './stackframe';
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
Expand Down Expand Up @@ -151,9 +150,5 @@ export type {

export type { BrowserClientReplayOptions, BrowserClientProfilingOptions } from './browseroptions';
export type { CheckIn, MonitorConfig, FinishedCheckIn, InProgressCheckIn, SerializedCheckIn } from './checkin';
export type {
MetricsAggregator,
MetricBucketItem,
MetricInstance,
} from './metrics';
export type { MetricsAggregator, MetricBucketItem, MetricInstance } from './metrics';
export type { ParameterizedString } from './parameterize';
9 changes: 0 additions & 9 deletions packages/types/src/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ export type SpanAttributes = Partial<{
}> &
Record<string, SpanAttributeValue | undefined>;

export type MetricSummary = {
min: number;
max: number;
count: number;
sum: number;
tags?: Record<string, Primitive> | undefined;
};

/** This type is aligned with the OpenTelemetry TimeInput type. */
export type SpanTimeInput = HrTime | number | Date;

Expand All @@ -55,7 +47,6 @@ export interface SpanJSON {
timestamp?: number;
trace_id: string;
origin?: SpanOrigin;
_metrics_summary?: Record<string, MetricSummary>;
}

// These are aligned with OpenTelemetry trace flags
Expand Down

0 comments on commit da8e9b6

Please sign in to comment.