feat: add PostHog analytics integration - #34
Closed
posthog[bot] wants to merge 1 commit into
Closed
Conversation
Generated-By: PostHog Code Task-Id: c01db094-bdb8-4598-a7d5-b49937182a01
requie
marked this pull request as ready for review
July 25, 2026 17:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds PostHog analytics to the reference SessionExporter receiver (
examples/exporter_receiver/) using theposthogPython SDK. The integration is purely additive — no existing code was removed or restructured.examples/exporter_receiver/config.py— new Pydantic Settings class with@lru_cache-decoratedget_settings(), readingPOSTHOG_PROJECT_TOKEN,POSTHOG_HOST,POSTHOG_DISABLED, andDEBUG(defaults.envvia pydantic-settings)examples/exporter_receiver/app.py— PostHog client initialized in a FastAPIlifespan,_ph_capture()helper, and capture calls across the session lifecycleexamples/exporter_receiver/requirements.txt— addsposthog>=3.0.0andpydantic-settings>=2.0.0.gitignore— adds.envInstrumented events:
session_startedPOST /sessionsadapter_name,has_agent_id(distinct id =agent_id, falls back tosession_id)event_receivedPOST /sessions/{id}/eventsevent_type,is_orphan,adapter_name,event_countsession_endedPOST /sessions/{id}/endevents_count,evaluations_count,chain_hash_linked,had_known_session,adapter_nameschema_validation_failedendpoint,error_count(distinct id =agentegrity-receiver)Insights and dashboards created
How to verify
pip install -r examples/exporter_receiver/requirements.txt.env, whichconfig.pyreads via pydantic-settings).uvicorn examples.exporter_receiver.app:app --host 0.0.0.0 --port 8787POST /sessions, one or morePOST /sessions/{id}/events, thenPOST /sessions/{id}/end.session_started,event_received, andsession_endedevents should arrive within a minute. The wizard's dashboard populates as data lands.To run the receiver's own test suite without sending data, leave the env vars unset — the lifespan skips client initialization when
POSTHOG_PROJECT_TOKENis absent and stays silent unlessDEBUG=true:Environment variables (action needed before PostHog works)
The receiver reads its PostHog config through pydantic-settings (
examples/exporter_receiver/config.py), which loads from process environment variables and, if present, a local.envfile..envis gitignored (this is a public repo and it holds the secret project token), so the real values are not committed — they must be set in whatever environment runs the receiver. There is no committed production deployment file (no Dockerfile, compose, Procfile, or hosting-provider config), so these cannot be wired automatically.Set these in the deployment environment (or in a local
.envnext to the app for development):POSTHOG_PROJECT_TOKENphc_CB2X8coGQ6k83TRRoyMcJnMRxbFr4QPzi4eD6BaAUNeoPOSTHOG_HOSThttps://us.i.posthog.comOptional:
POSTHOG_DISABLEDtrueDEBUGtruePOSTHOG_PROJECT_TOKENis missing; silent otherwiseAdd them wherever you inject runtime config for this service (compose file, systemd unit, task definition, Kubernetes secret, or hosting dashboard) and redeploy. PostHog will not receive any data until
POSTHOG_PROJECT_TOKENandPOSTHOG_HOSTare set.Created with PostHog Code