jpskill.com
🛠️ 開発・MCP コミュニティ

claude-code-telemetry-enable

Claude Codeからメトリクス、ログ、トレースといった情報を収集し、可観測性バックエンドへ送信することで、ローカル環境やRailway環境での監視・分析を容易にする設定を自動化するSkill。

📜 元の英語説明(参考)

Enable and configure Claude Code OTEL telemetry for local or Railway observability stacks. Use when setting up Claude Code to send metrics, logs, and traces to observability backends.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Claude Codeからメトリクス、ログ、トレースといった情報を収集し、可観測性バックエンドへ送信することで、ローカル環境やRailway環境での監視・分析を容易にする設定を自動化するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o claude-code-telemetry-enable.zip https://jpskill.com/download/9393.zip && unzip -o claude-code-telemetry-enable.zip && rm claude-code-telemetry-enable.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9393.zip -OutFile "$d\claude-code-telemetry-enable.zip"; Expand-Archive "$d\claude-code-telemetry-enable.zip" -DestinationPath $d -Force; ri "$d\claude-code-telemetry-enable.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して claude-code-telemetry-enable.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → claude-code-telemetry-enable フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Claude Code テレメトリの有効化

Claude Code で OpenTelemetry テレメトリを有効にして、メトリクス、ログ、トレースを可観測性スタック (ローカル LGTM または Railway) に送信します。

使用するタイミング

  • 可観測性スタック (observability-stack-setup) のデプロイ後
  • Claude Code のモニタリングを有効にする必要がある場合
  • ローカルまたはクラウドのバックエンド用にテレメトリを構成したい場合
  • テレメトリの接続性を検証する必要がある場合

この Skill でできること

以下を有効にする Claude Code 環境構成ファイルを作成します。

  • メトリクス: トークンの使用量、コスト、セッション数、ツールのパフォーマンス
  • ログ: ユーザープロンプト (全コンテンツ)、ツールの結果、API リクエスト/エラー
  • トレース: セッションフロー、ツール実行スパン、API 呼び出しトレース

プライバシーに関する注意: 要件に従い、完全なロギング (リダクションなし) 用に構成されています。

クイックスタート

ローカルスタックの場合

# observability-stack-setup を実行した後
# この Skill を以下で呼び出します:
enable-local

# Claude Code はテレメトリを localhost:4317 に送信します

Railway スタックの場合

# Railway にデプロイした後
# この Skill を以下で呼び出します:
enable-railway --endpoint https://your-alloy.railway.app:443

# Claude Code はテレメトリを Railway に送信します

操作

enable-local

ローカル LGTM スタック用に Claude Code を構成します。

作成: ~/.config/claude-code/.env.telemetry

構成:

CLAUDE_CODE_ENABLE_TELEMETRY=1
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

# 高速エクスポート (開発用)
OTEL_METRIC_EXPORT_INTERVAL=10000  # 10 秒
OTEL_LOGS_EXPORT_INTERVAL=5000     # 5 秒

# 完全なロギング (プライバシー制限なし)
OTEL_LOG_USER_PROMPTS=1
OTEL_METRICS_INCLUDE_SESSION_ID=true
OTEL_METRICS_INCLUDE_VERSION=true
OTEL_METRICS_INCLUDE_ACCOUNT_UUID=true

enable-railway

Railway ホストの LGTM スタック用に Claude Code を構成します。

パラメータ:

  • --endpoint: Railway Alloy OTLP エンドポイント URL
  • --token: (オプション) Railway 認証トークン

:

enable-railway \
  --endpoint https://your-alloy-abc123.railway.app:443 \
  --token your-railway-token

作成: Railway エンドポイントを持つ ~/.config/claude-code/.env.telemetry

enable-custom

カスタム OTLP エンドポイント (Grafana Cloud、DataDog など) 用に構成します。

パラメータ:

  • --endpoint: OTLP エンドポイント URL
  • --protocol: grpc または http (デフォルト: grpc)
  • --headers: 認証ヘッダー (例: "Authorization=Bearer token")

:

enable-custom \
  --endpoint https://otlp.grafana.net:443 \
  --protocol grpc \
  --headers "Authorization=Basic base64encodedcreds"

verify

テレメトリ構成と接続性をテストします。

チェック:

  1. 構成ファイルが存在するか
  2. 必要な環境変数が設定されているか
  3. OTLP エンドポイントに到達可能か
  4. テストテレメトリが正常に送信されたか
  5. バックエンド (Grafana/Loki/Prometheus/Tempo) でデータが表示されるか

出力:

Telemetry Configuration Check:
✅ Config file: ~/.config/claude-code/.env.telemetry
✅ CLAUDE_CODE_ENABLE_TELEMETRY=1
✅ OTLP endpoint: localhost:4317
✅ Endpoint reachable
✅ Test span sent successfully
✅ Data visible in Grafana

Status: HEALTHY - Telemetry fully operational

disable

テレメトリを完全にオフにします。

アクション:

  1. .env.telemetry の名前を .env.telemetry.disabled に変更します
  2. または CLAUDE_CODE_ENABLE_TELEMETRY=0 を設定します

再有効化: ファイル名を元に戻すか、enable-local / enable-railway を再度使用します

status

現在のテレメトリ構成を表示します。

出力:

Telemetry Status:
  State: ENABLED
  Endpoint: http://localhost:4317
  Protocol: gRPC
  Privacy: FULL LOGGING (all data captured)
  Export Intervals: Metrics 10s, Logs 5s

  Captured Data:
    - User prompts (full content)
    - Tool executions (all tools)
    - API requests (tokens, cost, latency)
    - Session metadata (IDs, version, account)

構成の詳細

環境変数

必須:

  • CLAUDE_CODE_ENABLE_TELEMETRY: 有効にする場合は 1、無効にする場合は 0
  • OTEL_EXPORTER_OTLP_ENDPOINT: OTLP エンドポイント URL
  • OTEL_EXPORTER_OTLP_PROTOCOL: grpc または http

エクスポーター:

  • OTEL_METRICS_EXPORTER: otlp (OTLP 経由でメトリクスを送信)
  • OTEL_LOGS_EXPORTER: otlp (OTLP 経由でログを送信)

エクスポート間隔:

  • OTEL_METRIC_EXPORT_INTERVAL: メトリクスエクスポート間のミリ秒数 (デフォルト: 60000)
  • OTEL_LOGS_EXPORT_INTERVAL: ログエクスポート間のミリ秒数 (デフォルト: 5000)

プライバシー制御 (完全なロギング用に構成):

  • OTEL_LOG_USER_PROMPTS: 1 = プロンプトの全コンテンツをログに記録、0 = 長さのみをログに記録
  • OTEL_METRICS_INCLUDE_SESSION_ID: true = メトリクスにセッション ID を含める
  • OTEL_METRICS_INCLUDE_VERSION: true = Claude Code バージョンを含める
  • OTEL_METRICS_INCLUDE_ACCOUNT_UUID: true = アカウント識別子を含める

認証 (クラウドバックエンドの場合):

  • OTEL_EXPORTER_OTLP_HEADERS: 認証用のヘッダー (例: "Authorization=Bearer token")

キャプチャされるもの

メトリクス (カウンター、ゲージ、ヒストグラム):

  • claude_code.session.count - セッション頻度
  • claude_code.token.usage - トークン消費量 (入力 + 出力)
  • claude_code.cost.usage - USD での API コスト
  • claude_code.code_edit_tool.decision - 受け入れ/拒否パターン
  • claude_code.active_time.total - エンゲージメント期間 (秒)
  • claude_code.pull_request.count - PR 作成数
  • claude_code.commit.count - Git コミット数

ログイベント (構造化 JSON):

  1. claude_code.user_prompt - ユーザープロンプトの送信 (全コンテンツ)
  2. claude_code.tool_result - ツールの実行結果 (ツール名、ステータス、期間)
  3. claude_code.api_request - Claude API 呼び出し (モデル、トークン、コスト、レイテンシー)
  4. claude_code.api_error - 失敗した API リクエスト (ステータスコード、再試行回数)
  5. claude_code.tool_decision - 許可の決定 (承認/拒否)

トレース (分散トレーシング):

  • セッショントレース: 完全な会話ワークフロー
  • ツール呼び出しスパン: Read、Write、Edit、Bash、Glob、Grep、Task など
  • エージェントタスクスパン: 並列エージェント実行
  • API リクエストスパン: Claude API l
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Claude Code Telemetry Enable

Enable OpenTelemetry telemetry in Claude Code to send metrics, logs, and traces to your observability stack (local LGTM or Railway).

When to Use

  • After deploying observability stack (observability-stack-setup)
  • Need to enable Claude Code monitoring
  • Want to configure telemetry for local or cloud backends
  • Need to verify telemetry connectivity

What This Skill Does

Creates Claude Code environment configuration files that enable:

  • Metrics: Token usage, costs, session counts, tool performance
  • Logs: User prompts (full content), tool results, API requests/errors
  • Traces: Session flows, tool execution spans, API call traces

Privacy Note: Configured for FULL LOGGING (no redactions) per your requirements.

Quick Start

For Local Stack

# After running observability-stack-setup
# Invoke this skill with:
enable-local

# Claude Code will now send telemetry to localhost:4317

For Railway Stack

# After deploying to Railway
# Invoke this skill with:
enable-railway --endpoint https://your-alloy.railway.app:443

# Claude Code will send telemetry to Railway

Operations

enable-local

Configure Claude Code for local LGTM stack.

Creates: ~/.config/claude-code/.env.telemetry

Configuration:

CLAUDE_CODE_ENABLE_TELEMETRY=1
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

# Fast export (for development)
OTEL_METRIC_EXPORT_INTERVAL=10000  # 10 seconds
OTEL_LOGS_EXPORT_INTERVAL=5000     # 5 seconds

# FULL LOGGING (no privacy restrictions)
OTEL_LOG_USER_PROMPTS=1
OTEL_METRICS_INCLUDE_SESSION_ID=true
OTEL_METRICS_INCLUDE_VERSION=true
OTEL_METRICS_INCLUDE_ACCOUNT_UUID=true

enable-railway

Configure Claude Code for Railway-hosted LGTM stack.

Parameters:

  • --endpoint: Railway Alloy OTLP endpoint URL
  • --token: (Optional) Railway authentication token

Example:

enable-railway \
  --endpoint https://your-alloy-abc123.railway.app:443 \
  --token your-railway-token

Creates: ~/.config/claude-code/.env.telemetry with Railway endpoint

enable-custom

Configure for custom OTLP endpoint (Grafana Cloud, DataDog, etc.).

Parameters:

  • --endpoint: OTLP endpoint URL
  • --protocol: grpc or http (default: grpc)
  • --headers: Authentication headers (e.g., "Authorization=Bearer token")

Example:

enable-custom \
  --endpoint https://otlp.grafana.net:443 \
  --protocol grpc \
  --headers "Authorization=Basic base64encodedcreds"

verify

Test telemetry configuration and connectivity.

Checks:

  1. Configuration file exists
  2. Required environment variables set
  3. OTLP endpoint reachable
  4. Test telemetry successfully sent
  5. Data visible in backend (Grafana/Loki/Prometheus/Tempo)

Output:

Telemetry Configuration Check:
✅ Config file: ~/.config/claude-code/.env.telemetry
✅ CLAUDE_CODE_ENABLE_TELEMETRY=1
✅ OTLP endpoint: localhost:4317
✅ Endpoint reachable
✅ Test span sent successfully
✅ Data visible in Grafana

Status: HEALTHY - Telemetry fully operational

disable

Turn off telemetry completely.

Actions:

  1. Renames .env.telemetry to .env.telemetry.disabled
  2. OR sets CLAUDE_CODE_ENABLE_TELEMETRY=0

Re-enable: Rename file back or use enable-local / enable-railway again

status

Show current telemetry configuration.

Output:

Telemetry Status:
  State: ENABLED
  Endpoint: http://localhost:4317
  Protocol: gRPC
  Privacy: FULL LOGGING (all data captured)
  Export Intervals: Metrics 10s, Logs 5s

  Captured Data:
    - User prompts (full content)
    - Tool executions (all tools)
    - API requests (tokens, cost, latency)
    - Session metadata (IDs, version, account)

Configuration Details

Environment Variables

Essential:

  • CLAUDE_CODE_ENABLE_TELEMETRY: 1 to enable, 0 to disable
  • OTEL_EXPORTER_OTLP_ENDPOINT: OTLP endpoint URL
  • OTEL_EXPORTER_OTLP_PROTOCOL: grpc or http

Exporters:

  • OTEL_METRICS_EXPORTER: otlp (send metrics via OTLP)
  • OTEL_LOGS_EXPORTER: otlp (send logs via OTLP)

Export Intervals:

  • OTEL_METRIC_EXPORT_INTERVAL: Milliseconds between metric exports (default: 60000)
  • OTEL_LOGS_EXPORT_INTERVAL: Milliseconds between log exports (default: 5000)

Privacy Controls (configured for FULL logging):

  • OTEL_LOG_USER_PROMPTS: 1 = log full prompt content, 0 = log length only
  • OTEL_METRICS_INCLUDE_SESSION_ID: true = include session IDs in metrics
  • OTEL_METRICS_INCLUDE_VERSION: true = include Claude Code version
  • OTEL_METRICS_INCLUDE_ACCOUNT_UUID: true = include account identifier

Authentication (for cloud backends):

  • OTEL_EXPORTER_OTLP_HEADERS: Headers for authentication (e.g., "Authorization=Bearer token")

What Gets Captured

Metrics (counters, gauges, histograms):

  • claude_code.session.count - Session frequency
  • claude_code.token.usage - Token consumption (input + output)
  • claude_code.cost.usage - API costs in USD
  • claude_code.code_edit_tool.decision - Accept/reject patterns
  • claude_code.active_time.total - Engagement duration (seconds)
  • claude_code.pull_request.count - PR creation count
  • claude_code.commit.count - Git commit count

Log Events (structured JSON):

  1. claude_code.user_prompt - User prompt submissions (full content)
  2. claude_code.tool_result - Tool execution outcomes (tool name, status, duration)
  3. claude_code.api_request - Claude API calls (model, tokens, cost, latency)
  4. claude_code.api_error - Failed API requests (status codes, retry attempts)
  5. claude_code.tool_decision - Permission decisions (approved/rejected)

Traces (distributed tracing):

  • Session traces: Complete conversation workflows
  • Tool call spans: Read, Write, Edit, Bash, Glob, Grep, Task, etc.
  • Agent task spans: Parallel agent execution
  • API request spans: Claude API latency breakdown

Retention

All data stored for 365 days (configured in observability stack).

File Locations

Configuration File:

  • Linux/WSL: ~/.config/claude-code/.env.telemetry
  • macOS: ~/.config/claude-code/.env.telemetry
  • Windows: %USERPROFILE%\.config\claude-code\.env.telemetry

Managed Settings (organization-enforced, optional):

  • Linux: /etc/claude-code/managed-settings.json
  • macOS: /Library/Application Support/ClaudeCode/managed-settings.json
  • Windows: C:\ProgramData\ClaudeCode\managed-settings.json

Troubleshooting

Telemetry Not Appearing in Grafana

Check 1: Is telemetry enabled?

cat ~/.config/claude-code/.env.telemetry
# Should show CLAUDE_CODE_ENABLE_TELEMETRY=1

Check 2: Is OTLP endpoint reachable?

curl -v http://localhost:4317
# Should connect (may get empty response, that's ok)

Check 3: Is observability stack running?

docker compose -f .observability/docker-compose.yml ps
# All 5 services should be "running"

Check 4: Use Claude Code and check immediately

# After using Claude Code, query Loki:
curl -s 'http://localhost:3100/loki/api/v1/query?query={job="claude_code"}' | jq .
# Should show recent logs

Port Already in Use (4317)

If another service is using port 4317:

Option 1: Stop the conflicting service

sudo lsof -i :4317
sudo kill <PID>

Option 2: Change Alloy port in observability stack Edit .observability/docker-compose.yml:

ports:
  - "4318:4317"  # Expose on 4318 instead

Then update telemetry config:

OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

Permission Denied

If configuration file creation fails:

# Create directory manually
mkdir -p ~/.config/claude-code
chmod 755 ~/.config/claude-code

# Try again

Next Steps

After enabling telemetry:

  1. Use Claude Code: Run tools (Read, Write, Bash, etc.)
  2. Generate telemetry: Each operation sends data
  3. View in Grafana: Open http://localhost:3000
  4. Check dashboards: Navigate to "Claude Code Overview"
  5. Verify metrics: See token usage, costs, tool calls

References

  • references/env-telemetry-local.txt - Local configuration template
  • references/env-telemetry-railway.txt - Railway configuration template
  • references/env-telemetry-custom.txt - Custom endpoint template
  • references/telemetry-variables.md - All environment variables explained
  • references/privacy-settings.md - Privacy configuration options

Scripts

  • scripts/enable-local.sh - Enable for local stack
  • scripts/enable-railway.sh - Enable for Railway
  • scripts/verify-telemetry.sh - Test configuration and connectivity
  • scripts/disable-telemetry.sh - Turn off telemetry