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
- ci: removed changelog.json file (#281) — committed to bizob2828/node-newrelic by svetlanabrennan 3 months ago
- ci: removed changelog.json file (#281) — committed to bizob2828/node-newrelic by svetlanabrennan 3 months ago
With version
5.13.0we 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
2 - add a proxy getter/setter to that segments transaction
3 - on that
4 - find your culprit

debuggerstatement look at the stack traceFor us we were logging a Hapi request.response. The response had an
.agentwhich 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
segment.transactionIS setisActiveproperty is not a functionis 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 …
segment.transaction.isActiveisn’t a function – can you use a debugger (or simply temporary logging) to figure out whatsegment.transaction.isActiveis?We basically want to find out what’s replacing the
isActivefunction, and then come up with a fix that will allow us to continue recording data.