🔍logfire-query
- プラグイン
- logfire
- ソース
- GitHub で見る ↗
説明
Logfire のテレメトリデータ(トレース、ログ、スパン、メトリクス、サマリー、SQL 結果)をクエリおよび分析します。 次のような場合に使用: ユーザーが「logfire をクエリする」「トレースを検索する」「ログを探す」「データをクエリする」「スパンを検索する」「logfire でエラーを調べる」「logfire からメトリクスを取得する」「テレメトリを分析する」「エラーを要約する」「根本原因を特定する」といった操作を求める場合、またはコードに Logfire クエリ機能を追加したい場合。 Logfire の UI 直接操作、ブラウザ操作、ライブビュー、Explore ページ、リンクを開くといったリクエストにはこのスキルを使用しないでください。それらには `logfire-ui` を使用してください。 「表示する」「見る」といった表現が曖昧な場合は、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.
ユースケース
- ✓トレースやログを検索したい
- ✓テレメトリデータを分析したい
- ✓エラーの根本原因を特定したい
- ✓メトリクスやSQL結果を取得したい
- ✓Logfireクエリ機能をコードに追加したい
本文(日本語訳)
Logfire データのクエリ
このスキルの使用タイミング
次のような場合に使用:
- ユーザーが Logfire からトレース、ログ、スパン、またはメトリクスをクエリしたい場合
- ユーザーがテレメトリデータの中から特定のイベント、エラー、またはパターンを検索したい場合
- ユーザーが Logfire に保存された OpenTelemetry データを分析したい場合
- ユーザーがコードにプログラマティックなクエリ機能を追加したい場合
- ユーザーが「logfire をクエリ」「トレースを検索」「ログを見つける」「メトリクスを取得」「カウント」「要約」「比較」「根本原因を特定」などと要求した場合
ユーザー向けの進捗表示
進捗の更新は簡潔に保つこと。ルート分類、ローカルスキルの指示、スキーマ選択、通常のクエリセットアップについて説明しないこと。更新が必要な場合は、「最近の Logfire エラーをクエリ中。」のように、実行中のアクションに絞った短い一文にする。
重要なルーティング: 1リクエストにつき1ワークフロー
クエリツールを使用する前に、リクエストを分類すること。
- クエリルート: 「分析」「クエリ」「カウント」「要約」「比較」「根本原因を特定」「最も遅いものを見つける」「エラーを調べる」「メトリクスを取得」「クエリ機能を追加」
- UI ルート: 「開く」「ブラウザで表示」「Codex で表示」「Logfire で表示」「ライブビュー」「Explore を開く」「UI を開く」「リンクをください」、または GUI/ブラウザでの表示。
logfire-uiを使用すること。URL を生成するだけの目的でquery_runを呼び出さないこと。 - 曖昧なルート: 「最近のエラーを表示」「ログを見る」「スパンを表示」などのプロンプトは、ユーザーがチャットでの分析を望んでいるのか Logfire UI を望んでいるのかが不明。クエリ分析か UI 表示かをユーザーに確認すること。
- 複合ルート: ユーザーが分析とリンクの両方を明示的に要求した場合、要求された分析または対象アイテムの特定のためのクエリのみを実行し、関連する Logfire リンクを提供する。ユーザーが要求しない限り、UI/ブラウザ操作を追加しないこと。
Logfire UI を開く前にクエリを実行するのは、「最も遅いトレースを見つけて開く」「最新のエラートレースを開く」など、先に検索が必要な不明なアイテムをユーザーが開こうとしている場合に限る。
2つのアプローチ
| 項目 | 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
SQL 構文
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
MCP アプローチ(インタラクティブ)
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
クエリ後の UI リンク
ユーザーが分析と 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
REST API アプローチ(プログラマティック)
エンドポイント: GET https://logfire-api.pydantic.dev/v1/query
リージョン別のエンドポイント:
- US:
https://logfire-us.pydantic.dev/v1/query - EU:
https://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 Arrow
Python クライアント: LogfireQueryClient(同期)、AsyncLogfireQueryClient(非同期)、logfire.db_api(PEP 249 / pandas)
詳細な使用例: references/client-usage.md
クエリのベストプラクティス
- 必ず LIMIT を付ける — まず 20 から始め、必要に応じて増やす
- 単純な時間範囲には
min_timestamp/max_timestampパラメータを使用 — SQL のWHERE句の代わりに使う - 効率的なフィルタリング —
service_name、span_name、trace_id、is_exceptionは高速フィルター - JSON 属性のアクセスには
->>'key'を使用(テキストを返す)。ネストされた JSON オブジェクトには->を使用 SELECT *を避ける — 必要なカラムのみを選択する- 最大 14 日間 — 14 日を超える範囲のクエリは実行不可
原文(English)を表示
Query Logfire Data
When to Use This Skill
Invoke this skill when:
- User wants to query traces, logs, spans, or metrics from Logfire
- User wants to search for specific events, errors, or patterns in telemetry data
- User wants to analyze OpenTelemetry data stored in Logfire
- User wants to add programmatic query capabilities to their code
- User asks to "query logfire", "search traces", "find logs", "get metrics", "count", "summarize", "compare", or "find root cause"
User-Facing Progress
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."
Critical Routing: One Workflow Per Request
Before using any query tool, classify the request.
- Query route: "analyze", "query", "count", "summarize", "compare", "find root cause", "find slowest", "look up errors", "get metrics", or "add query capabilities".
- UI route: "open", "show in browser", "show in Codex", "show in Logfire", "live view", "open Explore", "open the UI", "give me a link", or GUI/browser presentation. Use
logfire-ui; do not callquery_runjust to make a URL. - Ambiguous route: prompts like "show recent errors", "view logs", or "show spans" do not specify whether the user wants chat analysis or the Logfire UI. Ask the user to choose query analysis or UI view.
- Combined route: if the user explicitly asks for both analysis and a link, query only for the requested analysis or to identify the requested item, then provide the relevant Logfire link. Do not add UI/browser work unless the user asked for it.
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".
Two Approaches
| 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 |
Quick Schema Reference
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
SQL Syntax
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
MCP Approach (Interactive)
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 window
Default window is last 30 min. Max range is 14 days. Always include LIMIT in SQL.
Common queries
-- 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
UI Links After Querying
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:
- For a known
trace_id, useproject_logfire_link(trace_id=trace_id, project=project, handoff=True)only when the user asked to open it immediately in the browser. Useproject_logfire_link(trace_id=trace_id, project=project)for a durable or shareable URL. - For a project/filter view, use the
logfire-uirouting rules. - Do not open the browser unless the user asked to open the link.
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
REST API Approach (Programmatic)
Endpoint: GET https://logfire-api.pydantic.dev/v1/query
Region variants:
- US:
https://logfire-us.pydantic.dev/v1/query - EU:
https://logfire-eu.pydantic.dev/v1/query
Auth: 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/jsonwithrow_oriented=trueparam — row-oriented JSONtext/csv— CSVapplication/vnd.apache.arrow.stream— Apache Arrow
Python clients: LogfireQueryClient (sync), AsyncLogfireQueryClient (async), logfire.db_api (PEP 249 / pandas).
Detailed examples: references/client-usage.md
Query Best Practices
- Always LIMIT — start with 20, increase as needed
- Use
min_timestamp/max_timestampparams for simple time windows instead of SQLWHERE - Filter efficiently —
service_name,span_name,trace_id,is_exceptionare fast filters - Use
->>'key'for JSON attribute access (returns text); use->for nested JSON objects - Avoid
SELECT *— select only the columns you need - Max 14-day range — queries cannot span more than 14 days
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。