Feature Idea: Add IncrementCounter(string, int) to .NET API

I’m new to New Relic APIs. I’m trying to increment a counter by an arbitrary value in .NET code and notice NewRelic.IncrementCounter(string name) exists, but no overload version to include the increment amount (I assume 1 is always used). The Java API has that feature, so just missing from .NET.

What are my options? Is the API open source so I can add this feature myself? Switch to another API (something that works in .NET code)?

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.

Hey @eric.selk! Thanks for jumping in and letting us know your needs around this. At this time we do not have a version of an API call that takes additional parameters that would be able to specify in the way you are describing.

I am happy to pass this along to our product team for review! They will be interested to know how this is affecting your use with the .NET Agent. Thanks! And be sure to also vote above! :blush:

I would like this too. I use a library that in essence puts items on a queue and processes them, and lets me know how many were successfully processed. I’d like to monitor to catch if any items are being lost, so I’d like to increment the counter when an item goes on the queue, and decrement it when I receive a confirmation of success.

The Java and Ruby NewRelic APIs accept an amount parameter; unfortunately, I am in .NET. Do you know of any workaround for this?

Hi Kay,

I’m not so sure on whether or not this made it to the .Net agent (I’ll check with the team though)

In the meantime it may be possible to send custom attributes for this to Insights when these queue events occur. For example,

int counter = 1; 

NewRelic.Api.Agent.AddCustomParameter("incrementer", counter);
NewRelic.Api.Agent.AddCustomParameter("decrementer", counter);

Which you can then perform math on in insights; If for example you have 5 items on your queue in an hour,

SELECT sum(incrementer) FROM Transaction SINCE 1 HOUR AGO

This will return 5.

If all 5 are a confirmed success, your decrementer attribute will be added.

SELECT sum(decrementer) FROM Transaction SINCE 1 HOUR AGO

will also return 5.

Therefore, to see if an item didn’t receive a success message from the queue;

SELECT sum(incrementer) - sum(decrementer) FROM Transaction SINCE 1 HOUR AGO

In our example this should return 0. But if adding an item to the queue fails, your decrementer will be less than 5, returning >0, which you can alert on with NRQL alerts.