Introduction
Setting up alerts for critical application issues is essential, and tools like New Relic make it easy to monitor application performance. However, New Relic doesnโt offer a direct integration with Discord, which can be frustrating when you want real-time alerts in your Discord channels.
When I started integrating New Relic Alerts with Discord, I hit multiple roadblocks, from webhook failures to incorrect payload structures. But after several iterations and experiments, I found the best approach that works seamlessly. Hereโs a story of my debugging journey and how you can quickly set up New Relic alerts for Discord.
Step 1: Setting Up New Relic Alerts
Before integrating with Discord, I first needed to create an alert condition in New Relic. Hereโs how:
- Go to Alerts > Alert Conditions > Create Alert Condition.
Select Guided Mode.
Choose the APM service and select Error Rate as the metric.
Set the window size to 5 minutes and a threshold of 1% error rate in the last 5 minutes.
Add a meaningful name, title, and description.
Assign the alert to a default initial policy.
Great! Now I had an alert condition in place. The next challenge? Getting notifications to Discord.
Step 2: Trying Webhooks (The Wrong Way ๐)
New Relic provides several notification options, such as Slack, Webhooks, AWS EventBridge, but not Discord.
I found two promising documents:
New Relic Forum - Discord Webhook Setup
Microideation Blog on New Relic Alerts to Discord
Both documents suggested a workaround: use a Slack-compatible webhook by modifying the Discord Webhook URL like this:
<YOUR_DISCORD_WEBHOOK_URL>/slack
I was hopeful, but when I tried setting up Slack in New Relic, it only showed a login page for Slack authentication. ๐ค
No option to manually enter the webhook!
I even tried using New Relic CLI, but it didnโt work either.
Clearly, the Slack method was a dead end. Time for Plan B. ๐
Step 3: Using AWS EventBridge + Lambda (The Long Way ๐ )
Since the webhook approach was failing, I thought of another workaround:โ๏ธ Use AWS EventBridge to catch New Relic alert events. โ๏ธ Send these events to an AWS Lambda function. โ๏ธ Convert the payload to a Discord-compatible format and send the alert.
Setting Up EventBridge
Create an EventBridge Partner Event Bus using New Relic:
aws.partner/newrelic.com/<NEWRELIC_ACC_ID>/acc
Create an event rule:
Name: newrelic_alerts_to_discord
Event Pattern:
{
"source": [{
"prefix": "aws.partner/newrelic.com"
}]
}
Target: AWS Lambda Function
Lambda Function to Send Alerts to Discord
Hereโs the Python Lambda function I wrote:
import json
import requests
import os
DISCORD_WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL") # Set in Lambda environment variables
def lambda_handler(event, context):
try:
print("Received Event:", json.dumps(event, indent=2))
event_detail = event.get("detail", {})
# Extract fields
alert_condition = ", ".join(event_detail.get("alertConditionNames", ["N/A"]))
alert_description = ", ".join(event_detail.get("alertConditionDescriptions", ["N/A"]))
impacted_entities = ", ".join(event_detail.get("impactedEntities", ["N/A"]))
state = event_detail.get("state", "N/A")
created_at = event_detail.get("createdAt", "N/A")
# Format message for Discord
discord_payload = {
"content": "๐จ **New Relic Alert** ๐จ",
"embeds": [
{
"title": alert_condition,
"description": (
f"**Condition Description:** {alert_description}\n"
f"**Impacted Entities:** {impacted_entities}\n"
f"**State:** {state}\n"
f"**Created At:** {created_at}"
),
"color": 15158332
}
]
}
response = requests.post(DISCORD_WEBHOOK_URL, json=discord_payload)
if response.status_code == 204:
return {"status": "Success"}
else:
return {"status": "Failed", "error": response.text}
except Exception as e:
return {"status": "Error", "message": str(e)}
It worked! ๐ But, letโs be real โ this was too complex for a simple webhook notification.
Step 4: The Best Approach โ Using Webhooks the Right Way โ
For Discord Webhooks to work, the JSON payload must include content or embeds. Without these keywords, Discord will reject the payload!
Final JSON Payload for Discord Webhook
{
"content": "๐จ **New Relic Alert** ๐จ",
"embeds": [
{
"title": "{{ accumulations.conditionName.[0] }}",
"description": "**Condition Description:** {{#each accumulations.conditionDescription}}{{#unless @first}}, {{/unless}}{{escape this}}{{/each}}\n**Impacted Entities:** {{#each entitiesData.names}}{{#unless @first}}, {{/unless}}{{this}}{{/each}}\n**State:** {{state}}\n",
"color": 15158332,
"footer": {
"text": "{{timezone createdAt 'Asia/Kolkata'}}"
}
}
]
}
Why This Works?
โ๏ธ Uses Handlebars syntax to format the payload correctly. โ๏ธ Includes the required content field, making Discord accept the message. โ๏ธ No need for EventBridge or Lambda โ pure webhook solution! โ๏ธ Works seamlessly with New Relic webhook notifications.
Conclusion
๐ก Lesson Learned: Always check the webhook payload format before building unnecessary workarounds! ๐
By correctly structuring the JSON using Handlebars syntax and ensuring the presence of content or embeds, I was able to directly send New Relic alerts to Discord without using AWS services.
๐ If youโre setting up New Relic to Discord alerts, follow Solution 2 โ itโs simple, efficient, and works perfectly!



Top comments (0)