Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(signals): ship a default pre-check for the apm scout (#115955)

posthog[bot]ba62579e1112
diff --git a/products/signals/backend/test/test_scout_precheck.py b/products/signals/backend/test/test_scout_precheck.py
index 3ff3a8bae259..0ded9003cf78 100644
--- a/products/signals/backend/test/test_scout_precheck.py
+++ b/products/signals/backend/test/test_scout_precheck.py
@@ -17,6 +17,7 @@ from django.test import SimpleTestCase
from parameterized import parameterized
from rest_framework import status
+from posthog.clickhouse.client import sync_execute
from posthog.models import OrganizationMembership, Team, User
from posthog.models.scoping import team_scope
from posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summary
@@ -256,6 +257,35 @@ class TestSkillDefaultPrecheck(ClickhouseTestMixin, BaseTest):
assert result is not None
assert (result.outcome, result.query_source) == (outcome, "skill_default")
+ def test_apm_default_skips_only_without_spans_in_the_last_day(self) -> None:
+ skill = "signals-scout-apm"
+ LLMSkill.objects.create(
+ team=self.team, name=skill, description="", body="", metadata={"seeded_by": HARNESS_SEEDED_BY}
+ )
+ SignalScoutConfig.all_teams.create(team=self.team, skill_name=skill)
+
+ def evaluate():
+ with (
+ patch(ROLLOUT_PERCENT, return_value=100),
+ patch("products.signals.backend.scout_harness.precheck.posthoganalytics.capture"),
+ ):
+ return evaluate_scout_precheck(self.team.pk, skill)
+
+ outcomes = []
+ for hours_ago in (25, 23):
+ timestamp = (NOW - timedelta(hours=hours_ago)).strftime("%Y-%m-%d %H:%M:%S.%f")
+ sync_execute(
+ "INSERT INTO trace_spans (uuid, team_id, trace_id, span_id, parent_span_id, name, kind, "
+ "timestamp, end_time, observed_timestamp, status_code, service_name) VALUES "
+ f"(generateUUIDv4(), {self.team.pk}, 't{hours_ago}', 's{hours_ago}', '', 'GET /api', 2, "
+ f"'{timestamp}', '{timestamp}', '{timestamp}', 0, 'web')"
+ )
+ result = evaluate()
+ assert result is not None
+ outcomes.append((result.outcome, result.query_source))
+
+ assert outcomes == [("skip", "skill_default"), ("run", "skill_default")]
+
@parameterized.expand(
[
# Recordings stopped 20 days ago: a capture cliff the scout must still see.
diff --git a/products/signals/skills/signals-scout-apm/SKILL.md b/products/signals/skills/signals-scout-apm/SKILL.md
index b3c7386ba343..caf642acdaff 100644
--- a/products/signals/skills/signals-scout-apm/SKILL.md
+++ b/products/signals/skills/signals-scout-apm/SKILL.md
@@ -17,6 +17,11 @@ allowed_tools:
metadata:
owner_team: signals
scope: apm
+scout-precheck-query: |
+ SELECT 1 AS has_spans
+ FROM posthog.trace_spans
+ WHERE timestamp > {now} - INTERVAL 24 HOUR
+ LIMIT 1
---
# Signals scout: distributed tracing (APM)
@@ -31,6 +36,8 @@ You author reports directly via the report channel (`scout-emit-report` / `scout
## Quick close-out: is APM even in use?
+A scheduled run can start with a `<precheck_result>` block. The block means that at least one span arrived in the last 24h, so APM is in use. When the block is present, skip this check and go to the full run.
+
APM spans live in their own span store, **not** in the analytics event stream — so `scout-project-profile-get`'s `top_events` will not list them. Use the APM tools to check:
- `apm-services-list` — empty (no service has emitted spans), **and**