Logfire(ログ監視ツール)のテレメトリー(システム動作監視用データ)を照会・分析します。トレース、ログ、スパン(処理単位)、メトリクス(計測値)、サマリー、SQL実行結果などに対応しています。 次のような場合に使用: 「Logfireを照会する」「トレースを検索する」「ログを探す」「データを照会する」「スパンを検索する」「Logfireでエラーを調べる」「Logfireからメトリクスを取得する」「テレメトリーを分析する」「エラーをまとめる」「根本原因を特定する」といったユーザーのリクエスト、または、コード内にLogfire照会機能を追加する場合。 注意: Logfireの画面表示、ブラウザ操作、ライブビュー、探索ページ、リンク表示といった直接的なUI操作には使用しないでください。これらは logfire-ui スキルをご使用ください。「表示する」「見る」といった表現が曖昧な場合は、ユーザーに画面表示を希望するのか、照会による分析を希望するのかを確認してください。
Query and analyze Logfire telemetry data — traces, logs, spans, metrics, summaries, and SQL results. Use this skill when the user asks to "query logfire", "search traces", "find logs", "query data", "search spans", "look up errors in logfire", "get metrics from logfire", "analyze telemetry", "summarize errors", "find root cause", or add Logfire querying capabilities to code. Do not use this skill for direct Logfire UI, browser, live-view, Explore-page, or link-opening requests; use logfire-ui instead. If "show" or "view" wording is ambiguous, ask whether the user wants a UI view or query analysis.
次のような場合に使用:
進捗の更新は簡潔に保つこと。ルート分類、ローカルスキルの指示、スキーマ選択、通常のクエリセットアップについて説明しないこと。更新が必要な場合は、「最近の Logfire エラーをクエリ中。」のように、実行中のアクションに絞った短い一文にする。
クエリツールを使用する前に、リクエストを分類すること。
logfire-ui を使用すること。URL を生成するだけの目的で query_run を呼び出さないこと。Logfire UI を開く前にクエリを実行するのは、「最も遅いトレースを見つけて開く」「最新のエラートレースを開く」など、先に検索が必要な不明なアイテムをユーザーが開こうとしている場合に限る。
| 項目 | MCP query_run |
REST API /v1/query |
|---|---|---|
| 最適な用途 | Codex でのインタラクティブな分析 | プロジェクトへのクエリコードの追加 |
| 認証 | MCP セッション経由の OAuth | Bearer 読み取りトークン |
| セットアップ | plugin 経由で設定済み | 読み取りトークンが必要 |
| フォーマット | JSON 行 | JSON、CSV、Apache Arrow |
| デフォルト時間範囲 | 直近 30 分 | 直近 24 時間 |
| 最大範囲 | 14 日間 | 14 日間 |
| 行数制限 | SQL に記述必須 | デフォルト 500、最大 10,000 |
records テーブル(スパンとログ)クエリで使用する主要カラム:
| カラム | 型 | 説明 |
|---|---|---|
start_timestamp |
timestamp (UTC) | スパン/ログの作成日時 |
end_timestamp |
timestamp (UTC) | スパン/ログの完了日時 |
duration |
double(秒) | 開始から終了までの時間。ログの場合は NULL |
trace_id |
string(32桁の16進数) | 一意のトレース識別子 |
span_id |
string(16桁の16進数) | 一意のスパン識別子 |
parent_span_id |
string(16桁の16進数) | 親スパン。ルートスパンの場合は NULL |
span_name |
string | 類似レコードをまとめる低カーディナリティのラベル |
message |
string | 引数が埋め込まれた人間可読の説明文 |
level |
integer | 重大度(level = 'error' の文字列比較も可) |
kind |
string | span、log、span_event、pending_span のいずれか |
service_name |
string | サービス識別子 |
is_exception |
boolean | 例外が記録されたかどうか |
exception_type |
string | 例外クラス名 |
exception_message |
string | 例外メッセージ |
exception_stacktrace |
string | 完全なスタックトレース |
attributes |
JSON | 構造化データ。->>'key' でクエリ可能 |
tags |
string[] | グルーピング用ラベル。array_has(tags, 'x') でクエリ可能 |
http_response_status_code |
integer | HTTP ステータスコード |
http_method |
string | HTTP メソッド |
http_route |
string | HTTP ルートパターン |
otel_status_code |
string | スパンのステータス |
metrics テーブル| カラム | 型 | 説明 |
|---|---|---|
recorded_timestamp |
timestamp (UTC) | メトリクスの記録日時 |
metric_name |
string | メトリクス名 |
metric_type |
string | 種別(gauge、counter、histogram) |
unit |
string | 計測単位 |
scalar_value |
double | メトリクスの値 |
service_name |
string | サービス識別子 |
attributes |
JSON | メトリクスのディメンション |
フルスキーマ: references/schema.md
Logfire は Apache DataFusion(Postgres 互換)を使用。主なパターン:
-- 時間フィルタリング
WHERE start_timestamp > now() - interval '1 hour'
-- JSON 属性へのアクセス
WHERE attributes->>'user_id' = '123'
SELECT attributes->>'http.url' as url FROM records
-- ネストされた JSON
attributes->'request'->>'method'
-- 配列フィルタリング
WHERE array_has(tags, 'production')
-- レベルフィルタリング(文字列比較も有効)
WHERE level = 'error'
-- 大文字小文字を区別しないマッチング
WHERE message ILIKE '%timeout%'
-- 集計用の時間バケット
SELECT time_bucket(interval '5 minutes', start_timestamp) as bucket,
count(*) FROM records GROUP BY bucket ORDER BY bucket
query_run MCP ツールを呼び出す:
query(必須): SQL クエリ文字列project(任意): 対象プロジェクト(デフォルト: ユーザーの現在のプロジェクト)min_timestamp / max_timestamp(任意): 時間範囲を指定する ISO タイムスタンプデフォルトの時間範囲は直近 30 分。最大範囲は 14 日間。SQL には必ず LIMIT を含めること。
-- 最近のエラー
SELECT start_timestamp, message, exception_type, exception_message
FROM records WHERE is_exception LIMIT 20
-- 遅いスパン
SELECT span_name, duration, start_timestamp
FROM records WHERE duration > 1.0 ORDER BY duration DESC LIMIT 20
-- エンドポイントのエラー
SELECT start_timestamp, message, http_response_status_code
FROM records WHERE http_route = '/api/users' AND level = 'error' LIMIT 20
-- トレース全体
SELECT span_name, message, duration, parent_span_id
FROM records WHERE trace_id = '<id>' ORDER BY start_timestamp
-- サービス別エラー集計
SELECT service_name, count(*) as errors
FROM records WHERE is_exception GROUP BY service_name ORDER BY errors DESC
ユーザーが分析と Logfire リンクの両方を明示的に要求した場合は、まずクエリ分析を完了させ、その後判明した結果に対してのみ Logfire リンクを使用する:
trace_id に対しては、ユーザーがすぐにブラウザで開くよう要求した場合のみ project_logfire_link(trace_id=trace_id, project=project, handoff=True) を使用する。永続的または共有可能な URL には project_logfire_link(trace_id=trace_id, project=project) を使用する。logfire-ui のルーティングルールを使用する。スパン数のプロンプトに対して、ユーザーが集計クエリや分析を求めている場合は次のような SQL を提供する:
SELECT
time_bucket(interval '5 minutes', start_timestamp) AS bucket,
count(*) AS span_count
FROM records
WHERE kind = 'span'
GROUP BY bucket
ORDER BY bucket
LIMIT 200
エンドポイント: GET https://logfire-api.pydantic.dev/v1/query
リージョン別のエンドポイント:
https://logfire-us.pydantic.dev/v1/queryhttps://logfire-eu.pydantic.dev/v1/query認証: Authorization: Bearer <read_token>
パラメータ:
sql(必須): SQL クエリmin_timestamp / max_timestamp(任意): ISO タイムスタンプlimit(任意): 行数制限(デフォルト 500、最大 10,000)レスポンスフォーマット(Accept ヘッダーで指定):
application/json — カラム指向 JSON(デフォルト)application/json + row_oriented=true パラメータ — 行指向 JSONtext/csv — CSVapplication/vnd.apache.arrow.stream — Apache ArrowPython クライアント: LogfireQueryClient(同期)、AsyncLogfireQueryClient(非同期)、logfire.db_api(PEP 249 / pandas)
詳細な使用例: references/client-usage.md
min_timestamp/max_timestamp パラメータを使用 — SQL の WHERE 句の代わりに使うservice_name、span_name、trace_id、is_exception は高速フィルター->>'key' を使用(テキストを返す)。ネストされた JSON オブジェクトには -> を使用SELECT * を避ける — 必要なカラムのみを選択するInvoke this skill when:
Keep progress updates terse. Do not narrate route classification, local skill instructions, schema selection, or routine query setup. If an update is needed, use one short sentence focused on the action, such as "Querying recent Logfire errors."
Before using any query tool, classify the request.
logfire-ui; do not call query_run just to make a URL.Only query before opening Logfire UI when the user asks to open a specific unknown item that must be found first, such as "find the slowest trace and open it" or "open the latest error trace".
| Aspect | MCP query_run |
REST API /v1/query |
|---|---|---|
| Best for | Interactive analysis in Codex | Adding query code to a project |
| Auth | OAuth via MCP session | Bearer read token |
| Setup | Already configured via plugin | Need a read token |
| Formats | JSON rows | JSON, CSV, Apache Arrow |
| Default window | Last 30 min | Last 24 hours |
| Max range | 14 days | 14 days |
| Row limit | Must be in SQL | Default 500, max 10,000 |
records table (spans and logs)Key columns for querying:
| Column | Type | Description |
|---|---|---|
start_timestamp |
timestamp (UTC) | When span/log was created |
end_timestamp |
timestamp (UTC) | When span/log completed |
duration |
double (seconds) | Time between start and end; NULL for logs |
trace_id |
string (32 hex) | Unique trace identifier |
span_id |
string (16 hex) | Unique span identifier |
parent_span_id |
string (16 hex) | Parent span; NULL for root spans |
span_name |
string | Low-cardinality label for similar records |
message |
string | Human-readable description with arguments filled in |
level |
integer | Severity (supports level = 'error' string comparison) |
kind |
string | span, log, span_event, or pending_span |
service_name |
string | Service identifier |
is_exception |
boolean | Whether an exception was recorded |
exception_type |
string | Exception class name |
exception_message |
string | Exception message |
exception_stacktrace |
string | Full traceback |
attributes |
JSON | Structured data; query with ->>'key' |
tags |
string[] | Grouping labels; query with array_has(tags, 'x') |
http_response_status_code |
integer | HTTP status code |
http_method |
string | HTTP method |
http_route |
string | HTTP route pattern |
otel_status_code |
string | Span status |
metrics table| Column | Type | Description |
|---|---|---|
recorded_timestamp |
timestamp (UTC) | When metric was recorded |
metric_name |
string | Metric name |
metric_type |
string | Type (gauge, counter, histogram) |
unit |
string | Unit of measurement |
scalar_value |
double | Metric value |
service_name |
string | Service identifier |
attributes |
JSON | Metric dimensions |
Full schema: references/schema.md
Logfire uses Apache DataFusion (Postgres-like). Key patterns:
-- Time filtering
WHERE start_timestamp > now() - interval '1 hour'
-- JSON attribute access
WHERE attributes->>'user_id' = '123'
SELECT attributes->>'http.url' as url FROM records
-- Nested JSON
attributes->'request'->>'method'
-- Array filtering
WHERE array_has(tags, 'production')
-- Level filtering (string comparison works)
WHERE level = 'error'
-- Case-insensitive matching
WHERE message ILIKE '%timeout%'
-- Time bucketing for aggregation
SELECT time_bucket(interval '5 minutes', start_timestamp) as bucket,
count(*) FROM records GROUP BY bucket ORDER BY bucket
Call the query_run MCP tool:
query (required): SQL query stringproject (optional): target project (default: user's current project)min_timestamp / max_timestamp (optional): ISO timestamps for time windowDefault window is last 30 min. Max range is 14 days. Always include LIMIT in SQL.
-- Recent errors
SELECT start_timestamp, message, exception_type, exception_message
FROM records WHERE is_exception LIMIT 20
-- Slow spans
SELECT span_name, duration, start_timestamp
FROM records WHERE duration > 1.0 ORDER BY duration DESC LIMIT 20
-- Endpoint errors
SELECT start_timestamp, message, http_response_status_code
FROM records WHERE http_route = '/api/users' AND level = 'error' LIMIT 20
-- Full trace
SELECT span_name, message, duration, parent_span_id
FROM records WHERE trace_id = '<id>' ORDER BY start_timestamp
-- Error breakdown by service
SELECT service_name, count(*) as errors
FROM records WHERE is_exception GROUP BY service_name ORDER BY errors DESC
If the user explicitly asks for both analysis and a Logfire link, finish the query analysis first, then use a Logfire link only for the known result:
trace_id, use project_logfire_link(trace_id=trace_id, project=project, handoff=True) only when the user asked to open it immediately in the browser. Use project_logfire_link(trace_id=trace_id, project=project) for a durable or shareable URL.logfire-ui routing rules.For a span-count prompt, provide SQL like this when the user wants an aggregate query or analysis:
SELECT
time_bucket(interval '5 minutes', start_timestamp) AS bucket,
count(*) AS span_count
FROM records
WHERE kind = 'span'
GROUP BY bucket
ORDER BY bucket
LIMIT 200
Endpoint: GET https://logfire-api.pydantic.dev/v1/query
Region variants:
https://logfire-us.pydantic.dev/v1/queryhttps://logfire-eu.pydantic.dev/v1/queryAuth: Authorization: Bearer <read_token>
Parameters:
sql (required): SQL querymin_timestamp / max_timestamp (optional): ISO timestampslimit (optional): row limit (default 500, max 10,000)Response formats (via Accept header):
application/json — column-oriented JSON (default)application/json with row_oriented=true param — row-oriented JSONtext/csv — CSVapplication/vnd.apache.arrow.stream — Apache ArrowPython clients: LogfireQueryClient (sync), AsyncLogfireQueryClient (async), logfire.db_api (PEP 249 / pandas).
Detailed examples: references/client-usage.md
min_timestamp/max_timestamp params for simple time windows instead of SQL WHEREservice_name, span_name, trace_id, is_exception are fast filters->>'key' for JSON attribute access (returns text); use -> for nested JSON objectsSELECT * — select only the columns you need原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。