Skip to content

Commit fd0a8cb

Browse files
committed
restore unrelated file
1 parent d99e5ad commit fd0a8cb

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

packages/core/src/metrics/internal.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,50 @@ import { createMetricEnvelope } from './envelope';
1414

1515
const MAX_METRIC_BUFFER_SIZE = 1000;
1616

17+
/**
18+
* Converts a metric attribute to a serialized metric attribute.
19+
*
20+
* @param value - The value of the metric attribute.
21+
* @returns The serialized metric attribute.
22+
*/
23+
export function metricAttributeToSerializedMetricAttribute(value: unknown): SerializedMetricAttributeValue {
24+
switch (typeof value) {
25+
case 'number':
26+
if (Number.isInteger(value)) {
27+
return {
28+
value,
29+
type: 'integer',
30+
};
31+
}
32+
return {
33+
value,
34+
type: 'double',
35+
};
36+
case 'boolean':
37+
return {
38+
value,
39+
type: 'boolean',
40+
};
41+
case 'string':
42+
return {
43+
value,
44+
type: 'string',
45+
};
46+
default: {
47+
let stringValue = '';
48+
try {
49+
stringValue = JSON.stringify(value) ?? '';
50+
} catch {
51+
// Do nothing
52+
}
53+
return {
54+
value: stringValue,
55+
type: 'string',
56+
};
57+
}
58+
}
59+
}
60+
1761
/**
1862
* Sets a metric attribute if the value exists and the attribute key is not already present.
1963
*

0 commit comments

Comments
 (0)