node-newrelic: [Bug] unhandledException TypeError: segment.transaction.isActive is not a function

newrelic causes unhandledException and crashes the process

TypeError: segment.transaction.isActive is not a function
    at Shim.getActiveSegment (/usr/src/app/node_modules/newrelic/lib/shim/shim.js:1329:61)
    at AsyncHook.afterHook (/usr/src/app/node_modules/newrelic/lib/instrumentation/core/async_hooks.js:88:31)
    at emitAfterNative (internal/async_hooks.js:164:40)
    at <anonymous>
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:229:7)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (7 by maintainers)

Commits related to this issue

Most upvoted comments

With version 5.13.0 we made the segment reference we add to the output request non-enumerable to hopefully avoid these issues.

Has anyone upgraded and are they still having issues?

So my team had this same issue occurring.

Steps to resolve: 1 - determine when the segment that throws the error is being set Screen Shot 2019-07-26 at 4 08 36 PM 2 - add a proxy getter/setter to that segments transaction Screen Shot 2019-07-26 at 4 18 16 PM 3 - on that debugger statement look at the stack trace Screen Shot 2019-07-26 at 4 20 21 PM 4 - find your culprit Screen Shot 2019-07-26 at 4 10 59 PM

For us we were logging a Hapi request.response. The response had an .agent which was the newrelic Agent, which went into the pino logger library which used fast-safe-stringify which traversed the Agent object deeply and converted any circular references into the string '[Circular]'.

I’m currently running newrelic in prod from this branch https://github.com/newrelic/node-newrelic/compare/master...ali-essam:tmp/debug-is-active. Now we wait and see if this issue happens again

@ali-essam Thanks for reporting this issue, and for the workaround PR you submitted.

Do you happen to know what/how this is being triggered? The fact that

  1. segment.transaction IS set
  2. But it’s isActive property is not a function

is super confusing, and shouldn’t be possible. Obviously it is possible, but we’re curious as to what might be causing it. The fix you provided will prevent this error, but it also means a lot of data might be silently dropped on the floor, and we’re not sure that’s the right long term solution. (Although folks running into this issue are free to give your PR a try)

Thinking this through out loud …

  1. Are you able to reproduce this problem at will, or does it just happen randomly? If so how often?
  2. Can you reproduce this issue with a small test case, or does it require your entire application to be loaded?
  3. The stack trace says segment.transaction.isActive isn’t a function – can you use a debugger (or simply temporary logging) to figure out what segment.transaction.isActive is?

We basically want to find out what’s replacing the isActive function, and then come up with a fix that will allow us to continue recording data.