I had a createTracer() method in the code which we were using in old new relic version.
NR.createTracer("processThread", _ => this._initialize())();
To migrate new relic to latest versin of New Relic, I've replaced it to startSegment() method as per new relic doc: https://github.com/newrelic/node-newrelic/blob/master/Migration%20Guide.md#upgrading-to-agent-v5
NR.startSegment("processThread", _ => this._initialize())();
But now, my code is giving me this error:
TypeError: NR.startSegment(...) is not a function
What am I doing wrong here?
I see the arguments have been changed in startSegment() and createTracer() https://newrelic.github.io/node-newrelic/docs/API.html#createTracer
As docs suggest, you have a mandatory (boolean) second parameter which you must supply:
NR.startSegment('mySegment', false, _ => this._initialize())();
record bool
Indicates if the segment should be recorded as a metric. Metrics will show up on the transaction breakdown table and server breakdown graph. Segments just show up in transaction traces.
And parameter callback is now optional, you should use third parameter handler for callback
To instrument individual callbacks, call startSegment() inside the callback, and move the main callback logic to the handler function.