Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/metrics/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/metrics/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types-hoist/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Metric {
/**
* The value of the metric.
*/
value: number | string;
value: number;

/**
* The type of metric.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion packages/core/test/lib/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down