MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / estimateAttributesSizeInBytes

Function estimateAttributesSizeInBytes

packages/core/src/client.ts:1797–1816  ·  view source on GitHub ↗

* Estimate the size of attributes in bytes. * * @param attributes - The attributes object to estimate the size of. * @returns The estimated size of the attributes in bytes.

(attributes: Record<string, unknown> | undefined)

Source from the content-addressed store, hash-verified

1795 * @returns The estimated size of the attributes in bytes.
1796 */
1797function estimateAttributesSizeInBytes(attributes: Record<string, unknown> | undefined): number {
1798 if (!attributes) {
1799 return 0;
1800 }
1801
1802 let weight = 0;
1803
1804 Object.values(attributes).forEach(value => {
1805 if (Array.isArray(value)) {
1806 weight += value.length * estimatePrimitiveSizeInBytes(value[0]);
1807 } else if (isPrimitive(value)) {
1808 weight += estimatePrimitiveSizeInBytes(value);
1809 } else {
1810 // For objects values, we estimate the size of the object as 100 bytes
1811 weight += 100;
1812 }
1813 });
1814
1815 return weight;
1816}
1817
1818function estimatePrimitiveSizeInBytes(value: Primitive): number {
1819 if (typeof value === 'string') {

Callers 2

estimateLogSizeInBytesFunction · 0.85

Calls 4

isPrimitiveFunction · 0.90
forEachMethod · 0.65
valuesMethod · 0.65

Tested by

no test coverage detected