-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracemetrics)!: Update types #17907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,79 @@ function setCurrentRequestSessionErroredOrCrashed(eventHint?: EventHint): void { | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Estimate the size of a metric in bytes. | ||
* | ||
* @param metric - The metric to estimate the size of. | ||
* @returns The estimated size of the metric in bytes. | ||
*/ | ||
function estimateMetricSizeInBytes(metric: Metric): number { | ||
let weight = 0; | ||
|
||
// Estimate byte size of 2 bytes per character. This is a rough estimate JS strings are stored as UTF-16. | ||
if (metric.name) { | ||
weight += metric.name.length * 2; | ||
} | ||
|
||
// Add weight for the value | ||
weight += 8; // number | ||
|
||
if (metric.attributes) { | ||
Object.values(metric.attributes).forEach(value => { | ||
if (Array.isArray(value)) { | ||
weight += value.length * estimatePrimitiveSizeInBytes(value[0]); | ||
} else if (isPrimitive(value)) { | ||
weight += estimatePrimitiveSizeInBytes(value); | ||
} else { | ||
// For objects values, we estimate the size of the object as 100 bytes | ||
weight += 100; | ||
} | ||
}); | ||
} | ||
|
||
return weight; | ||
} | ||
|
||
/** | ||
* Estimate the size of a log in bytes. | ||
* | ||
* @param log - The log to estimate the size of. | ||
* @returns The estimated size of the log in bytes. | ||
*/ | ||
function estimateLogSizeInBytes(log: Log): number { | ||
let weight = 0; | ||
|
||
// Estimate byte size of 2 bytes per character. This is a rough estimate JS strings are stored as UTF-16. | ||
if (log.message) { | ||
weight += log.message.length * 2; | ||
} | ||
|
||
if (log.attributes) { | ||
Object.values(log.attributes).forEach(value => { | ||
if (Array.isArray(value)) { | ||
weight += value.length * estimatePrimitiveSizeInBytes(value[0]); | ||
} else if (isPrimitive(value)) { | ||
weight += estimatePrimitiveSizeInBytes(value); | ||
} else { | ||
// For objects values, we estimate the size of the object as 100 bytes | ||
weight += 100; | ||
} | ||
}); | ||
} | ||
|
||
return weight; | ||
} | ||
|
||
function estimatePrimitiveSizeInBytes(value: Primitive): number { | ||
if (typeof value === 'string') { | ||
return value.length * 2; | ||
} else if (typeof value === 'number') { | ||
return 8; | ||
} else if (typeof value === 'boolean') { | ||
return 4; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unused Functions Cause Compilation ErrorsThe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do this for logs. When can this ever happen?