diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 6a269a969c8d..e0294ef26c59 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -1521,12 +1521,8 @@ function estimateMetricSizeInBytes(metric: Metric): number { weight += metric.name.length * 2; } - // Add weight for the value - if (typeof metric.value === 'string') { - weight += metric.value.length * 2; - } else { - weight += 8; // number - } + // Add weight for number + weight += 8; return weight + estimateAttributesSizeInBytes(metric.attributes); } diff --git a/packages/core/src/metrics/internal.ts b/packages/core/src/metrics/internal.ts index 676814f4d4e6..f8e40b5fc0b4 100644 --- a/packages/core/src/metrics/internal.ts +++ b/packages/core/src/metrics/internal.ts @@ -201,7 +201,7 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal const serializedMetric: SerializedMetric = { timestamp: timestampInSeconds(), - trace_id: traceId, + trace_id: traceId ?? '', span_id: spanId, name: processedMetric.name, type: processedMetric.type, diff --git a/packages/core/src/metrics/public-api.ts b/packages/core/src/metrics/public-api.ts index e508fcb9e6d0..7dcfe74dfdb0 100644 --- a/packages/core/src/metrics/public-api.ts +++ b/packages/core/src/metrics/public-api.ts @@ -30,7 +30,7 @@ export interface MetricOptions { * @param value - The value of the metric. * @param options - Options for capturing the metric. */ -function captureMetric(type: MetricType, name: string, value: number | string, options?: MetricOptions): void { +function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void { _INTERNAL_captureMetric( { type, name, value, unit: options?.unit, attributes: options?.attributes }, { scope: options?.scope }, diff --git a/packages/core/src/types-hoist/metric.ts b/packages/core/src/types-hoist/metric.ts index 9201243c4a38..6ac63da6032b 100644 --- a/packages/core/src/types-hoist/metric.ts +++ b/packages/core/src/types-hoist/metric.ts @@ -9,7 +9,7 @@ export interface Metric { /** * The value of the metric. */ - value: number | string; + value: number; /** * The type of metric. @@ -42,7 +42,7 @@ export interface SerializedMetric { /** * The trace ID for this metric. */ - trace_id?: string; + trace_id: string; /** * The span ID for this metric. @@ -67,7 +67,7 @@ export interface SerializedMetric { /** * The value of the metric. */ - value: number | string; + value: number; /** * Arbitrary structured data that stores information about the metric. diff --git a/packages/core/test/lib/client.test.ts b/packages/core/test/lib/client.test.ts index ae324aa40f9f..d50d6da911b8 100644 --- a/packages/core/test/lib/client.test.ts +++ b/packages/core/test/lib/client.test.ts @@ -2763,7 +2763,10 @@ describe('Client', () => { // Create large metrics that will exceed the 800KB threshold const largeValue = 'x'.repeat(400_000); // 400KB string - _INTERNAL_captureMetric({ name: 'large_metric', value: largeValue, type: 'counter', attributes: {} }, { scope }); + _INTERNAL_captureMetric( + { name: 'large_metric', value: 1, type: 'counter', attributes: { large_value: largeValue } }, + { scope }, + ); expect(sendEnvelopeSpy).toHaveBeenCalledTimes(1); });