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.

834 B
Raw Blame
/**
 * A trace or span id in the form the events hold it, or null when the row carries none.
 *
 * Spans read their ids back as uppercase hex while the SDKs write them lowercase. An id of all
 * zeros is OpenTelemetry's "no id" sentinel, and it arrives as a string like any other, so a
 * caller that only checks for a value would match every uninstrumented row to it.
 * Stored trace and span ids are always whole bytes of hex, so any other value is null too. Event
 * properties such as `$trace_id` accept any string, and callers put the id into URLs and API paths.
 */
export function usableId(value: string | null | undefined): string | null {
    if (!value) {
        return null
    }
    const normalized = value.toLowerCase()
    return /^(?:[0-9a-f]{2})+$/.test(normalized) && !/^0+$/.test(normalized) ? normalized : null
}