Repository navigation
Instrument application with PostHog - #20
Open
posthog[bot] wants to merge 1 commit into
Open
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
PostHog setup report
PostHog is installed and initialized for the FastAPI risk engine, with five successful-outcome events, automatic uncaught-exception capture, isolated OTLP log export, and a starter dashboard.
Installed and initialized
posthog>=7.69,<8inrequirements.txt; the reviewed virtual environment resolved PostHog 7.91.4.opentelemetry-api,opentelemetry-sdk, andopentelemetry-exporter-otlp; the reviewed environment resolved them at 1.45.2.core/config.pyloadsPOSTHOG_PROJECT_TOKENandPOSTHOG_HOST; both are documented in.env.exampleand were confirmed present in the local.env.layer6/api.pycreates onePosthogclient, conditionally installsPosthogASGIMiddleware, enables exception autocapture, and shuts analytics down with a five-second budget.python -m compileall core/config.py layer6/api.pypassed. No project typechecker, linter, formatter, or configured equivalent was available; no test suite or runtime delivery check was run.Events instrumented
All captures are guarded after successful engine outcomes and use aggregate technical metadata only (counts, duration, cache state, and engine availability). No event arrival was observed during this run.
asset_risk_scoredlayer6/api.pyportfolio_risk_scoredlayer6/api.pyrisk_stress_test_completedlayer6/api.pyrisk_histogram_generatedlayer6/api.pyrisk_simulation_completedlayer6/api.pyIdentification
User identification was deliberately not wired. This server-only engine receives only a shared service credential from a separate Go gateway—no trusted end-user, session, or caller-resource identifier reaches this application. Using
ENGINE_SECRETor the Authorization header as a distinct ID would collapse users onto a service identity and expose credential-derived data.Follow-up issue: stable identity is unavailable
The Go gateway must propagate a trusted stable user ID (or its established PostHog tracing identity) to this request boundary. Until then, the product events and errors remain personless, so per-user adoption, retention, and attribution cannot be meaningfully analyzed. Once that contract exists, bind it in a request-boundary dependency or middleware using
posthog_client.new_context()andidentify_context(stable_user_id).Error tracking
Global uncaught FastAPI exception capture is configured through
PosthogASGIMiddlewaretogether withenable_exception_autocapture=Trueinlayer6/api.py. No catch-all exception handler was added, avoiding duplicate exception instrumentation. Runtime exception delivery was not exercised.AI Observability
AI Observability was not applicable in this repository. No production LLM provider/client invocation exists here: the legacy
/analyzeand/chatroutes return HTTP 410, and the recorded handoff states that live model calls belong to the separate Go gateway. Consequently, no AI-generation event or privacy-mode setting was configured in this service, and no AI delivery was verified. Instrument the actual Go gateway call path in its own project if AI Observability is needed.Starter analytics dashboard
Created Analytics basics (wizard) with five 30-day daily trend views for the engine’s instrumented outcome events: asset and portfolio risk scoring, stress-test completion, histogram generation, and simulation completion. The dashboard and every insight are tagged
wizard; charts will populate as production requests emit these events.PostHog Logs
Configured an isolated OpenTelemetry log exporter for the FastAPI risk engine. It exports only the purpose-written
meteorium.posthog_logslines added in this run, not the service’s existing logs. Structured records cover engine start/stop plus successful asset and portfolio scoring outcomes, with technical aggregate metadata only (for example duration, cache state, and counts); they exclude request bodies, secrets, asset IDs, locations, and user data.Install
opentelemetry-api,opentelemetry-sdk, andopentelemetry-exporter-otlpduring review, then trigger an authenticated successfulPOST /risk/assetand findasset_risk_scoring_completedin PostHog Logs. Delivery remains unverified until that observation. To export existing application logs later, deliberately attach the configuredLoggingHandlerto the selected existing logger or root logger; that broader export was intentionally not enabled here.Final review state
The OpenTelemetry dependencies named above were subsequently added to
requirements.txtand installed during review, so no further package installation is required. Runtime event, exception, and log delivery remain unconfirmed because the application was not exercised against PostHog. No build conflict was reported; the review made one safe-delivery fix inlayer6/api.py, replacing a boundedforce_flush()plus unbounded shutdown withshutdown(timeout_millis=5000).MCP analytics
MCP analytics was not configured because no MCP server was detected within this project scope.
Before you merge
core/config.pyandlayer6/api.py.POSTHOG_PROJECT_TOKENandPOSTHOG_HOSTfrom.env.exampleare set in every deployment environment—not only local.env—and inspect the configuration additions incore/config.pyand initialization inlayer6/api.py.layer6/api.pyand confirm all five listed events arrive in PostHog; compilation does not demonstrate ingestion.layer6/api.pyand confirm it appears in PostHog error tracking.POST /risk/assetand confirm theasset_risk_scoring_completedentry fromlayer6/api.pyappears in PostHog Logs with its expected service and severity.layer6/api.py; do not useENGINE_SECRETor Authorization as the distinct ID.