New Relic:如何用 startSegment 替换 createTracer
New Relic: How to replace createTracer with startSegment
我在代码中有一个 createTracer() 方法,我们在旧的新 relic 版本中使用它。
NR.createTracer("processThread", _ => this._initialize())();
为了将新 Relic 迁移到 New Relic 的最新版本,我已根据新 Relic 文档将其替换为 startSegment() 方法:https://github.com/newrelic/node-newrelic/blob/master/Migration%20Guide.md#upgrading-to-agent-v5
NR.startSegment("processThread", _ => this._initialize())();
但是现在,我的代码给出了这个错误:
TypeError: NR.startSegment(...) is not a function
我做错了什么?
我看到 startSegment() 和 createTracer() 中的参数已更改
https://newrelic.github.io/node-newrelic/docs/API.html#createTracer
正如 docs 所建议的,您必须提供一个强制性(布尔值)第二个参数:
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.
并且参数回调现在是可选的,你应该使用第三个参数handler作为回调
To instrument individual callbacks, call startSegment() inside the callback, and move the main callback logic to the handler function.
我在代码中有一个 createTracer() 方法,我们在旧的新 relic 版本中使用它。
NR.createTracer("processThread", _ => this._initialize())();
为了将新 Relic 迁移到 New Relic 的最新版本,我已根据新 Relic 文档将其替换为 startSegment() 方法:https://github.com/newrelic/node-newrelic/blob/master/Migration%20Guide.md#upgrading-to-agent-v5
NR.startSegment("processThread", _ => this._initialize())();
但是现在,我的代码给出了这个错误:
TypeError: NR.startSegment(...) is not a function
我做错了什么?
我看到 startSegment() 和 createTracer() 中的参数已更改 https://newrelic.github.io/node-newrelic/docs/API.html#createTracer
正如 docs 所建议的,您必须提供一个强制性(布尔值)第二个参数:
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.
并且参数回调现在是可选的,你应该使用第三个参数handler作为回调
To instrument individual callbacks, call startSegment() inside the callback, and move the main callback logic to the handler function.