NewEvent icon
Script icon
Loop icon
EvaluateFeatureFlag icon
Switch icon
Log icon
Capture icon
Write icon
If icon
SlackIncomingWebhook icon
Fail icon

PostHog Error Burst and Feature Flag Blast Radius Incident Gate

Correlate PostHog error event spikes with active feature flags, evaluate affected user blast radius, and automate release rollback triage.

Categories
Infrastructure

Automates real-time incident triage and release regression detection by correlating PostHog client error bursts with active feature flag rollouts. When frontend exceptions or API rejections suddenly surge in production, engineering teams lose critical minutes trying to determine whether a newly deployed feature flag is the culprit or if a backend database is degrading. This blueprint leverages PostHog's event-driven NewEvent trigger to capture error surges, evaluates the target feature flag state across all affected users, computes statistical causality, and gates automated CD pipelines when blast radius thresholds breach.

How it works

  1. An event-driven io.kestra.plugin.posthog.NewEvent trigger polls the PostHog Query API every 5 minutes for newly captured $exception events across production client sessions.
  2. extract_error_cluster (io.kestra.plugin.scripts.python.Script) parses the event payload, extracts distinct user identifiers (distinctId), groups error signatures, and checks whether overall error volume breaches min_error_count.
  3. audit_user_feature_flags (io.kestra.plugin.core.flow.Loop) iterates through each affected distinct ID, querying io.kestra.plugin.posthog.EvaluateFeatureFlag to discover whether the target flag (flag_key) was enabled for that user session, surfacing each iteration's result via the Loop task's outputs declaration.
  4. correlate_blast_radius (io.kestra.plugin.scripts.python.Script) calculates the percentage of failing users who have the feature flag enabled. If this correlation meets or exceeds correlation_threshold_pct (default 70%), the workflow attributes causality to the flag rollout.
  5. route_incident_action (io.kestra.plugin.core.flow.Switch) routes downstream actions based on the classified verdict:
    • FLAG_CORRELATED_REGRESSION: Emits a feature_flag_regression_detected telemetry marker back into PostHog via io.kestra.plugin.posthog.Capture, persists an incident dossier to internal storage, logs a critical alert, and dispatches a Slack block alert.
    • ORGANIC_INFRASTRUCTURE_SURGE: Exonerates the feature flag and logs an infrastructure investigation notice.
    • BASELINE_LOW_SEVERITY: Acknowledges normal background error noise under threshold.
  6. enforce_release_gate (io.kestra.plugin.core.flow.If) halts execution via io.kestra.plugin.core.execution.Fail when gate_on_regression is enabled and a flag regression is confirmed.

What you get

  • Automated blast radius correlation linking production client errors directly to specific feature flag rollouts.
  • Elimination of release war-room guesswork by distinguishing feature flag bugs from general infrastructure outages.
  • Closed-loop telemetry annotation via PostHog Capture, linking Kestra execution IDs directly to PostHog session insights.
  • Structured incident dossiers persisted to internal storage (kestra://...) for seamless post-mortem analysis.
  • Automated CD deployment gating that prevents buggy flags from advancing to wider rollout cohorts.

Who it's for

  • Release Engineers and SREs managing progressive canary deployments and feature flag rollouts.
  • Full-Stack and Frontend Engineering teams monitoring production client-side runtime health.
  • Platform Operations teams implementing automated self-healing and deployment rollback gates.

Why orchestrate this with Kestra

  • Declarative combination of PostHog's stateful trigger, user-level flag evaluation, and event capture without maintaining custom webhook microservices.
  • Built-in containerized Python execution for statistical analysis without needing dedicated analytics workers.
  • Secure credential management masking PostHog personal and project API keys across automated incident workflows.

Prerequisites

  • A PostHog project with client exception tracking enabled (e.g. PostHog JS SDK $exception autocapture or custom exception events).
  • A feature flag configured in PostHog under active progressive rollout.

Secrets

  • POSTHOG_PERSONAL_API_KEY: PostHog personal API key with Query Read permissions used by the NewEvent trigger.
  • POSTHOG_PROJECT_ID: Numeric PostHog project identifier used by the NewEvent trigger.
  • POSTHOG_API_KEY: PostHog project API key (phc_...) used by EvaluateFeatureFlag and Capture tasks.
  • SLACK_WEBHOOK_URL: Optional Slack webhook URL for dispatching incident triage alerts (required only if notify_slack is enabled).

Quick start

  1. Import this blueprint into your Kestra instance.
  2. Configure the required secrets (POSTHOG_PERSONAL_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_API_KEY) in your Kestra namespace.
  3. Click Execute using default inputs to test the workflow against the bundled sample error cluster.
  4. Enable the on_new_posthog_errors trigger to continuously monitor live production exceptions.

How to extend

  • Connect an automated flag disable task (e.g. via PostHog REST API patch or GitHub PR dispatch) in the FLAG_CORRELATED_REGRESSION branch to engage an instant automated kill switch.
  • Wire PagerDuty or Opsgenie alerts to immediately page the feature team owning the culprit flag.
  • Feed incident dossiers directly to Grafana or OpenTelemetry dashboards to track mean time to detection (MTTD).

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.