This repository contains an automated script that listens for alerts from New Relic APM, fetches recent error traces for impacted services, and sends them via email in a CSV report format.
- Listens to New Relic webhook alert payloads (ideal for AWS Lambda or Flask app).
- Fetches recent errors (last 60 minutes) for selected applications using New Relic's GraphQL API.
- Generates a detailed CSV report of error traces.
- Sends the report via email using Gmail SMTP.
- Cleans and formats data before sending.
- Python 3.8+
- Gmail SMTP credentials
- New Relic API key and Account ID
- Pre-configured environment variables
Variable | Description |
---|---|
NEWRELIC_API_KEY |
New Relic User API Key |
NEWRELIC_ACCOUNT_ID |
Your New Relic Account ID |
GMAIL_USER |
Gmail address to send emails from |
GMAIL_PASSWORD |
Gmail App Password (not your account password) |
RECEIVER_EMAILS |
Comma-separated list of recipient emails |
RECEIVER_CC |
(Optional) CC email address |
flowchart TD
A[New Relic<br>Alert Triggered] --> B[Webhook Payload<br>Received]
B --> C[Check if alert<br>is ACTIVATED]
C -- No --> Z[Ignore and exit]
C -- Yes --> D[Parse impactedEntities]
D --> E[Call New Relic<br>GraphQL API]
E --> F[Fetch recent<br>ErrorTrace events]
F --> G[Generate CSV<br>from error data]
G --> H[Send email via<br>SMTP with attachment]
H --> I[Log success<br>or failure]