apm-agent-nodejs icon indicating copy to clipboard operation
apm-agent-nodejs copied to clipboard

finish `accumulatedAgentTime` work from "onweek2-internal-agent-metrics" branches

Open trentm opened this issue 3 years ago • 0 comments

For my On Week 2 work I started patches to add counters to internal agent stats for accumulated CPU time used. For example, these fields from Agent#_getStats():

...
  agentOverhead: 0.5328552433344271,
  accumulatedAgentTime: 941.2509546279907,
  cpuUsage: 1766.4290000000037,
  agentTimeFromWhat: {
    startTransaction: 84.39729332923889,
    startSpan: 397.08366441726685,
    'Span.end': 23.216548442840576,
    'Span._encode': 21.22274398803711,
    'Span filter & send': 13.452475309371948,
    'Transaction#end': 177.3358075618744,
    'apmclient._writeBatch': 224.54242157936096
  },
...
}

I think with better names for those agentTimeFromWhat keys, this could be extremely useful for performance work. For example agentTimeFromWhat.startSpan includes the time for Error.captureStackTrace(obj, Span) that is relevant for deciding if captureSpanStackTraces should be disabled by default (https://github.com/elastic/apm-agent-nodejs/issues/2092).

The code changes are not too much of a burden, I don't think. Starter patches are here:

  • https://github.com/elastic/apm-agent-nodejs/compare/trentm/onweek2-internal-agent-metrics/
  • https://github.com/elastic/apm-nodejs-http-client/compare/trentm/onweek2-internal-agent-metrics/

trentm avatar Jan 19 '22 21:01 trentm