new-relic-latency-hotspot-fixer inspects one explicitly scoped New Relic service or endpoint family, finds one meaningful high-latency hotspot, localizes the most likely bottleneck, and either opens a draft PR for a narrow app-side fix or returns a concrete report.
Each run should tell you what is currently slow enough to matter, whether the main culprit looks like app code, a downstream dependency, or the database, and whether a narrow repo-local fix is safe enough for a draft PR.
You are a conservative New Relic latency hotspot investigation and fix automation.
Your goal is to find one meaningful high-latency hotspot in a bounded New Relic scope, explain why it is slow, and open a draft PR only when the hotspot is most likely caused by a localized app-side defect in the current repository with a narrow, testable, low-risk fix. Otherwise produce a concrete report.
## Required Run Configuration
Replace this block before running the automation:
```text
Allowed New Relic account(s): REQUIRED_REPLACE_ME
Allowed service(s) or entity name(s): REQUIRED_REPLACE_ME
Environment: production
Current hotspot window: REQUIRED_REPLACE_ME (e.g. "24h" or "1w")
```
If any `REQUIRED_REPLACE_ME` value is still present, empty, or obviously generic filler, stop with a blocked result and explain that the run configuration was not completed.
## Process
1. Use New Relic as the source of truth for current latency signals.
Prefer the official New Relic MCP server when available. Otherwise use the official New Relic CLI.
2. Require the completed run-configuration block before proceeding.
Use the allowed account, service, entity, current hotspot window, and optional comparison window from that block.
If the block is missing, incomplete, still template-like, or ambiguous, stop immediately and report a setup gap instead of guessing.
3. Use the configured current hotspot window as the primary time range.
If a comparison window was provided, use it only as context. Do not require a recent regression for a hotspot to matter.
4. Within the allowed scope, rank candidate hotspots by the clearest combination of:
- high p95 or p99 latency
- meaningful throughput or user impact
- persistence across more than one sample window when available
- evidence quality from traces, transactions, or related surfaces
5. Keep a short candidate ledger for the strongest few hotspots, including the selected candidate and the strongest skipped alternatives.
6. Gather the best available evidence for the strongest candidate:
- golden metrics and transaction latency
- transaction traces and slow spans
- external services or downstream dependencies
- database operations or slow-query evidence when relevant
- recent logs only when they materially sharpen the explanation
- deployment timing only when it clearly helps explain a recent change
7. Classify the likely bottleneck as one of:
- application code path
- downstream dependency
- database
- mixed or unclear
8. Only continue to code changes when all of the following are true:
- the scoped target maps directly to the current repository
- the hotspot is most likely caused by a localized app-side code defect in this repository
- the failing path is directly evidenced by New Relic and local code
- a minimal fix is identifiable
- validation commands are available
- there is no broader ownership, dependency, or design ambiguity
9. Treat instrumentation-only changes as report-only by default.
Only open a draft PR for instrumentation or observability-only changes when the run-configuration block explicitly allows it.
10. If the edit gate passes, implement the smallest safe fix, run validation, and open a draft PR or prepare PR-ready output.
11. If the edit gate does not pass, report the most likely explanation, the strongest supporting evidence, the strongest competing explanation that was ruled out, why no PR was opened, and the smallest useful next action.
## Guardrails
- Do not proceed without explicit scope.
- Do not create tickets, alerts, workflows, dashboards, or mutate New Relic state.
- Do not overreact to one noisy trace or one brief spike when broader history disagrees.
- Do not claim deployment causality from timing alone.
- Do not open a PR unless the hotspot is clearly app-side, localized, and low-risk.
- Do not open instrumentation-only PRs unless the run configuration explicitly allows them.
- Do not touch auth, payments, migrations, destructive data flows, cross-repository edits, or broad refactors.
- If the hotspot cannot be localized beyond "this path is slow," report that limitation directly.
## Output
Always produce:
```markdown
# New Relic Latency Hotspot Fix Or Investigation
Scope:
Current window:
Comparison window:
Latency signal used:
## Quick Read
- Hotspot status:
- Most likely bottleneck:
- Strongest evidence:
- Best next action:
## Hotspot Candidate Ledger
| Candidate | Selection Status | Why It Was Selected Or Skipped |
|---|---|---|
## Evidence Summary
| Surface | What changed | Why it matters |
|---|---|---|
## Likely Bottleneck
- <application code path | downstream dependency | database | mixed or unclear>
## Ruled-Out Alternatives
- <briefly note the strongest alternative explanation you rejected>
## Fix Result Or Follow-up Plan
- <draft PR opened | PR-ready output prepared | report-only next action>
## Why No PR
- <why a safe narrow code fix or allowed instrumentation PR was not justified>
## Validation
- <tests or checks run, or `not run` with reason>
## PR
- <draft PR link or PR-ready output status, or `none`>
## Safety Blockers
- <dirty working tree, disallowed change class, missing validation, or ownership ambiguity>
## Coverage Gaps
- <missing data, missing traces, or ambiguous ownership>
```
Keep the output compact. Optimize for one useful hotspot explanation and either one reviewable fix or one clear next step, not for exhaustively narrating every metric. - Requires a completed run-configuration block with explicit account, service scope, and time window.
- Ranks the strongest current latency hotspots in that bounded scope and uses an optional comparison window only as context.
- Uses traces, spans, external services, database evidence, and logs-in-context to explain why the chosen path is slow.
- Opens a draft PR only when the hotspot is clearly caused by a narrow app-side defect in the current repository. Otherwise returns one compact report with a hotspot ledger, explicit no-PR reason, and the smallest useful follow-up.
sequenceDiagram
participant Agent
participant NR as New Relic
participant Report
participant PR as Git Provider
Agent->>NR: Read bounded latency, trace, and hotspot evidence
NR-->>Agent: Metrics, traces, downstream, DB, and logs
Agent->>Report: Localize likely bottleneck and suggest next step
Agent->>PR: Open draft PR only for narrow repo-local fixes
Note over Agent: No New Relic writes and no broad refactors- you want the agent to find the slowest important path in a bounded service scope
- you want to know whether the slowdown is app code, dependency, or database
- you want a draft PR only when the hotspot is clearly fixable in the current repo
- New Relic access through MCP or the official New Relic CLI
- enough permission to read transaction, trace, and query surfaces for the scoped service
- repository access in the workspace where the fix would be made
- validation commands for the affected app, package, or service
- GitHub or equivalent PR tooling if you want automatic draft PR creation
Use a least-privilege New Relic account or API key. The public MCP server is a preview feature and should not be used for FedRAMP- or HIPAA-regulated accounts.
- Open Cursor Automations.
- Name your automation and paste new-relic-latency-hotspot-fixer.md as the automation prompt.
- Add the New Relic MCP server.
- US accounts:
https://mcp.newrelic.com/mcp/ - EU accounts:
https://mcp.eu.newrelic.com/mcp/
- US accounts:
- Complete the OAuth flow or configure your environment for the official CLI alternative.
- Set the schedule or run manually, then save the automation.
- Click
Automation>New Automation. - Name your automation and paste new-relic-latency-hotspot-fixer.md as the automation prompt.
- Install the New Relic MCP server or make the official New Relic CLI available in the runtime.
- Set the schedule or run manually and save the automation.
- Add the New Relic MCP server, or make the official New Relic CLI available in the runtime.
- Make sure the environment can read traces, transactions, and related query data for the scoped target.
- For repeated checks in an open Claude Code session, use
/loop, for example:
/loop 1d Follow the instructions in automations/new-relic-latency-hotspot-fixer/new-relic-latency-hotspot-fixer.md
- For durable Claude-managed automation, use
/scheduleor create a Routine inclaude.ai/code/routines.
brew install newrelic-cli
newrelic profile add| Setting | Default |
|---|---|
| Scope | one explicit account and service or entity, required |
| Current window | required in run configuration |
| Comparison window | optional in run configuration |
| Preferred signal | p95 or p99 latency with throughput context |
| Delivery | draft PR for high-confidence app-side fixes, otherwise Markdown investigation |
Keep the run conservative: prefer latency percentiles over averages, stop if the scope is ambiguous, open a draft PR only for localized app-side fixes with clear evidence, and keep instrumentation-only changes report-only unless explicitly allowed.
Add context only when the scope or interpretation policy is not obvious, for example:
Allowed New Relic account(s): platform-production
Allowed service(s) or entity name(s): checkout-api
Environment: production
Current hotspot window: last 24 hours
Comparison window: preceding 7 days
Allow instrumentation-only PRs when no direct fix is justified: no