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.

678 B
Raw Blame
const CUSTOM_METADATA_MARKER = 'posthog_'
const RESERVED_CUSTOM_NAMES = new Set(['distinct_id', '__proto__'])

export function promotePosthogCustomMetadata(props: Record<string, unknown>, namespacePrefix: string): void {
    const prefix = `${namespacePrefix}${CUSTOM_METADATA_MARKER}`
    for (const key of Object.keys(props)) {
        if (!key.startsWith(prefix)) {
            continue
        }
        const name = key.slice(prefix.length)
        if (!name || name.startsWith('$') || RESERVED_CUSTOM_NAMES.has(name)) {
            continue
        }
        if (!Object.prototype.hasOwnProperty.call(props, name)) {
            props[name] = props[key]
        }
    }
}