【问题标题】:New Relic: How to replace createTracer with startSegmentNew Relic:如何用 startSegment 替换 createTracer
【发布时间】:2019-07-10 08:35:37
【问题描述】:

我们在旧的新遗物版本中使用的代码中有一个 createTracer() 方法。

NR.createTracer("processThread", _ => this._initialize())();

为了将新遗物迁移到新遗物的最新版本,我已根据新遗物文档将其替换为 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

【问题讨论】:

    标签: callback trace newrelic


    【解决方案1】:

    正如docs 建议的那样,您必须提供一个强制性(布尔值)第二个参数:

    NR.startSegment('mySegment', false,  _ => this._initialize())();
    

    记录布尔值
    指示是否应将段记录为指标。指标将显示在事务分解表和服务器分解图上。段只显示在事务跟踪中。

    而且参数回调现在是可选的,你应该使用第三个参数handler进行回调

    要检测单个回调,请在回调内部调用 startSegment(),并将主回调逻辑移至处理函数。

    【讨论】:

    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    相关资源
    最近更新 更多