8000 feat(metrics)!: Update types (#17907) · getsentry/sentry-javascript@ad870cf · GitHub
[go: up one dir, main page]

Skip to content

Commit ad870cf

Browse files
authored
feat(metrics)!: Update types (#17907)
- Fixing some of the types according to the specs.
1 parent 1a7189d commit ad870cf

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

packages/core/src/client.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,8 @@ function estimateMetricSizeInBytes(metric: Metric): number {
15211521
weight += metric.name.length * 2;
15221522
}
15231523

1524-
// Add weight for the value
1525-
if (typeof metric.value === 'string') {
1526-
weight += metric.value.length * 2;
1527-
} else {
1528-
weight += 8; // number
1529-
}
1524+
// Add weight for number
1525+
weight += 8;
15301526

15311527
return weight + estimateAttributesSizeInBytes(metric.attributes);
15321528
}

packages/core/src/metrics/internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal
201201

202202
const serializedMetric: SerializedMetric = {
203203
timestamp: timestampInSeconds(),
204-
trace_id: traceId,
204+
trace_id: traceId ?? '',
205205
span_id: spanId,
206206
name: processedMetric.name,
207207
type: processedMetric.type,

packages/core/src/metrics/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface MetricOptions {
3030
* @param value - The value of the metric.
3131
* @param options - Options for capturing the metric.
3232
*/
33-
function captureMetric(type: MetricType, name: string, value: number | string, options?: MetricOptions): void {
33+
function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void {
3434
_INTERNAL_captureMetric(
3535
{ type, name, value, unit: options?.unit, attributes: options?.attributes },
3636
{ scope: options?.scope },

packages/core/src/types-hoist/metric.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Metric {
99
/**
1010
* The value of the metric.
1111
*/
12-
value: number | string;
12+
value: number;
1313

1414
/**
1515
* The type of metric.
@@ -42,7 +42,7 @@ export interface SerializedMetric {
4242
/**
4343
* The trace ID for this metric.
4444
*/
45-
trace_id?: string;
45+
trace_id: string;
4646

4747
/**
4848
* The span ID for this metric.
@@ -67,7 +67,7 @@ export interface SerializedMetric {
6767
/**
6868
* The value of the metric.
6969
*/
70-
value: number | string;
70+
value: number;
7171

7272
/**
7373
* Arbitrary structured data that stores information about the metric.

packages/core/test/lib/client.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,10 @@ describe('Client', () => {
27632763

27642764
// Create large metrics that will exceed the 800KB threshold
27652765
const largeValue = 'x'.repeat(400_000); // 400KB string
2766-
_INTERNAL_captureMetric({ name: 'large_metric', value: largeValue, type: 'counter', attributes: {} }, { scope });
2766+
_INTERNAL_captureMetric(
2767+
{ name: 'large_metric', value: 1, type: 'counter', attributes: { large_value: largeValue } },
2768+
{ scope },
2769+
);
27672770

27682771
expect(sendEnvelopeSpy).toHaveBeenCalledTimes(1);
27692772
});

0 commit comments

Comments
 (0)
0