Return Integration Errors in HTTP Responses from Trace and Metric REST APIs

When submitting spans or metrics to their respective HTTP REST API, if the data would result in a NRIntegrationError, the HTTP response is 202 with a JSON response body only containing the request ID. In order to correlate an integration error with the request, a service would be required to always log the response’s request ID regardless of error. This is rather noisy when the request ID is only handy if an integration error has occurred.

It would be nice if the response contained the integration error so that an error log could be emitted to better identify and correct the issue.

A couple examples of this are: old timestamps on spans, old timestamps on metrics, and negative count values on metrics.

The following is a python script that can reproduce the issue. This script generates three integration errors in New Relic; however, the script has no way to detect the issue other than programmer foresight to validate the data prior to submitting the request.

import requests
import time

API_KEY = '<OMITTED>'


def http_metrics():
    day_seconds = 60 * 60 * 24
    data = """[{{
        "metrics": [
            {{
                "name": "test.metric.count.negative",
                "type": "count",
                "value": -1,
                "interval.ms": 0,
                "timestamp": {}
            }},
            {{
                "name": "test.metric.count.old",
                "type": "count",
                "value": 1,
                "interval.ms": 0,
                "timestamp": {}
            }},
        ]
    }}]""".format(time.time(), time.time() - 2 * day_seconds)

    r = requests.post(
        'https://metric-api.newrelic.com/metric/v1',
        headers={
            'Content-Type': 'application/json',
            'Api-Key': API_KEY,
        },
        data=data,
    )
    print(r.status_code)
    print(r.text)


def http_spans():
    day_seconds = 60 * 60 * 24
    data = """[{{
        "spans": [{{
            "trace.id": "00000000",
            "id": "ABC",
            "attributes": {{
                "duration.ms": 12.53,
                "name": "test.span.old",
                "timestamp": {}
            }}
        }}]
    }}]""".format(time.time() - 2 * day_seconds)

    r = requests.post(
        'https://trace-api.newrelic.com/trace/v1',
        headers={
            'Content-Type': 'application/json',
            'Api-Key': API_KEY,
        },
        data=data,
    )
    print(r.status_code)
    print(r.text)


if __name__ == '__main__':
    http_spans()
    http_metrics()

New Relic Edit

  • I want this too
  • I have more info to share (reply below)
  • I have a solution for this

0 voters

We take feature ideas seriously and our product managers review every one when plotting their roadmaps. However, there is no guarantee this feature will be implemented. This post ensures the idea is put on the table and discussed though. So please vote and share your extra details with our team.

@blake.roberts Looks like you are working this out with our support team via a ticket. Once resolved please do share in this thread the solution to the errors you are seeing :slight_smile:

There is a support ticket open! They directed me here as it sounds like this is known behavior. They let me know they put in a feature request and said I should do the same as this way other New Relic users could chime in with additional use cases and possible work arounds.

@blake.roberts Thanks for that background information. I went ahead and added a poll to your post to get the interest of other community members. Hopefully some of them will also share if that have work arounds. :slight_smile:

1 Like