Sazabi
BackendsExternal Backends

PostHog

Query PostHog events and analytics directly from Sazabi without moving data.

Overview

PostHog is a product analytics platform. With Sazabi's PostHog backend, you can query your PostHog events and analytics directly from Chat, correlating product usage data with your application logs.

Prerequisites

Before you begin, make sure you have:

  • A PostHog account with project access
  • Permission to create Personal API Keys in your PostHog organization
  • Your PostHog Project ID (found in Project Settings)

What you can query

When PostHog is configured as a backend, Chat can access:

  • Logs: Query structured log data using HogQL
  • Events: Search custom and autocaptured events
  • Aggregations: Run count, group by, and other analytics queries

Queries use HogQL, PostHog's SQL dialect built on ClickHouse. Chat automatically constructs HogQL queries based on your questions.

Setup

Get your Project ID

  1. Log in to PostHog and open your project
  2. Go to Settings > Project Settings
  3. Copy your Project ID (a numeric value like 12345)

Create a Personal API Key

  1. In PostHog, go to Settings > Personal API Keys
  2. Click Create personal API key
  3. Enter a descriptive name (e.g., "Sazabi Backend")
  4. Under scopes, select query:read to enable HogQL queries
  5. Click Create key and copy the key immediately

Store your API key securely. PostHog only displays it once. If you lose it, you will need to create a new key.

Configure in Sazabi

  1. Click Add backend and select PostHog
  2. Enter your Personal API Key
  3. Enter your Project ID
  4. Select your API Host:
    • US Cloud: app.posthog.com (default for most users)
    • EU Cloud: eu.posthog.com (for EU-hosted projects)
    • Self-hosted: Enter your custom PostHog instance URL
  5. Click Test connection to verify your credentials
  6. Click Save to enable the backend

Required permissions

The Personal API Key needs the following scope:

ScopePurpose
query:readExecute HogQL queries against your project data

This is the minimum permission required. The backend only performs read operations and cannot modify your PostHog data.

Query capabilities

Chat can run HogQL queries to answer questions about your PostHog data. Example queries you can ask:

  • "Show me recent error logs from PostHog"
  • "What are the most common log levels in the last hour?"
  • "Find logs containing 'timeout' from the past day"
  • "Count errors by level for the last 24 hours"

HogQL syntax reference

Common HogQL patterns the assistant uses:

-- Recent logs
SELECT * FROM logs ORDER BY timestamp DESC LIMIT 100

-- Filter by level
SELECT * FROM logs WHERE level = 'error' LIMIT 100

-- Time range queries
SELECT * FROM logs WHERE timestamp >= now() - INTERVAL 1 HOUR

-- Aggregations
SELECT level, count() as count FROM logs GROUP BY level

-- Search in messages
SELECT * FROM logs WHERE message LIKE '%timeout%' LIMIT 100

Limitations

  • Queries time out after 30 seconds
  • Results are limited to 10,000 rows per query
  • Only read operations are supported (no data modification)
  • Session recordings and feature flags are not directly queryable through this backend

PostHog as data source vs backend

PostHog can be used as both a data source and a backend:

ModeData flowUse case
Data SourcePostHog events are forwarded to SazabiUnified storage, cross-source correlation
BackendSazabi queries PostHog directlyKeep data in PostHog, no duplication

Choose data source when you want to store events in Sazabi and correlate them with other log sources. Choose backend when you want to keep data in PostHog and query it on demand.

Troubleshooting

Connection test fails with 401

Your API key is invalid or expired. Create a new Personal API Key in PostHog under Settings > Personal API Keys and ensure it has the query:read scope.

Connection test fails with 403

Your API key does not have permission to access this project. Verify the key was created with the query:read scope and has access to the project you specified.

Connection test fails with 404

The Project ID is incorrect. Go to Settings > Project Settings in PostHog and verify you are using the numeric Project ID, not the project name or slug.

Queries return no results

  • Verify you have log data in PostHog for the time range being queried
  • Check that your project has the logs table populated
  • Try a simple query like "Show me recent logs" to verify connectivity

Self-hosted connection issues

  • Ensure your PostHog instance is accessible from the internet
  • Verify the URL includes the protocol (e.g., https://posthog.example.com)
  • Check that your instance has SSL/TLS configured correctly