Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

725 B
Raw Blame
import type { LogRecord } from './log-record-avro'

export const MAX_LOG_RECORD_BYTES = 1024 * 1024

export function logRecordSizeBytes(
    record: Pick<LogRecord, 'body' | 'severity_text' | 'attributes' | 'resource_attributes'>
): number {
    let bytes = 0
    for (const value of [record.body, record.severity_text]) {
        if (typeof value === 'string') {
            bytes += Buffer.byteLength(value)
        }
    }
    for (const attributes of [record.attributes, record.resource_attributes]) {
        if (attributes) {
            for (const [key, value] of Object.entries(attributes)) {
                bytes += Buffer.byteLength(key) + Buffer.byteLength(value)
            }
        }
    }
    return bytes
}