Reputation: 19
I am currently working on integrating New Relic into our application monitoring stack, and I'm facing an issue while trying to fetch query results using NRQL (New Relic Query Language). I'm relatively new to New Relic, so any insights would be greatly appreciated.
Here's the problem I'm encountering:
I have configured New Relic in my application, and I can see various data metrics and dashboards in the New Relic UI. However, when I attempt to use NRQL to fetch specific query results programmatically, I get unexpected or empty results.
For example, I'm trying to fetch the average response time of a particular API endpoint over the last 24 hours using the following NRQL query:
sql Copy code SELECT average(duration) FROM Transaction WHERE appName = 'MyApp' AND name = 'MyEndpoint' SINCE 1 day ago When I run this query in the New Relic Query Builder, it returns the expected results. However, when I use the New Relic API or the New Relic Python SDK to execute the query programmatically, I get an empty response or an error.
I have verified the following:
The New Relic API key and account ID used for authentication are correct. The required New Relic Python SDK and packages are installed. The application name ('MyApp') and endpoint name ('MyEndpoint') used in the query are correct. Despite these verifications, I am unable to retrieve the query result as expected. I have also tried other NRQL queries, and the issue persists with all of them.
Has anyone faced a similar issue while trying to fetch query results programmatically using NRQL and the New Relic API/SDK? Are there any additional configurations or settings required to ensure the NRQL queries return valid data programmatically?
Any guidance, suggestions, or troubleshooting steps would be highly appreciated. Thank you in advance for your help!
Upvotes: 0
Views: 2716
Reputation: 36
The query looks ok, if it works in the UI it should work in the API. Are you targteting the correct API? These differ based upon whether your account is in the US or EU data center.
You can test the queries out in the graphiql explorer. This has a nice feature of allowing you to copy as curl like this:
-H 'Content-Type: application/json' \
-H 'API-Key: YOUR-API-KEY-HERE' \
--data-binary '{"query":"{\n actor {\n account(id: YOUR-ACCOUNT-ID-HERE) {\n nrql(\n query: \"SELECT average(duration) FROM Public_APICall where api=\u0027amazonaws.com\u0027\"\n ) {\n results\n }\n }\n }\n}", "variables":""}'
If you drop your API Key and account ID in the above (and set the correct domain name for either EU or US data center) you should get a result from this public data set.
Upvotes: 0