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.

982 B
Raw Blame
import api from 'lib/api'
import { createSetupDetectionLogic } from 'lib/components/ProductEmptyState/setupDetectionLogic'
import { retryWithBackoff } from 'lib/utils/async'

import { ProductKey } from '~/queries/schema/schema-general'

/**
 * Setup detection for the logs empty state. Binary: the team has ingested at
 * least one log line, or it hasn't - there is no "instrumented but quiet"
 * signal to read, so no waiting-for-data state.
 */
export const logsSetupLogic = createSetupDetectionLogic({
    productKey: ProductKey.LOGS,
    path: ['products', 'logs', 'frontend', 'emptyState', 'logsSetupLogic'],
    detect: async () => {
        const hasLogs = await retryWithBackoff(() => api.logs.hasLogs(), { maxAttempts: 3 })
        return hasLogs ? 'has-data' : 'needs-setup'
    },
    // The first log usually lands moments after the collector restarts, so
    // re-check often enough for the flip to feel immediate.
    pollIntervalMs: 5000,
    cacheHasData: true,
})