【问题标题】:How does one implement Sentry Performance tracing (@sentry/tracing) in Node/Express如何在 Node/Express 中实现 Sentry 性能跟踪(@sentry/tracing)
【发布时间】:2020-12-16 04:24:26
【问题描述】:

我正在尝试将 @sentry/tracing 集成到 NodeJS + Express 应用程序中。

似乎没有我能找到的任何文档(我已向文档库here 提交了一个问题)。

我查看了@sentry/tracing 代码,似乎有一个 Express 集成可用。

基于集成源代码,它看起来应该像这样实例化:

const express = require('express');

const app = express();

const Sentry = require('@sentry/node');
const { Integrations } = require( "@sentry/tracing");

Sentry.init({ 
    dsn: __MY_SENTRY_DSN__,
    integrations: [
        new Integrations.Express({app}),
    ]
});

我已经尝试过了,但我没有在 Sentry 中获得任何跟踪数据。

【问题讨论】:

    标签: node.js express sentry


    【解决方案1】:

    好的,基本上,我们这里需要的主要跟踪组件是一个单独的 express 处理程序。

    该跟踪处理程序实际上是 @sentry/node 包的一部分(因为逻辑),并且可以作为 Sentry.Handlers.tracingHandler 访问

    所以正确的初始化步骤是:

    Sentry.init({ 
        tracesSampleRate: 1.0,  // <- ** you need this one here (Note: the docs for the BrowserTracing version says to use less for production environment or it might suck all your quota) **
        dsn: __MY_SENTRY_DSN__,
        // ...
    });
    
    app.use(Sentry.Handlers.requestHandler());
    
    app.use(Sentry.Handlers.tracingHandler()); // <- ** and add this one here **
    
    // your route handlers
    
    app.use(Sentry.Handlers.errorHandler());
    

    配置完成后,您应该会开始在“性能”选项卡中看到跟踪数据。

    这留下了一个未解决的问题。Integrations.Express 是什么?

    基本上,它似乎正在做的事情(并且它是可选的)是为跟踪中的每个中间件调用显示子帧(其术语中的 Spans)。

    这是一个没有的痕迹:

    这是一个跟踪:

    这就是我能够弄清楚的。如果你觉得有什么错误或者有更好的方法,请指正。

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 2021-01-03
      • 2021-01-27
      • 2020-01-01
      • 2014-10-22
      • 2021-11-03
      • 2021-08-06
      • 2020-02-29
      • 2019-03-13
      相关资源
      最近更新 更多