From 387075ebe1cef98a902a5e570d519a1d892a98a3 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 10 Oct 2025 14:02:55 +0200 Subject: [PATCH 1/2] fix types --- packages/core/src/types-hoist/metric.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. From 3b7a096adcfd2c5749fa07a122034cf465537bfe Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Fri, 10 Oct 2025 14:12:20 +0200 Subject: [PATCH 2/2] update tracing_id logic and update func signature --- packages/core/src/metrics/internal.ts | 5 +++++ packages/core/src/metrics/public-api.ts | 2 +- packages/core/src/server-runtime-client.ts | 6 +----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/src/metrics/internal.ts b/packages/core/src/metrics/internal.ts index 0f16d98b790e..0c08a56ca246 100644 --- a/packages/core/src/metrics/internal.ts +++ b/packages/core/src/metrics/internal.ts @@ -199,6 +199,11 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal const traceId = span ? span.spanContext().traceId : traceContext?.trace_id; const spanId = span ? span.spanContext().spanId : undefined; + if (!traceId) { + DEBUG_BUILD && debug.warn('[Metric] No trace ID available, will not send metric.'); + return; + } + const serializedMetric: SerializedMetric = { timestamp: timestampInSeconds(), trace_id: traceId, 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/server-runtime-client.ts b/packages/core/src/server-runtime-client.ts index 761d4aca7cd7..cafb7fce3d86 100644 --- a/packages/core/src/server-runtime-client.ts +++ b/packages/core/src/server-runtime-client.ts @@ -283,11 +283,7 @@ function estimateMetricSizeInBytes(metric: Metric): number { } // Add weight for the value - if (typeof metric.value === 'string') { - weight += metric.value.length * 2; - } else { - weight += 8; // number - } + weight += 8; // number if (metric.attributes) { Object.values(metric.attributes).forEach(value => {