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
- Log in to PostHog and open your project
- Go to Settings > Project Settings
- Copy your Project ID (a numeric value like
12345)
Create a Personal API Key
- In PostHog, go to Settings > Personal API Keys
- Click Create personal API key
- Enter a descriptive name (e.g., "Sazabi Backend")
- Under scopes, select query:read to enable HogQL queries
- 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
- Click Add backend and select PostHog
- Enter your Personal API Key
- Enter your Project ID
- 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
- US Cloud:
- Click Test connection to verify your credentials
- Click Save to enable the backend
Required permissions
The Personal API Key needs the following scope:
| Scope | Purpose |
|---|---|
query:read | Execute 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 100Limitations
- 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:
| Mode | Data flow | Use case |
|---|---|---|
| Data Source | PostHog events are forwarded to Sazabi | Unified storage, cross-source correlation |
| Backend | Sazabi queries PostHog directly | Keep 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
logstable 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