posthog-exploring-llm-traces
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "posthog-exploring-llm-traces":https://skillpi.com/zh/skills/deepskill-621f33083c39990511468e73aa44c97ac15518eaf2a9ba0f5696f37467a1e266。安装前核对上游来源和版本:https://skills.sh/posthog/ai-plugin/exploring-llm-traces。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skills.sh
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
用于调试和检查使用 PostHog 的 LLM/AI 代理追踪记录。当用户粘贴追踪记录或会话 URL(例如 /ai-observability/traces/<id> 或 /ai-observability/sessions/<id>)、要求调试追踪、排查问题、检查代理是否正确使用工具、验证上下文或文件是否被正确呈现、检查子代理行为、调查 LLM 决策或分析 token 使用量与成本时使用。也应在对 events.properties.$ai_input / $ai_output_choices 执行原始 SQL/HogQL 查询返回空结果时使用——相关消息内容仅存在于专用的 posthog.ai_events 表中。
介绍来源: third_party · posthog · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: exploring-llm-traces
description: >
ABSOLUTE MUST to debug and inspect LLM/AI agent traces using PostHog's MCP tools.
Use when the user pastes a trace or session URL (e.g. /ai-observability/traces/<id> or /ai-observability/sessions/<id>),
asks to debug a trace, figure out what went wrong, check if an agent used a tool correctly,
verify context/files were surfaced, inspect subagent behavior, investigate LLM decisions,
or analyze token usage and costs. Also use when raw SQL/HogQL against
`events.properties.$ai_input` / `$ai_output_choices` returns empty — message content lives only
on the dedicated `posthog.ai_events` table.Exploring LLM traces with MCP tools
PostHog captures LLM/AI agent activity as traces. Each trace is a tree of events representing a single AI interaction — from the top-level agent invocation down to individual LLM API calls.
Available tools
| Tool | Purpose |
|---|---|
posthog:query-llm-traces-list |
Search and list traces; can return large multi-trace payloads |
posthog:query-llm-trace |
Get a single trace by ID with full event tree |
posthog:read-data-schema |
Discover custom event/person properties before filtering |
posthog:execute-sql |
Ad-hoc SQL for complex trace analysis |
Event hierarchy
See the event reference for the full schema.
$ai_trace (top-level container)
└── $ai_span (logical groupings, e.g. "RAG retrieval", "tool execution")
├── $ai_generation (individual LLM API call)
└── $ai_embedding (embedding creation)
Events are linked via $ai_parent_id → parent's $ai_span_id or $ai_trace_id.
Workflow: debug a trace or session from a URL
Step 1 — Classify the URL
First inspect the path. Do not treat every UUID-looking value as a trace ID.
/ai-observability/traces/<trace_id>or legacy/llm-analytics/traces/<trace_id>//llm-observability/traces/<trace_id>is a single trace. Fetch it withposthog:query-llm-trace./ai-observability/sessions/<session_id>or legacy/llm-analytics/sessions/<session_id>is an AI session, not a trace. Fetch traces withposthog:query-llm-traces-listfiltered by event property$ai_session_id.
Preserve date_from / date_to query parameters from the URL when present.
If none are present but the URL has a timestamp query parameter, use that timestamp as the anchor and query an absolute window around it, for example timestamp - 36h to timestamp + 36h.
This handles exact session links whose UI timestamp may be offset from the stored event timestamps while keeping the query bounded.
If the URL has neither explicit dates nor timestamp, use a safe default like {"date_from": "-7d"}.
For exact trace and session URLs, skip schema discovery for the standard $ai_* fields used below. These are AI observability built-ins, not project-specific custom properties.
Step 2 — Fetch trace data
For a trace URL, call posthog:query-llm-trace with:
{
"traceId": "<trace_id>",
"dateRange": { "date_from": "-7d" }
}
For a session URL, call posthog:query-llm-traces-list with:
{
"dateRange": { "date_from": "<timestamp_minus_36h>", "date_to": "<timestamp_plus_36h>" },
"filterTestAccounts": false,
"limit": 20,
"properties": [{ "type": "event", "key": "$ai_session_id", "value": ["<session_id>"], "operator": "exact" }]
}
Use the URL's date_from / date_to values in the session query if present.
If the URL only has timestamp, calculate the absolute date range from that timestamp instead of using a relative range like -1h.
Set filterTestAccounts: false for an exact URL so the requested trace is not hidden by account filters.
The result contains the event tree with all properties. The response may be large — when it exceeds the inline limit, Claude Code auto-persists it to a file.
From the result you get:
- Every event with its type (
$ai_span,$ai_generation, etc.) - Span names (
$ai_span_name) — these are the tool/step names - Latency, error flags, models used
- Parent-child relationships via
$ai_parent_id _posthogUrl— always include this in your response so the user can click through to the UI
Step 3 — Parse large results with scripts
When the result is persisted to a file (large traces with full $ai_input/$ai_output_choices),
use the parsing scripts to explore it.
Start with the summary to get the full picture, then drill into specifics:
# 1. Overview: metadata, tool calls, final output, errors
python3 scripts/print_summary.py /path/to/persisted-file.json
# 2. Timeline: chronological event list with truncated I/O
python3 scripts/print_timeline.py /path/to/persisted-file.json
# 3. Drill into a specific span's full input/output
SPAN="tool_name" python3 scripts/extract_span.py /path/to/persisted-file.json
# 4. Full conversation with thinking blocks and tool calls
python3 scripts/extract_conversation.py /path/to/persisted-file.json
# 5. Search for a keyword across all properties
SEARCH="keyword" python3 scripts/search_traces.py /path/to/persisted-file.json
All scripts support MAX_LEN=N env var to control truncation (0 = unlimited).
Investigation patterns
"Did the agent use the tool correctly?"
- Find the
$ai_spanfor the tool call (look at$ai_span_name) - Check
$ai_input_state— what arguments were passed to the tool? - Check
$ai_output_state— what did the tool return? - Check
$ai_is_error— did the tool call fail?
"Was the context correct?" / "Were the right files surfaced?"
- Find the
$ai_generationevent where the LLM made the decision - Check
$ai_input— this is the full message history the LLM saw - Look at preceding
$ai_spanevents for retrieval/search steps - Check their
$ai_output_state— what content was retrieved and fed to the LLM?
"Did the subagent work?"
- In the structural overview, find spans that are children of other spans (via
$ai_parent_id) - The parent span is the orchestrator; child spans are subagent steps
- Check each child's
$ai_output_stateand$ai_is_error - If a child span contains
$ai_generationevents, those are the subagent's LLM calls
"Why did the LLM say X?"
- Use
search_traces.pyto find where the text appears:SEARCH="the text" python3 scripts/search_traces.py FILE - This shows which event and property path contains it
- Check the
$ai_inputof that generation to see what the LLM was told before it said X
Constructing UI links
The trace tools return _posthogUrl — always surface this to the user.
You can also construct links manually:
- Trace detail:
https://app.posthog.com/ai-observability/traces/<trace_id>?timestamp=<url_encoded_timestamp>&event=<optional_event_id> - Traces list with filters: returned in
_posthogUrlfromquery-llm-traces-list
The timestamp query param is required — use the createdAt of the earliest event in the trace, URL-encoded (e.g. timestamp=2026-04-01T19%3A39%3A20Z).
When presenting findings, always include the relevant PostHog URL so the user can verify.
Finding traces
Use posthog:query-llm-traces-list to search and filter traces.
CRITICAL: Never assume event names, property names, or property values from training data.
Every project instruments different custom properties. For open-ended searches and custom filters, call
posthog:read-data-schema first to discover what properties and values actually exist in the project's
data before constructing filters.
The exception is exact AI observability trace/session URLs: use the built-in $ai_trace_id / $ai_session_id
fields directly and skip schema discovery.
Discovering the schema first
Before filtering traces, discover what's available:
- Confirm AI events exist — call
posthog:read-data-schemawithkind: "events"and look for$ai_*events - Find filterable properties — call
posthog:read-data-schemawithkind: "event_properties"andevent_name: "$ai_generation"(or another AI event) to see what properties are captured - Get actual values — call
posthog:read-data-schemawithkind: "event_property_values",event_name: "$ai_generation", andproperty_name: "$ai_model"to see real model names in use
Only then construct the query-llm-traces-list call with property filters.
This is especially important for custom properties like project_id, conversation_id, user_tier, etc. — these vary per project and cannot be guessed.
Do not confirm $ai_* properties, but confirm any other like email of a person.
By filters
posthog:query-llm-traces-list
{
"dateRange": {"date_from": "-1h"},
"filterTestAccounts": true,
"limit": 20,
"properties": [
{"type": "event", "key": "$ai_model", "value": "gpt-4o", "operator": "exact"}
]
}
Multiple filters are AND-ed together:
posthog:query-llm-traces-list
{
"dateRange": {"date_from": "-1h"},
"filterTestAccounts": true,
"properties": [
{"type": "event", "key": "$ai_provider", "value": "anthropic", "operator": "exact"},
{"type": "event", "key": "$ai_is_error", "value": ["true"], "operator": "exact"}
]
}
You can also filter by person properties (discover them via read-data-schema with kind: "entity_properties" and entity: "person"):
posthog:query-llm-traces-list
{
"dateRange": {"date_from": "-1h"},
"filterTestAccounts": true,
"properties": [
{"type": "person", "key": "email", "value": "@company.com", "operator": "icontains"}
]
}
By external identifiers
Customers often store their own IDs as event or person properties.
Use posthog:read-data-schema to discover what custom properties exist, then filter:
- Call
posthog:read-data-schemawithkind: "event_properties"andevent_name: "$ai_trace"to find custom properties - Review the returned properties and their sample values
- Construct the filter using the discovered property key and a known value
posthog:query-llm-traces-list
{
"dateRange": {"date_from": "-7d"},
"properties": [
{"type": "event", "key": "project_id", "value": "proj_abc123", "operator": "exact"}
]
}
For more complex SQL patterns, read these references:
- Single trace retrieval — fetches a single trace by ID with all events and properties (renders the
TraceQueryHogQL) - Traces list with aggregated metrics — two-phase query: find trace IDs first, then fetch aggregated latency, tokens, costs, and error counts
Parsing large trace results
Trace tool results are JSON. When too large to read inline, Claude Code persists them to a file.
Persisted file format
[{ "type": "text", "text": "{\"results\": [...], \"_posthogUrl\": \"...\"}" }]
Trace JSON structure
results (array for list, object for single trace)
├── id, traceName, createdAt, totalLatency, totalCost
├── inputState, outputState (trace-level state)
└── events[]
├── event ($ai_span | $ai_generation | $ai_embedding | $ai_metric | $ai_feedback)
├── id, createdAt
└── properties
├── $ai_span_name, $ai_latency, $ai_is_error
├── $ai_input_state, $ai_output_state (span tool I/O)
├── $ai_input, $ai_output_choices (generation messages)
├── $ai_model, $ai_provider
└── $ai_input_tokens, $ai_output_tokens, $ai_total_cost_usd
Available scripts
| Script | Purpose | Usage |
|---|---|---|
print_summary.py |
Aggregate list/session totals, trace metadata, tool calls, errors, and final LLM output | python3 scripts/print_summary.py FILE |
print_timeline.py |
Chronological event timeline with I/O summaries | python3 scripts/print_timeline.py FILE |
extract_span.py |
Full input/output of a specific span by name | SPAN="name" python3 scripts/extract_span.py FILE |
extract_conversation.py |
LLM messages with thinking blocks and tool calls | python3 scripts/extract_conversation.py FILE |
search_traces.py |
Find a keyword across all event properties | SEARCH="keyword" python3 scripts/search_traces.py FILE |
show_structure.py |
Show JSON keys and types without values | cat blob.json \| python3 scripts/show_structure.py |
Tips
- Always set
dateRange— queries without a time range are slow. Use narrow windows (-30m,-1h) for broad listing queries; wider windows (-7d,-30d) are fine for narrow queries filtered by trace ID or specific property values - Always include the
_posthogUrlin your response so the user can click through $ai_input_state/$ai_output_stateon spans contain tool call inputs and outputs$ai_input/$ai_output_choiceson generations contain the full LLM conversation — can be megabytes; when the result is persisted to a file, use the parsing scripts- In raw SQL, heavy content (
$ai_input/$ai_output/$ai_output_choices/$ai_input_state/$ai_output_state/$ai_tools) lives only on theposthog.ai_eventstable, notevents.properties— see the event reference for the column mapping and trace-id-anchored query patterns - Use
filterTestAccounts: trueto exclude internal/test traffic when searching $ai_traceevents are NOT in theeventsarray — their data is surfaced via trace-levelinputState,outputState, andtraceName
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供了完整的 LLM 追踪调试工作流,覆盖从 URL 解析到结果分析的全链路场景
- 针对高频刚需痛点(调试追踪、检查工具使用、验证上下文、分析成本)提供了实用解决方案
亮点
- 触发场景描述详尽且边界清晰,覆盖多种用户意图变体
- 明确指出了应使用此工具的具体条件和上下文
亮点
- 文档结构清晰,Phase 划分合理,步骤说明详细
- 包含完整的端到端示例和 frontmatter 信息
待提升项
-
缺少 When to Use 显式章节 原报告严重程度:轻微
文档中未设置独立的 'When to Use' 章节,但触发场景已在 description 和正文中充分覆盖
改进建议:建议在正文开头添加显式的 'When to Use' 章节以提升可读性
亮点
- 工具来源明确,参数使用规范,覆盖了主要异常场景
- 提供了大结果文件的解析脚本,增强了执行可靠性
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- app.posthog.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。