mcpField
S
sentry-setup-tracing

sentry-setup-tracing

github.com/getsentry開発25253 回インストール35 週間前に更新
リポジトリ

sentry-setup-tracing について

sentry-setup-tracingは、Sentryのパフォーマンス監視を設定するスキルです。複数の言語でトランザクション、レイテンシ、カスタムスパンを追跡する方法を示し、実装前に最新ドキュメントを確認するよう案内します。

主な機能

  1. 01複数言語向けSentryトレーシング設定例
  2. 02サンプリング率と動的サンプリングの設定
  3. 03カスタムスパンの作成
  4. 04分散トレース伝播先の設定
  5. 05検証とトラブルシューティング手順

活用シーン

  1. 01API応答時間やページ読み込みの追跡
  2. 02アプリケーション処理へのカスタムスパン追加
  3. 03トラフィックに応じたトレースサンプリングの調整
  4. 04Sentryのパフォーマンスデータ表示の確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/getsentry/sentry-agent-skills --skill sentry-setup-tracing

インストール後、Claude Code で/sentry-setup-tracingを入力して読み込まれたか確認します。

詳細

Sentry トレーシングの設定

Sentry のパフォーマンスモニタリングを設定して、トランザクションとスパンを追跡します。

このスキルを使うタイミング

  • ユーザーが「トレーシングを有効にする」または「パフォーマンスモニタリングを追加する」と尋ねた場合
  • API の応答時間、ページの読み込み時間、またはレイテンシを追跡したい場合
  • tracesSampleRate やカスタムスパンについて尋ねた場合

重要: 以下の SDK バージョン、API 名、コードサンプルは例です。API や最小バージョンが変更されている可能性があるため、実装前に必ず docs.sentry.io で確認してください。

クイックリファレンス

プラットフォーム最小 SDK バージョン有効化カスタムスパン
JS/ブラウザー9.0.0+tracesSampleRate + browserTracingIntegration()Sentry.startSpan()
Next.js9.0.0+各ランタイム設定ファイルの tracesSampleRateSentry.startSpan()
Node.js9.0.0+tracesSampleRateSentry.startSpan()
Python0.11.2+traces_sample_rate@sentry_sdk.trace または start_span()
Ruby5.0.0+traces_sample_rateSentry.with_child_span()

JavaScript の設定

トレーシングを有効にする
Sentry.init({
  dsn: "YOUR_DSN",
  tracesSampleRate: 1.0,  // 1.0 = 100%, lower for production
  integrations: [Sentry.browserTracingIntegration()],  // Browser/React only
  tracePropagationTargets: ["localhost", /^https:\/\/api\./],
});
カスタムスパン
// Async operation
const result = await Sentry.startSpan(
  { name: "fetch-user", op: "http.client" },
  async () => {
    return await fetch("/api/user").then(r => r.json());
  }
);

// Nested spans
await Sentry.startSpan({ name: "checkout", op: "transaction" }, async () => {
  await Sentry.startSpan({ name: "validate", op: "validation" }, validateCart);
  await Sentry.startSpan({ name: "payment", op: "payment" }, processPayment);
});
動的サンプリング
tracesSampler: ({ name, inheritOrSampleWith }) => {
  if (name.includes("healthcheck")) return 0;
  if (name.includes("checkout")) return 1.0;
  return inheritOrSampleWith(0.1);  // Respects parent sampling decision, falls back to 0.1
},

Python の設定

トレーシングを有効にする
sentry_sdk.init(
    dsn="YOUR_DSN",
    traces_sample_rate=1.0,
)
カスタムスパン
# Decorator
@sentry_sdk.trace
def expensive_function():
    return do_work()

# Context manager
with sentry_sdk.start_span(name="process-order", op="task") as span:
    span.set_data("order.id", order_id)
    process(order_id)
動的サンプリング
from sentry_sdk.types import SamplingContext

def traces_sampler(sampling_context: SamplingContext) -> float:
    name = sampling_context.get("transaction_context", {}).get("name", "")
    parent_sampled = sampling_context.get("parent_sampled")
    if "healthcheck" in name: return 0
    if "checkout" in name: return 1.0
    if parent_sampled is not None: return float(parent_sampled)  # Respect parent decision
    return 0.1

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

Ruby の設定

Sentry.init do |config|
  config.dsn = "YOUR_DSN"
  config.traces_sample_rate = 1.0
end

一般的な操作タイプ

op の値用途
http.client送信 HTTP
http.server受信 HTTP
db / db.queryデータベース
cacheキャッシュ操作
queue.taskバックグラウンドジョブ
function関数呼び出し

サンプリングの推奨値

トラフィックレート
開発環境1.0
低(<1K req/min)0.5 - 1.0
中(1K-10K)0.1 - 0.5
高(>10K)0.01 - 0.1

分散トレーシング

API にトレースヘッダーを送信するには、tracePropagationTargets を設定します。

tracePropagationTargets: ["localhost", "https://api.yourapp.com"],

Next.js 14 App Router の場合は、ルートレイアウトに追加します(Next.js 15 以降では不要です)。

export function generateMetadata(): Metadata {
  return { other: { ...Sentry.getTraceData() } };
}

検証

トレーシングを有効にした後、トレース対象の操作(例:HTTP リクエスト)を実行し、Sentry の Performance ダッシュボードでトランザクションを確認します。カスタムスパンは、親トランザクションの下にネストして表示されます。

トラブルシューティング

問題解決策
トランザクションが表示されないtracesSampleRate > 0 を確認し、DSN を検証します
ブラウザーのトレースが見つからないbrowserTracingIntegration() を追加します
分散トレースが接続されないtracePropagationTargets と CORS ヘッダーを確認します
トランザクションが多すぎるサンプルレートを下げるか、tracesSampler を使ってフィルターします

コメント