为什么在 Nest Express 应用中配置的 Sentry 不在仪表板中显示 spans?

huangapple go评论65阅读模式
英文:

why sentry config in nest express app dose not show spans in doshboard?

问题

添加Sentry到Nest应用后,'http.server' span 就会添加到仪表板中。
我的配置如下:

Sentry.init({
  dsn: configService.get('SENTRY_DSN'),
  tracesSampleRate: +configService.get('SENTRY_SAMPLE_RATE'),
  sampleRate: +configService.get('SENTRY_SAMPLE_RATE'),
  environment: configService.get('NODE_ENV'),
  debug: true,
  attachStacktrace: true,
  integrations: [
    new Sentry.Integrations.Http(),
    new Sentry.Integrations.Mysql(),
    new Sentry.Integrations.Modules(),
    new Sentry.Integrations.Express(),
  ],
});

app.use(
  Sentry.Handlers.requestHandler({
    ip: true,
    request: true,
    transaction: true,
    user: true,
  }),
);
app.use(Sentry.Handlers.tracingHandler());

// ...

app.use(Sentry.Handlers.errorHandler());

我的包版本如下:

"@sentry/node": "^7.58.0",
"@sentry-internal/tracing": "7.58.0",
"@sentry/core": "7.58.0",
"@sentry/types": "7.58.0",
"@sentry/utils": "7.58.0",

我需要在仪表板中获取其他 spans。

英文:

After I add Senty to nest app, 'http.server' span just added to the dashboard.
My config is:

 Sentry.init({
      dsn: configService.get('SENTRY_DSN'),
      tracesSampleRate: +configService.get('SENTRY_SAMPLE_RATE'),
      sampleRate: +configService.get('SENTRY_SAMPLE_RATE'),
      environment: configService.get('NODE_ENV'),
      debug: true,
      attachStacktrace: true,
      integrations: [
        new Sentry.Integrations.Http(),
        new Sentry.Integrations.Mysql(),
        new Sentry.Integrations.Modules(),
        new Sentry.Integrations.Express(),
      ],
    });

    app.use(
      Sentry.Handlers.requestHandler({
        ip: true,
        request: true,
        transaction: true,
        user: true,
      }),
    );
    app.use(Sentry.Handlers.tracingHandler());

...

  app.use(Sentry.Handlers.errorHandler());

and my packages are :

    "@sentry/node": "^7.58.0",
    "@sentry-internal/tracing": "7.58.0",
    "@sentry/core": "7.58.0",
    "@sentry/types": "7.58.0",
    "@sentry/utils": "7.58.0",

I need to get other spans in doshboard

答案1

得分: 1

要添加自定义跨度,您可以使用 Sentry.startTransaction() 方法创建一个新事务,然后使用 Sentry.captureSpan() 方法在该事务内捕获单独的跨度。

const transaction = Sentry.startTransaction();

const span = transaction.startChild({
  op: 'custom_operation',
  description: '自定义操作的描述',
});

// 在这里执行您的自定义操作

span.finish();

transaction.finish();
英文:

To add custom spans, you can use the Sentry.startTransaction() method to create a new transaction and then use the Sentry.captureSpan() method to capture individual spans within that transaction.

const transaction = Sentry.startTransaction();

const span = transaction.startChild({
  op: 'custom_operation',
  description: 'Description of the custom operation',
});

// Perform your custom operation here

span.finish();

transaction.finish();

huangapple
  • 本文由 发表于 2023年7月13日 21:05:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定