Skip to content

原文(日本語に翻訳) ​

OpenTelemetry: user_prompt イベントにスラッシュコマンド用の command_name と command_source が追加されました。cost.usage、token.usage、api_request、api_error にモデルがエフォートレベルをサポートする場合に effort アトリビュートが追加されました。カスタム/MCPコマンド名は OTEL_LOG_TOOL_DETAILS=1 が設定されていない限りマスクされます。

原文(英語) ​

OpenTelemetry: user_prompt events now include command_name and command_source for slash commands; cost.usage, token.usage, api_request, and api_error now include an effort attribute when the model supports effort levels. Custom/MCP command names are redacted unless OTEL_LOG_TOOL_DETAILS=1 is set

概要 ​

Claude CodeのOpenTelemetryテレメトリデータが強化されました。スラッシュコマンドの実行をより詳細に追跡できる command_name と command_source フィールドが追加され、コスト・トークン使用量・APIリクエストにもエフォートレベル情報が含まれるようになりました。これにより、どのコマンドがどれだけのコストを消費しているかを正確に把握できます。

基本的な使い方 ​

OpenTelemetryを設定している環境では、追加のコードなしに新しいアトリビュートが自動的に含まれます。

bash
# OpenTelemetry エクスポーターを設定
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317"
export OTEL_SERVICE_NAME="claude-code"

# カスタム/MCPコマンド名もログに含める場合
export OTEL_LOG_TOOL_DETAILS=1

claude

実践例 ​

user_prompt イベントの新しいフィールド ​

スラッシュコマンド実行時のイベントデータ例:

json
{
  "event_type": "user_prompt",
  "timestamp": "2026-04-22T10:30:00Z",
  "command_name": "/compact",
  "command_source": "builtin",
  "session_id": "abc123",
  "tokens": 150
}

MCPコマンドの場合(OTEL_LOG_TOOL_DETAILS=1 なし):

json
{
  "event_type": "user_prompt",
  "command_name": "[redacted]",
  "command_source": "mcp"
}

MCPコマンドの場合(OTEL_LOG_TOOL_DETAILS=1 あり):

json
{
  "event_type": "user_prompt",
  "command_name": "/my-custom-command",
  "command_source": "mcp"
}

cost.usage イベントの effort アトリビュート ​

json
{
  "event_type": "cost.usage",
  "model": "claude-opus-4-6",
  "effort": "high",
  "input_tokens": 5000,
  "output_tokens": 800,
  "cost_usd": 0.042
}

Grafana / Datadog でのクエリ例 ​

promql
# エフォートレベル別のコスト集計
sum by (effort) (rate(claude_code_cost_usage_total[5m]))

# スラッシュコマンド別の使用頻度
topk(10, count by (command_name) (claude_code_user_prompt_total))

command_source の値 ​

値説明
builtin組み込みスラッシュコマンド(/compact, /model など)
mcpMCPサーバーが提供するカスタムコマンド
skillスキルとして定義されたコマンド

注意点 ​

  • OTEL_LOG_TOOL_DETAILS=1 を設定しない場合、カスタム/MCPコマンド名はプライバシー保護のためマスクされます
  • effort アトリビュートはエフォートレベルをサポートするモデル(Opus 4.6, Sonnet 4.6 など)でのみ含まれます
  • 既存のOTelパイプラインに新しいアトリビュートが追加されるため、ダッシュボードのフィールド定義の更新が必要な場合があります

関連情報 ​