Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

externalDuration not matching internal time checks

transactions
externalduration

#1

Hi,

We recently had an issue where Insights led us to believe one of our API services was performing very slowly.

The web service is built in .NET with the latest agent installed.

We were trying to calculate the internal duration by excluding external calls using (duration-externalDuration).

The total duration of the transactions was consistently around 6 seconds and the reported external duration around 2 seconds. On investigation we could see that actually the external duration was actually 4 seconds, this was based on our internal logs, recording a DateTime whenever a request is set and received.

My question is, how does the agent determine when an external request has been made? Are there certain coding patterns where the agent may not report accurately?

Not all of our API services have this issue, but they are not obviously implemented differently.

Any ideas appreciated.

Thanks.


#2

@jamesc1 -

The .NET agent monitors external calls by instrumenting (i.e. inserting timers) into the following methods:

System.Net.HttpWebRequest.GetResponse

and

System.Net.Http.HttpClient.SendAsync (which you may not call directly but is called by other HttpClient methods).

The GetResponse instrumentation is straightforward because that’s a synchronous call. The timer starts when the method is entered and stops when the method exits.

The SendAsync instrumentation is a bit tricker because the timer isn’t stopped until the promise returned by the awaited Task is fulfilled.

Maybe the way you are starting and stopping your timers for an async call are not in alignment with the way the agent does things?

Does that help?


#3

Hi Tjd, that’s really helpful thanks.