Sentry-javascript: Sentry.captureExceptionはイベントをSentryに1回だけ送信します(AWS Lambda)

作成日 2019年02月26日  ·  3コメント  ·  ソース: getsentry/sentry-javascript

パッケージ+バージョン

@sentry/node

バージョン:

4.6.3

説明

新しい歩哨SDKをサーバーレスアーキテクチャに統合しようとしています。captureExceptionを呼び出すすべてのハンドラーの周りに一般的なtry-catchがあります。 一言で言えば、これは私たちのコードがどのように見えるかです(私は私たちのビジネスロジックと多くのユーティリティメソッドを省略しました)。

Sentry.init({
  dsn: process.env.sentryUrl,
  environment: process.env.NODE_ENV,
  // debugging issue where we only get an event once
  beforeSend: (event, _) => { console.log(event.exception); return event }
});

async function wrapper(...) {
   try {
     handler(...)
   } catch(error) {
      Sentry.configureScope(scope => {
        scope.setTag("test", "Hello, world")
      })

      const eventId = Sentry.captureException(error)
      // debugging, log event id to see if captureException works
      console.log(eventId)

      const flushResult = await Sentry.flush(1000)
      console.log(flushResult) // see if flush succeeded
   }
}

ハンドラーに常にエラーをスローさせました。 私が最初のリクエストを行うと、すべてがSentryで問題なく終了します。 2番目の要求では、何も起こりません。 CloudWatchを見ると、これが私が見つけたものです。 便宜上コメントを追加しました。

最初のリクエスト:

/// the eventId from captureException
2019-02-26T13:47:22.584Z: 8cf83e38081a4672841a6f795ce8105a 
/// the middleware defined in Sentry.init
2019-02-26T13:47:23.153Z: { values: [ { stacktrace: [Object], type: 'Error', value: 'This is an error' } ] } 
/// result of Sentry.flush
2019-02-26T13:47:23.294Z: true 

二つ目の要求:

/// the eventId from captureException
2019-02-26T13:47:24.761Z fbc2c8b2a4d5447380a0f92dd87896f6
/// result of Sentry.flush
2019-02-26T13:47:24.963Z: true 

ご覧のとおり、2番目のリクエストでbeforeSendミドルウェアにヒットすることはないため、Sentryに送信されることはまったくないと思います。

Sentry.getCurrentHub().getClient().captureException(error) 、毎回Sentryに例外が送信されますが、 Sentry.configureScope構成されたスコープがイベントに適用されることはありません。

これをローカルで再現しようとしましたが、AWSLambdaにデプロイした場合にのみ発生します。

最も参考になるコメント

重複がなくなる可能性があります。
init呼び出しでdebug: trueして、何が起こっているかを確認できます。

実際に重複排除されている場合は、次を使用してこの統合を削除できます。

Sentry.init({
  integrations: integrations => {
    return integrations.filter(integration => integration.name !== 'Dedupe');
  }
});

https://docs.sentry.io/platforms/node/default-integrations/

全てのコメント3件

重複がなくなる可能性があります。
init呼び出しでdebug: trueして、何が起こっているかを確認できます。

実際に重複排除されている場合は、次を使用してこの統合を削除できます。

Sentry.init({
  integrations: integrations => {
    return integrations.filter(integration => integration.name !== 'Dedupe');
  }
});

https://docs.sentry.io/platforms/node/default-integrations/

面白い。 同様の問題を探しているこれを見つけました。 削除重複排除は私のためにそれを修正しました。

バグではないので、これを閉じます。
さらに、次のメジャーバージョンでは、 Dedupeオプションになります。これは、デフォルトで重複排除がないことを意味します。

このページは役に立ちましたか?
0 / 5 - 0 評価