feat: add PostHog event tracking for SDK installs (ENG-2277) - #141
feat: add PostHog event tracking for SDK installs (ENG-2277)#141devin-ai-integration[bot] wants to merge 5 commits into
Conversation
- Create lightweight PostHog client using httpx (no external dependencies) - Track 'Installed SDK' event once per new version via ~/.blaxel/telemetry.json - Inject __posthog_key__ at build time via sed in CI workflows - Fire-and-forget async capture, respects DO_NOT_TRACK and config.yaml - Anonymous UUID as distinct_id (generated via uuid.uuid4) Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…ding Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
Co-Authored-By: tcrochet <tcrochet@blaxel.ai>
|
❌ Cannot revive Devin session - the session is too old. Please start a new session instead. |
…i-sdk-installs-posthog
🧪 Testing GuideWhat this PR addressesAdds lightweight PostHog event tracking to the Python SDK that fires an "Installed SDK" event once per new SDK version. It uses Steps to reproduce / exercise the new behavior
What to verify (expected behavior)
Note Posted by PR Testing Guide · Tag @mendral-app with feedback. |
Summary
Adds lightweight PostHog event tracking to the Python SDK to fire an "Installed SDK" event once per new SDK version. Mirrors the existing Sentry pattern — no external PostHog library, uses
httpx(already a dependency) for a raw HTTP POST tohttps://us.i.posthog.com/capture/.How it works:
track_sdk_installed()is called duringautoload()(gated behindsettings.tracking)~/.blaxel/telemetry.json— only fires once per SDK version__posthog_key__placeholder in__init__.pyis injected at build time viasedin CI (same pattern as__sentry_dsn__)distinct_id, persisted intelemetry.jsonReview & Testing Checklist for Human
POSTHOG_KEYsecret in the repo'sreleaseenvironment before the next release — without it, tracking is silently disabled (no build failure)posthog.pydoesimport blaxelinside_get_posthog_key()which is called fromtrack_sdk_installed()duringautoload(), itself called fromblaxel.__init__. The lazy call timing should be safe (same pattern assettings.sentry_dsn), but worth a manualpython -c "import blaxel.core"checktelemetry.jsonconcurrent access is acceptable: no file lock is used when reading/writing the shared state file — concurrent CLI + SDK runs could race, but worst case is a duplicate event (matches existing CLI pattern)__posthog_key__in the built package is replaced with the actual key valueNotes
httpxis already a core dependency — no new packages addedtelemetry.jsonis shared between CLI and all SDKs (Python, TypeScript) — thesdks.pythonkey tracks the last reported Python SDK versionsettings.trackingdefaults toFalse), consistent with the existing Sentry behaviorLink to Devin session: https://app.devin.ai/sessions/43a6073c1fe54dbfb87b42e3dc01db56
Requested by: @Grotoma
Note
Adds a new commit that makes telemetry delivery reliable: state is now only persisted to disk after PostHog confirms receipt (via an
on_completecallback), with in-memory deduplication using_pending_sdk_versionsto prevent concurrent duplicate sends. Comprehensive tests cover delivery failure retry, deduplication, and state preservation.Written by Mendral for commit 18db14c.