:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tracing): align apm skill and tools on the _posthogUrl contract (#67602)
posthog[bot]c2dbdaaad4ec
diff --git a/products/tracing/mcp/tools.yaml b/products/tracing/mcp/tools.yamlindex 9fd3fb359099..36469cdfeaa6 100644--- a/products/tracing/mcp/tools.yaml+++ b/products/tracing/mcp/tools.yaml@@ -173,6 +173,7 @@ tools:readOnly: truedestructive: falseidempotent: true+ enrich_url: ?trace={params.trace_id}title: Retrieve trace spansdescription: >Fetch all spans for a specific trace by its hex trace ID. Returns the full span tree for the trace includingdiff --git a/products/tracing/skills/exploring-apm-traces/SKILL.md b/products/tracing/skills/exploring-apm-traces/SKILL.mdindex b430b4a69df3..ad27d78acb2d 100644--- a/products/tracing/skills/exploring-apm-traces/SKILL.md+++ b/products/tracing/skills/exploring-apm-traces/SKILL.md@@ -43,13 +43,13 @@ posthog:apm-trace-get}```-The response is `{ results: [span, span, …] }` — a flat list of every span in the trace.+The response is `{ results: [span, span, …], _posthogUrl: "…" }` — a flat list of every span in the trace.The list can be very large for fan-out request flows; when it exceeds the inline limit, Claude Code auto-persists it to a file.From the result you get:- Every span with `name`, `service_name`, `kind`, `status_code`, `parent_span_id`, `duration_nano`, `is_root_span`-- The `_posthogUrl` — **always include this in your response** so the user can click through to the UI+- The `_posthogUrl` — a deep link to this trace in the tracing UI; **always include this in your response** so the user can click through### Step 2 — Parse large results with scripts@@ -148,9 +148,11 @@ Each span carries an `attributes` map (span-level OTel attributes like `http.met## Constructing UI links-`apm-trace-get` and `query-apm-spans` return `_posthogUrl` — **always surface this to the user** so they can verify in the PostHog UI.+`apm-trace-get` returns a `_posthogUrl` deep link that opens the trace in the tracing UI — **always surface this to the user** so they can verify in the PostHog UI.-When presenting findings, include the relevant PostHog URL.+`query-apm-spans` does not return `_posthogUrl`.+To link a trace found via the query tool, feed its `trace_id` to `apm-trace-get` and surface the `_posthogUrl` from that response.+Never hand-construct PostHog URLs.## Finding traces@@ -237,7 +239,7 @@ results (array of span dicts)## Tips- Always set `dateRange` on `query-apm-spans` — queries without a time range are slow. Default is `-1h`; widen only when needed.-- Always include the `_posthogUrl` in your response so the user can click through.+- Always include the `_posthogUrl` from `apm-trace-get` in your response so the user can click through to the trace.- Span-level attributes **are** in the `apm-trace-get` / `query-apm-spans` payload (each span's `attributes` map). Resource attributes are not — use `apm-attributes-list` (type `resource`) and `apm-attribute-values-list` for those.- `is_root_span` is the cheap way to find the trace entry — don't string-match `00000000…`.- For aggregates (p95 by operation, slowest children of a span), use `apm-spans-aggregate` for a flat view or `apm-spans-tree` for parent→child edges — don't reach for SQL.diff --git a/services/mcp/scripts/generate-tools.ts b/services/mcp/scripts/generate-tools.tsindex e6c5e11bd033..76f42a19668e 100644--- a/services/mcp/scripts/generate-tools.ts+++ b/services/mcp/scripts/generate-tools.ts@@ -1072,16 +1072,19 @@ function generateToolCode(// Response filtering — pick/omit fields before enrichmentconst responseFilter = buildResponseFilter(config)if (responseFilter.code) {- // Warn if filtering might break enrich_url+ // Warn if filtering might break enrich_url — only for response-sourced fields;+ // '{params.x}' fields are read from the request params, so filtering can't break them.if (config.enrich_url) {- const { field } = parseEnrichUrl(config.enrich_url)- if (config.response?.exclude?.includes(field)) {- console.warn(`Warning: tool "${toolName}" excludes response field "${field}" used by enrich_url`)- }- if (config.response?.include?.length && !config.response?.include.includes(field)) {- console.warn(- `Warning: tool "${toolName}" uses response_include without "${field}" needed by enrich_url`- )+ const { field, source } = parseEnrichUrl(config.enrich_url)+ if (source === 'result') {+ if (config.response?.exclude?.includes(field)) {+ console.warn(`Warning: tool "${toolName}" excludes response field "${field}" used by enrich_url`)+ }+ if (config.response?.include?.length && !config.response?.include.includes(field)) {+ console.warn(+ `Warning: tool "${toolName}" uses response_include without "${field}" needed by enrich_url`+ )+ }}}}diff --git a/services/mcp/src/tools/generated/tracing.ts b/services/mcp/src/tools/generated/tracing.tsindex f6199414d026..f0167395c7e4 100644--- a/services/mcp/src/tools/generated/tracing.ts+++ b/services/mcp/src/tools/generated/tracing.ts@@ -17,7 +17,7 @@ import {TracingSpansValuesRetrieveQueryParams,} from '@/generated/tracing/api'import { withUiApp } from '@/resources/ui-apps'-import { pickResponseFields } from '@/tools/tool-utils'+import { withPostHogUrl, pickResponseFields } from '@/tools/tool-utils'import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'const ApmAttributeBreakdownSchema = TracingSpansAttributeBreakdownCreateBody@@ -238,7 +238,7 @@ const apmTraceGet = (): ToolBase<typeof ApmTraceGetSchema, unknown> =>body,})const filtered = pickResponseFields(result, ['results']) as typeof result- return filtered+ return await withPostHogUrl(context, filtered, `/tracing/?trace=${params.trace_id}`)},})