New Relic Integration

Toollake enables seamless connectivity between various business tools, allowing AI agents to interact with observability platforms like New Relic for performance monitoring and analytics.

This section outlines how to execute NRQL queries using the Newrelic class from apm.newrelic.

📦 Requirements

  • New Relic API Key

  • New Relic Account ID

  • apm.newrelic module available in your environment


🔧 Class: Newrelic

A lightweight utility for querying New Relic via NRQL within Toollake.

Constructor

Newrelic(api_key: str, account_id: str)
  • api_key (str): Your New Relic User API Key.

    • Example: "NRAK-XXXXXXXXXXXXXX"

  • account_id (str): Your New Relic account identifier.

    • Example: "1234567"


📡 Method: execute_nrql(nrql_query: str) → dict

Executes a NRQL (New Relic Query Language) query to fetch custom telemetry metrics.

Parameters

  • nrql_query (str): A valid NRQL query string.

    • Example:

      SELECT percentage(count(*), WHERE httpResponseCode = '5%') AS 'http500_percentage', 
             percentage(count(*), WHERE httpResponseCode = '4%') AS 'http400_percentage', 
             count(*) AS 'total_requests' 
      FROM Transaction 
      SINCE 60 minutes ago

Returns

  • dict: A structured JSON response containing query results.


✅ Example Usage

from apm.newrelic import Newrelic

api_key = "NRAK-XXXXXXXXXXXXXX"  # Replace with your secure API key
account_id = "1234567"           # Replace with your account ID

nr = Newrelic(api_key, account_id)

nrql_query = """
SELECT percentage(count(*), WHERE httpResponseCode = '5%') AS 'http500_percentage', 
       percentage(count(*), WHERE httpResponseCode = '4%') AS 'http400_percentage', 
       count(*) AS 'total_requests' 
FROM Transaction 
SINCE 60 minutes ago
"""

print("Executing NRQL Query:")
print(nr.execute_nrql(nrql_query))

📈 Use Case in Toollake

Toollake agents can leverage this method to:

  • Monitor API health and error rates in real time

  • Trigger alerts based on custom thresholds

  • Optimize routing or performance decisions dynamically


🔐 Security Tip

Never hard-code your API key in production. Use secure storage solutions like environment variables or secrets managers.

Last updated