|
1 | 1 | from sentry.investigations.models import InvestigationBlockKind, InvestigationSourceType |
2 | 2 | from sentry.investigations.templates.types import InvestigationTemplateSpec, TemplateBlockSpec |
3 | 3 |
|
| 4 | +SHORT_LINKED_SUMMARY_INSTRUCTIONS = ( |
| 5 | + "Use at most three short sentences or three compact bullets total. Preserve useful Markdown " |
| 6 | + "links from the evidence. Link concrete Sentry issues, releases, transactions, or other pages " |
| 7 | + "when the evidence contains a valid URL or identifier; never invent a URL or identifier." |
| 8 | +) |
| 9 | +LINKED_EVIDENCE_INSTRUCTIONS = ( |
| 10 | + "Include concise Markdown links to relevant Sentry issues, releases, transactions, or other " |
| 11 | + "pages when telemetry returns a concrete URL or identifier. Use organizationSlug from the " |
| 12 | + "investigation context for relative Sentry paths when needed; never guess a URL or identifier." |
| 13 | +) |
| 14 | + |
4 | 15 | BREACHED_METRIC_TEMPLATE = InvestigationTemplateSpec( |
5 | 16 | key="breached_metric", |
6 | 17 | version=1, |
7 | 18 | source_type=InvestigationSourceType.METRIC_OPEN_PERIOD, |
8 | 19 | parameters=(), |
9 | 20 | blocks=( |
10 | 21 | TemplateBlockSpec( |
11 | | - key="metric_chart", |
| 22 | + key="monitor_summary", |
| 23 | + kind=InvestigationBlockKind.TEXT, |
| 24 | + title="Monitor context", |
| 25 | + generation_prompt=( |
| 26 | + "Summarize only the Monitor details evidence for a human responder. State the " |
| 27 | + "monitor name and query, affected project and environment when known, threshold " |
| 28 | + "and breach direction, and supplied open-period time range. Do not speculate about " |
| 29 | + "the cause. " + SHORT_LINKED_SUMMARY_INSTRUCTIONS |
| 30 | + ), |
| 31 | + config={"autoRun": True}, |
| 32 | + display={"type": "markdown"}, |
| 33 | + dependencies=("monitor_evidence",), |
| 34 | + ), |
| 35 | + TemplateBlockSpec( |
| 36 | + key="monitor_evidence", |
12 | 37 | kind=InvestigationBlockKind.QUERY, |
13 | | - title="Breached metric", |
| 38 | + title="Monitor details", |
| 39 | + generation_prompt=( |
| 40 | + "Use the supplied metric issue, monitor definition, project, open-period window, " |
| 41 | + "threshold, and direction. Query the exact supplied monitor definition over the " |
| 42 | + "open period and an equal pre-breach baseline. Return a compact table of the " |
| 43 | + "monitor facts and the most useful baseline and open-period values. Preserve the " |
| 44 | + "exact query and time range; do not infer missing monitor configuration. " |
| 45 | + + LINKED_EVIDENCE_INSTRUCTIONS |
| 46 | + ), |
| 47 | + config={"autoRun": True}, |
| 48 | + display={"version": 1, "type": "table", "defaultView": "table"}, |
| 49 | + ), |
| 50 | + TemplateBlockSpec( |
| 51 | + key="spike_summary", |
| 52 | + kind=InvestigationBlockKind.TEXT, |
| 53 | + title="What happened", |
14 | 54 | generation_prompt=( |
15 | | - "Query the exact supplied monitor definition over the supplied analysis window. " |
16 | | - "Make the breach immediately visible in a time-series chart spanning the equal " |
17 | | - "pre-breach baseline and open-period portions. Plot the observed metric and the " |
18 | | - "supplied threshold or comparison as separate series so the crossing is clear. " |
19 | | - "Use the monitor time window for the chart interval when supported." |
| 55 | + "Summarize only the Metric spike evidence. Describe when the ramp-up began, the " |
| 56 | + "peak value and time, how long the breach lasted, and whether the signal recovered " |
| 57 | + "or remained elevated. State uncertainty when sparse telemetry does not establish " |
| 58 | + "one of those facts. " + SHORT_LINKED_SUMMARY_INSTRUCTIONS |
| 59 | + ), |
| 60 | + config={"autoRun": True}, |
| 61 | + display={"type": "markdown"}, |
| 62 | + dependencies=("spike_evidence",), |
| 63 | + ), |
| 64 | + TemplateBlockSpec( |
| 65 | + key="spike_evidence", |
| 66 | + kind=InvestigationBlockKind.QUERY, |
| 67 | + title="Metric spike", |
| 68 | + generation_prompt=( |
| 69 | + "Query the exact supplied monitor definition over the supplied open period and an " |
| 70 | + "equal pre-breach baseline. Make the ramp-up, peak, and ramp-down or recovery " |
| 71 | + "visible in a time-series chart. Plot the observed metric and supplied threshold " |
| 72 | + "or comparison as separate series so the crossing is clear. Use the monitor time " |
| 73 | + "window for the chart interval when supported, and do not invent missing points. " |
| 74 | + + LINKED_EVIDENCE_INSTRUCTIONS |
20 | 75 | ), |
21 | 76 | config={"autoRun": True, "preferChart": True}, |
22 | 77 | display={"version": 1, "type": "table", "defaultView": "chart"}, |
| 78 | + dependencies=("monitor_evidence",), |
23 | 79 | ), |
24 | 80 | TemplateBlockSpec( |
25 | | - key="overview", |
| 81 | + key="issues_summary", |
26 | 82 | kind=InvestigationBlockKind.TEXT, |
27 | | - title="Overview", |
| 83 | + title="What caused the spike", |
28 | 84 | generation_prompt=( |
29 | | - "Give the reader a useful overview of this breached metric using the supplied " |
30 | | - "monitor, open-period, project, threshold, direction, and analysis-window facts. " |
31 | | - "Accurately describe whether this is an upward or downward breach. Do not claim a " |
32 | | - "cause before examining the telemetry. Keep the overview to two short paragraphs." |
| 85 | + "Summarize only the Contributing issues evidence. Identify the issue groups that " |
| 86 | + "best account for the spike, including their counts, change from baseline, and " |
| 87 | + "relative contribution when available. If no issue groups convincingly explain " |
| 88 | + "the metric change, say that clearly. " + SHORT_LINKED_SUMMARY_INSTRUCTIONS |
33 | 89 | ), |
34 | 90 | config={"autoRun": True}, |
35 | 91 | display={"type": "markdown"}, |
| 92 | + dependencies=("issues_evidence",), |
36 | 93 | ), |
37 | 94 | TemplateBlockSpec( |
38 | | - key="synthesis", |
| 95 | + key="issues_evidence", |
| 96 | + kind=InvestigationBlockKind.QUERY, |
| 97 | + title="Contributing issues", |
| 98 | + generation_prompt=( |
| 99 | + "Using the Metric spike evidence to preserve the spike window, compare issue-group " |
| 100 | + "telemetry during the open period with the equal pre-breach baseline. Rank issue " |
| 101 | + "groups by the strongest supported contribution using absolute counts, change " |
| 102 | + "from baseline, and share of the spike. Prefer a bar chart with a compact table " |
| 103 | + "when useful, and include issue links only when the telemetry provides valid ones. " |
| 104 | + "Treat no supporting issue groups as a valid result; never fabricate attribution. " |
| 105 | + + LINKED_EVIDENCE_INSTRUCTIONS |
| 106 | + ), |
| 107 | + config={"autoRun": True, "preferChart": True}, |
| 108 | + display={"version": 1, "type": "table", "defaultView": "chart"}, |
| 109 | + dependencies=("spike_evidence",), |
| 110 | + ), |
| 111 | + TemplateBlockSpec( |
| 112 | + key="tags_summary", |
39 | 113 | kind=InvestigationBlockKind.TEXT, |
40 | | - title="What explains the change", |
| 114 | + title="Why those issues spiked", |
41 | 115 | generation_prompt=( |
42 | | - "Explain what the breached-metric result above and contributor result below show " |
43 | | - "together. Focus on evidence, distinguish correlation from causation, and state " |
44 | | - "uncertainty when the telemetry does not establish a convincing explanation. Keep " |
45 | | - "the answer to two or three short paragraphs unless a tiny table is essential." |
| 116 | + "Summarize only the Issue tag changes evidence. Explain which dimensions changed " |
| 117 | + "most during the spike and what explanation, if any, those distribution changes " |
| 118 | + "support. Distinguish evidence from hypotheses and say when the slices do not " |
| 119 | + "establish a convincing explanation. " + SHORT_LINKED_SUMMARY_INSTRUCTIONS |
46 | 120 | ), |
47 | 121 | config={"autoRun": True}, |
48 | 122 | display={"type": "markdown"}, |
49 | | - dependencies=("metric_chart", "contributors"), |
| 123 | + dependencies=("tags_evidence",), |
50 | 124 | ), |
51 | 125 | TemplateBlockSpec( |
52 | | - key="contributors", |
| 126 | + key="tags_evidence", |
53 | 127 | kind=InvestigationBlockKind.QUERY, |
54 | | - title="Likely contributors", |
| 128 | + title="Issue tag changes", |
55 | 129 | generation_prompt=( |
56 | | - "Compare telemetry during the supplied open-period window with its equal baseline. " |
57 | | - "Use as many supported telemetry calls and local transformations as useful. Let " |
58 | | - "the evidence determine whether issue groups, tags, or other metadata best explain " |
59 | | - "the change, then chart the strongest available evidence. If no convincing " |
60 | | - "contributor exists, show the most useful evidence and say so in the result." |
| 130 | + "Slice the contributing issue groups by supported dimensions that can explain the " |
| 131 | + "change, such as release, transaction, environment, region, browser, device, or " |
| 132 | + "other useful tags. Compare each distribution during the open period with the " |
| 133 | + "equal pre-breach baseline; do not rank raw spike volume without that comparison. " |
| 134 | + "Chart the strongest supported distribution changes and retain a compact table " |
| 135 | + "when useful. Do not invent unavailable tags or claim causation from correlation. " |
| 136 | + + LINKED_EVIDENCE_INSTRUCTIONS |
61 | 137 | ), |
62 | 138 | config={"autoRun": True, "preferChart": True}, |
63 | 139 | display={"version": 1, "type": "table", "defaultView": "chart"}, |
| 140 | + dependencies=("issues_evidence",), |
| 141 | + ), |
| 142 | + TemplateBlockSpec( |
| 143 | + key="trigger_summary", |
| 144 | + kind=InvestigationBlockKind.TEXT, |
| 145 | + title="Likely trigger and next steps", |
| 146 | + generation_prompt=( |
| 147 | + "Summarize only the Release and infrastructure signals evidence. Classify the " |
| 148 | + "result as code-related, infrastructure-related, mixed, or insufficient evidence. " |
| 149 | + "Distinguish correlation from causation, name the strongest supported finding, and " |
| 150 | + "give concrete next steps a human can take. Present external observability checks " |
| 151 | + "as suggestions rather than findings. " + SHORT_LINKED_SUMMARY_INSTRUCTIONS |
| 152 | + ), |
| 153 | + config={"autoRun": True}, |
| 154 | + display={"type": "markdown"}, |
| 155 | + dependencies=("trigger_evidence",), |
| 156 | + ), |
| 157 | + TemplateBlockSpec( |
| 158 | + key="trigger_evidence", |
| 159 | + kind=InvestigationBlockKind.QUERY, |
| 160 | + title="Release and infrastructure signals", |
| 161 | + generation_prompt=( |
| 162 | + "Use the supplied spike window together with the contributing issue and tag " |
| 163 | + "evidence. Check supported Sentry telemetry for releases, deployments, affected " |
| 164 | + "services or transactions, and infrastructure-like patterns correlated with the " |
| 165 | + "change. Return a compact evidence table containing only observed signals and " |
| 166 | + "their timing. If Sentry cannot inspect relevant infrastructure directly, include " |
| 167 | + "specific suggested external checks such as affected pods or services in Datadog, " |
| 168 | + "clearly labeled as follow-up checks rather than findings. Never fabricate release, " |
| 169 | + "deployment, infrastructure, or external-observability data. " |
| 170 | + + LINKED_EVIDENCE_INSTRUCTIONS |
| 171 | + ), |
| 172 | + config={"autoRun": True}, |
| 173 | + display={"version": 1, "type": "table", "defaultView": "table"}, |
| 174 | + dependencies=("spike_evidence", "issues_evidence", "tags_evidence"), |
64 | 175 | ), |
65 | 176 | ), |
66 | 177 | ) |
0 commit comments