0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Sentryの設定項「traces_sampler」の役割

Posted at

Sentryの設定項目「traces_sampler」は、トランザクションごとにサンプリング率を動的に決定するための機能です。この設定により、パフォーマンストレースのどの部分を収集・保存するかを、リクエストやコンテキストに応じて柔軟に調整できます。

主な役割と使用例

  • 動的なサンプリング: traces_sampler は関数を指定する形式で設定され、各トランザクションのサンプリング率を動的に設定します。例えば、特定のリクエストパスやユーザー属性に基づいて、トレースの収集頻度を変えられます。
  • 効率的なデータ収集: 大量のトランザクションを発生させるシステムであっても、traces_sampler により、重要なトランザクションのみを選んで収集し、データの保存コストを抑えつつ分析に役立つ情報を収集することができます。
  • サンプルのカスタマイズ: traces_sampler に設定する関数では、トランザクションのメタデータ(例:ユーザー情報、リクエストパス、サービス名など)に基づいてサンプリング率を変更できるため、特定のエンドポイントや機能の詳細なパフォーマンスを追跡する際に役立ちます。

設定例

以下は、traces_sampler を使って特定のリクエストパスに基づいてサンプリング率を設定する例です。

def traces_sampler(sampling_context):
    # 特定のパスの場合、サンプリング率を100%に設定
    if sampling_context["transaction_context"]["op"] == "http.server" and \
       sampling_context["transaction_context"]["description"].startswith("/important-path"):
        return 1.0  # 100%収集

    # その他のトランザクションは10%の確率で収集
    return 0.1

sentry_sdk.init(
    dsn="YOUR_SENTRY_DSN",
    traces_sampler=traces_sampler
)

この例では、特定のパス(例:/important-path)については100%の確率でトレースが収集され、それ以外のトランザクションは10%の確率で収集されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?