Skip to content

: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.

feat(tracing): expose the latency heatmap endpoint as an mcp tool (#72533)

Jon McCallum00dde98b36d9
diff --git a/products/tracing/backend/presentation/views.py b/products/tracing/backend/presentation/views.py
index 06235c86ff78..e1984c13ce00 100644
--- a/products/tracing/backend/presentation/views.py
+++ b/products/tracing/backend/presentation/views.py
@@ -244,7 +244,10 @@ class _TracingLatencyHeatmapCellSerializer(serializers.Serializer):
),
)
count = serializers.IntegerField(
- help_text="Spans (or traces when rootSpans is true) in this cell. 0 only on sentinel rows.",
+ help_text=(
+ "Traces in this cell, bucketed by root-span duration (the default, rootSpans=true). "
+ "When rootSpans is false, every matching span is counted instead. 0 only on sentinel rows."
+ ),
)
diff --git a/products/tracing/frontend/generated/api.schemas.ts b/products/tracing/frontend/generated/api.schemas.ts
index 3eb7d1cd2858..f1dc30299035 100644
--- a/products/tracing/frontend/generated/api.schemas.ts
+++ b/products/tracing/frontend/generated/api.schemas.ts
@@ -323,7 +323,7 @@ export interface _TracingLatencyHeatmapCellApi {
time: string
/** Lower edge of the 1-2-5 series duration bucket in nanoseconds (1ms, 2ms, 5ms, 10ms, ...). 0 on the sentinel row that enumerates a time bucket with no matching spans. */
bucket_ns: number
- /** Spans (or traces when rootSpans is true) in this cell. 0 only on sentinel rows. */
+ /** Traces in this cell, bucketed by root-span duration (the default, rootSpans=true). When rootSpans is false, every matching span is counted instead. 0 only on sentinel rows. */
count: number
}
diff --git a/products/tracing/mcp/prompts/apm-spans-latency-heatmap.md b/products/tracing/mcp/prompts/apm-spans-latency-heatmap.md
new file mode 100644
index 000000000000..d3794151edfb
--- /dev/null
+++ b/products/tracing/mcp/prompts/apm-spans-latency-heatmap.md
@@ -0,0 +1,92 @@
+Latency over time — trace counts per (time bucket, duration bucket) cell, combining `apm-spans-sparkline` and `apm-spans-duration-histogram` into one call: "when did latency change, and how".
+
+Returns one row per non-empty `(time bucket, duration bucket)` cell:
+
+- `time` — ISO 8601 bucket start (UTC)
+- `bucket_ns` — duration bucket floor in nanoseconds, on the 1-2-5 series (1ms, 2ms, 5ms, 10ms, 20ms, ...)
+- `count` — traces whose ROOT span duration falls in that cell (or spans, when `rootSpans` is false)
+
+Time buckets are sized adaptively to the window (roughly 50 buckets regardless of range, e.g. `-1h` → ~minute buckets, `-7d` → ~4-hour buckets). A time bucket with no matching traces returns a single sentinel row `{time, bucket_ns: 0, count: 0}`, so the full time axis can be read off the response — ignore sentinel rows when reading densities.
+
+Use to answer:
+
+- "When did this service get slow?" — the slow band's first non-empty `time` is the onset.
+- "Is the latency regression a shift (whole distribution moved) or a new mode (a second band appeared)?"
+- "Did the deploy at 14:00 change the latency profile, not just the p95?"
+- "Is the slow tail constant background or bursty?"
+
+For a single distribution with per-service breakdown, use `apm-spans-duration-histogram`; for counts over time, `apm-spans-sparkline`; for per-operation percentiles, `apm-spans-aggregate`.
+
+All parameters must be nested inside a `query` object.
+
+# Reading the grid
+
+Group rows by `bucket_ns` and read each duration bucket as a horizontal band over time:
+
+- A band that exists in every time bucket at similar counts = steady-state population.
+- A band that starts at a specific `time` = something changed then (deploy, dependency, cache).
+- The whole distribution stepping up one or two buckets at once = a uniform slowdown.
+
+# Parameters
+
+All parameters go inside `query`.
+
+## query.dateRange
+
+Date range for the grid. Defaults to the last hour.
+
+- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.
+- `date_to`: End of the range. Same format. Omit or null for "now".
+
+## query.serviceNames
+
+List of service names to restrict the grid to. Use `apm-services-list` to discover services.
+
+## query.statusCodes
+
+Filter by OTel span status codes (list of integers: `0` Unset, `1` OK, `2` Error) — **not** HTTP status codes. Use `[2]` to select error spans.
+
+## query.rootSpans
+
+When true (default), cells count **traces by their root span's duration** — the request the user experienced, lining up with `apm-spans-duration-histogram`. Set false to count every matching span instead; combine with a `name` filter for one operation's latency over time.
+
+## query.filterGroup
+
+Property filters applied to the counted spans. Same filter shape and operators as `query-apm-spans`:
+
+- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code, is_root_span)
+- `span_attribute` — span-level attributes
+- `span_resource_attribute` — resource-level attributes
+
+# Examples
+
+## When did api-gateway get slow, over the last day?
+
+```json
+{
+ "query": {
+ "serviceNames": ["api-gateway"],
+ "dateRange": { "date_from": "-1d" }
+ }
+}
+```
+
+## One operation's latency over time (span-level, not per trace)
+
+```json
+{
+ "query": {
+ "rootSpans": false,
+ "filterGroup": [{ "key": "name", "operator": "exact", "type": "span", "value": ["SELECT orders"] }],
+ "dateRange": { "date_from": "-6h" }
+ }
+}
+```
+
+# Reminders
+
+- `bucket_ns` is nanoseconds: 1ms = 1,000,000; 1s = 1,000,000,000. Buckets follow the 1-2-5 series; a 3.5ms trace lands in the 2ms bucket (bucket floor).
+- `{bucket_ns: 0, count: 0}` rows are the sentinel time-axis filler described above — skip them when reading densities.
+- Default counts are **traces** (one per root span); they line up with `apm-spans-duration-histogram`, not with `apm-spans-count`.
+- Cells carry no service breakdown — narrow with `serviceNames` instead.
+- After spotting when the slow band appeared, pull the actual traces with `query-apm-spans` filtered to that time window plus a `duration` filter (nanoseconds), `orderBy: "duration"`.
diff --git a/products/tracing/mcp/tools.yaml b/products/tracing/mcp/tools.yaml
index 065ff45b2a13..fe701d8eb16d 100644
--- a/products/tracing/mcp/tools.yaml
+++ b/products/tracing/mcp/tools.yaml
@@ -135,6 +135,21 @@ tools:
response:
include:
- results
+ apm-spans-latency-heatmap:
+ operation: tracing_spans_latency_heatmap_create
+ enabled: true
+ scopes:
+ - tracing:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Latency over time (heatmap)
+ description_file: ./prompts/apm-spans-latency-heatmap.md
+ feature_flag: tracing
+ response:
+ include:
+ - results
apm-spans-sparkline:
operation: tracing_spans_sparkline_create
enabled: true
@@ -209,9 +224,6 @@ tools:
tracing-spans-has-spans-retrieve:
operation: tracing_spans_has_spans_retrieve
enabled: false
- tracing-spans-latency-heatmap-create:
- operation: tracing_spans_latency_heatmap_create
- enabled: false
tracing-spans-symbol-stats-create:
operation: tracing_spans_symbol_stats_create
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 3f39e681d378..e73faadc0479 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -1243,6 +1243,21 @@
},
"feature_flag": "tracing"
},
+ "apm-spans-latency-heatmap": {
+ "description": "Latency over time — trace counts per (time bucket, duration bucket) cell, combining `apm-spans-sparkline` and `apm-spans-duration-histogram` into one call: \"when did latency change, and how\".\n\nReturns one row per non-empty `(time bucket, duration bucket)` cell:\n\n- `time` — ISO 8601 bucket start (UTC)\n- `bucket_ns` — duration bucket floor in nanoseconds, on the 1-2-5 series (1ms, 2ms, 5ms, 10ms, 20ms, ...)\n- `count` — traces whose ROOT span duration falls in that cell (or spans, when `rootSpans` is false)\n\nTime buckets are sized adaptively to the window (roughly 50 buckets regardless of range, e.g. `-1h` → ~minute buckets, `-7d` → ~4-hour buckets). A time bucket with no matching traces returns a single sentinel row `{time, bucket_ns: 0, count: 0}`, so the full time axis can be read off the response — ignore sentinel rows when reading densities.\n\nUse to answer:\n\n- \"When did this service get slow?\" — the slow band's first non-empty `time` is the onset.\n- \"Is the latency regression a shift (whole distribution moved) or a new mode (a second band appeared)?\"\n- \"Did the deploy at 14:00 change the latency profile, not just the p95?\"\n- \"Is the slow tail constant background or bursty?\"\n\nFor a single distribution with per-service breakdown, use `apm-spans-duration-histogram`; for counts over time, `apm-spans-sparkline`; for per-operation percentiles, `apm-spans-aggregate`.\n\nAll parameters must be nested inside a `query` object.\n\n# Reading the grid\n\nGroup rows by `bucket_ns` and read each duration bucket as a horizontal band over time:\n\n- A band that exists in every time bucket at similar counts = steady-state population.\n- A band that starts at a specific `time` = something changed then (deploy, dependency, cache).\n- The whole distribution stepping up one or two buckets at once = a uniform slowdown.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the grid. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.serviceNames\n\nList of service names to restrict the grid to. Use `apm-services-list` to discover services.\n\n## query.statusCodes\n\nFilter by OTel span status codes (list of integers: `0` Unset, `1` OK, `2` Error) — **not** HTTP status codes. Use `[2]` to select error spans.\n\n## query.rootSpans\n\nWhen true (default), cells count **traces by their root span's duration** — the request the user experienced, lining up with `apm-spans-duration-histogram`. Set false to count every matching span instead; combine with a `name` filter for one operation's latency over time.\n\n## query.filterGroup\n\nProperty filters applied to the counted spans. Same filter shape and operators as `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code, is_root_span)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\n# Examples\n\n## When did api-gateway get slow, over the last day?\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## One operation's latency over time (span-level, not per trace)\n\n```json\n{\n \"query\": {\n \"rootSpans\": false,\n \"filterGroup\": [{ \"key\": \"name\", \"operator\": \"exact\", \"type\": \"span\", \"value\": [\"SELECT orders\"] }],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n# Reminders\n\n- `bucket_ns` is nanoseconds: 1ms = 1,000,000; 1s = 1,000,000,000. Buckets follow the 1-2-5 series; a 3.5ms trace lands in the 2ms bucket (bucket floor).\n- `{bucket_ns: 0, count: 0}` rows are the sentinel time-axis filler described above — skip them when reading densities.\n- Default counts are **traces** (one per root span); they line up with `apm-spans-duration-histogram`, not with `apm-spans-count`.\n- Cells carry no service breakdown — narrow with `serviceNames` instead.\n- After spotting when the slow band appeared, pull the actual traces with `query-apm-spans` filtered to that time window plus a `duration` filter (nanoseconds), `orderBy: \"duration\"`.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Latency over time (heatmap)",
+ "title": "Latency over time (heatmap)",
+ "required_scopes": ["tracing:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
"apm-spans-sparkline": {
"description": "Span counts over time — a zero-filled time series for trend and spike analysis.\n\nReturns one row per `(time bucket, service)` pair:\n\n- `time` — ISO 8601 bucket start (UTC)\n- `service` — service name (top 10 services per bucket)\n- `count` — spans in that bucket matching the filters\n\nBuckets are sized adaptively to the window (roughly 50 buckets regardless of range, e.g. `-1h` → ~minute buckets, `-7d` → ~hour buckets). Quiet stretches return zero-count rows, so the series is continuous — read spike timing straight off the `time` values.\n\nUse to answer:\n\n- \"When did the error rate spike?\" (see the error-trend workflow below)\n- \"Is traffic to service X growing, flat, or bursty?\"\n- \"Did span volume change after the deploy at 14:00?\"\n- \"Which time window should I zoom into before pulling raw spans?\"\n\nFor a single aggregate number per operation, use `apm-spans-aggregate` instead. For latency distribution, use `apm-spans-duration-histogram`.\n\nAll parameters must be nested inside a `query` object.\n\n# Error-trend workflow\n\nTwo calls, then divide per bucket:\n\n1. `apm-spans-sparkline` with your filters → total counts per bucket.\n2. The same call with `statusCodes: [2]` added → error counts per bucket.\n\nError rate per bucket = errors / total. The bucket where the ratio jumps is when the spike started.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the series. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.serviceNames\n\nList of service names to restrict the series to. Use `apm-services-list` to discover services.\n\n## query.statusCodes\n\nFilter by OTel span status codes (list of integers: `0` Unset, `1` OK, `2` Error) — **not** HTTP status codes. Use `[2]` to select error spans.\n\n## query.filterGroup\n\nProperty filters applied to the counted spans. Same filter shape and operators as `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code, is_root_span)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\n# Examples\n\n## Span volume per service over the last 6 hours\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Error spans only, one service, last day\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"statusCodes\": [2],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Request (root span) volume trend\n\n```json\n{\n \"query\": {\n \"filterGroup\": [{ \"key\": \"is_root_span\", \"operator\": \"exact\", \"type\": \"span\", \"value\": true }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n# Reminders\n\n- Counts are **spans**, not traces — filter `is_root_span = true` to count requests/traces.\n- Zero-count rows are bucket filler; read non-zero rows for activity and zero rows for gaps.\n- Only the top 10 services per bucket are returned — narrow with `serviceNames` when a busy project drowns out the service you care about.\n- Use `apm-services-list`, `apm-attributes-list`, `apm-attribute-values-list` to discover values before filtering.",
"category": "Tracing",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 44ac5988dd5e..4c999e65351d 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -1272,6 +1272,21 @@
},
"feature_flag": "tracing"
},
+ "apm-spans-latency-heatmap": {
+ "description": "Latency over time — trace counts per (time bucket, duration bucket) cell, combining `apm-spans-sparkline` and `apm-spans-duration-histogram` into one call: \"when did latency change, and how\".\n\nReturns one row per non-empty `(time bucket, duration bucket)` cell:\n\n- `time` — ISO 8601 bucket start (UTC)\n- `bucket_ns` — duration bucket floor in nanoseconds, on the 1-2-5 series (1ms, 2ms, 5ms, 10ms, 20ms, ...)\n- `count` — traces whose ROOT span duration falls in that cell (or spans, when `rootSpans` is false)\n\nTime buckets are sized adaptively to the window (roughly 50 buckets regardless of range, e.g. `-1h` → ~minute buckets, `-7d` → ~4-hour buckets). A time bucket with no matching traces returns a single sentinel row `{time, bucket_ns: 0, count: 0}`, so the full time axis can be read off the response — ignore sentinel rows when reading densities.\n\nUse to answer:\n\n- \"When did this service get slow?\" — the slow band's first non-empty `time` is the onset.\n- \"Is the latency regression a shift (whole distribution moved) or a new mode (a second band appeared)?\"\n- \"Did the deploy at 14:00 change the latency profile, not just the p95?\"\n- \"Is the slow tail constant background or bursty?\"\n\nFor a single distribution with per-service breakdown, use `apm-spans-duration-histogram`; for counts over time, `apm-spans-sparkline`; for per-operation percentiles, `apm-spans-aggregate`.\n\nAll parameters must be nested inside a `query` object.\n\n# Reading the grid\n\nGroup rows by `bucket_ns` and read each duration bucket as a horizontal band over time:\n\n- A band that exists in every time bucket at similar counts = steady-state population.\n- A band that starts at a specific `time` = something changed then (deploy, dependency, cache).\n- The whole distribution stepping up one or two buckets at once = a uniform slowdown.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the grid. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.serviceNames\n\nList of service names to restrict the grid to. Use `apm-services-list` to discover services.\n\n## query.statusCodes\n\nFilter by OTel span status codes (list of integers: `0` Unset, `1` OK, `2` Error) — **not** HTTP status codes. Use `[2]` to select error spans.\n\n## query.rootSpans\n\nWhen true (default), cells count **traces by their root span's duration** — the request the user experienced, lining up with `apm-spans-duration-histogram`. Set false to count every matching span instead; combine with a `name` filter for one operation's latency over time.\n\n## query.filterGroup\n\nProperty filters applied to the counted spans. Same filter shape and operators as `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code, is_root_span)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\n# Examples\n\n## When did api-gateway get slow, over the last day?\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## One operation's latency over time (span-level, not per trace)\n\n```json\n{\n \"query\": {\n \"rootSpans\": false,\n \"filterGroup\": [{ \"key\": \"name\", \"operator\": \"exact\", \"type\": \"span\", \"value\": [\"SELECT orders\"] }],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n# Reminders\n\n- `bucket_ns` is nanoseconds: 1ms = 1,000,000; 1s = 1,000,000,000. Buckets follow the 1-2-5 series; a 3.5ms trace lands in the 2ms bucket (bucket floor).\n- `{bucket_ns: 0, count: 0}` rows are the sentinel time-axis filler described above — skip them when reading densities.\n- Default counts are **traces** (one per root span); they line up with `apm-spans-duration-histogram`, not with `apm-spans-count`.\n- Cells carry no service breakdown — narrow with `serviceNames` instead.\n- After spotting when the slow band appeared, pull the actual traces with `query-apm-spans` filtered to that time window plus a `duration` filter (nanoseconds), `orderBy: \"duration\"`.",
+ "category": "Tracing",
+ "feature": "tracing",
+ "summary": "Latency over time (heatmap)",
+ "title": "Latency over time (heatmap)",
+ "required_scopes": ["tracing:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ },
+ "feature_flag": "tracing"
+ },
"apm-spans-sparkline": {
"description": "Span counts over time — a zero-filled time series for trend and spike analysis.\n\nReturns one row per `(time bucket, service)` pair:\n\n- `time` — ISO 8601 bucket start (UTC)\n- `service` — service name (top 10 services per bucket)\n- `count` — spans in that bucket matching the filters\n\nBuckets are sized adaptively to the window (roughly 50 buckets regardless of range, e.g. `-1h` → ~minute buckets, `-7d` → ~hour buckets). Quiet stretches return zero-count rows, so the series is continuous — read spike timing straight off the `time` values.\n\nUse to answer:\n\n- \"When did the error rate spike?\" (see the error-trend workflow below)\n- \"Is traffic to service X growing, flat, or bursty?\"\n- \"Did span volume change after the deploy at 14:00?\"\n- \"Which time window should I zoom into before pulling raw spans?\"\n\nFor a single aggregate number per operation, use `apm-spans-aggregate` instead. For latency distribution, use `apm-spans-duration-histogram`.\n\nAll parameters must be nested inside a `query` object.\n\n# Error-trend workflow\n\nTwo calls, then divide per bucket:\n\n1. `apm-spans-sparkline` with your filters → total counts per bucket.\n2. The same call with `statusCodes: [2]` added → error counts per bucket.\n\nError rate per bucket = errors / total. The bucket where the ratio jumps is when the spike started.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.dateRange\n\nDate range for the series. Defaults to the last hour.\n\n- `date_from`: Start of the range. ISO 8601 or relative: `-1h`, `-6h`, `-1d`, `-7d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.serviceNames\n\nList of service names to restrict the series to. Use `apm-services-list` to discover services.\n\n## query.statusCodes\n\nFilter by OTel span status codes (list of integers: `0` Unset, `1` OK, `2` Error) — **not** HTTP status codes. Use `[2]` to select error spans.\n\n## query.filterGroup\n\nProperty filters applied to the counted spans. Same filter shape and operators as `query-apm-spans`:\n\n- `span` — built-in span fields (trace_id, span_id, duration, name, kind, status_code, is_root_span)\n- `span_attribute` — span-level attributes\n- `span_resource_attribute` — resource-level attributes\n\n# Examples\n\n## Span volume per service over the last 6 hours\n\n```json\n{\n \"query\": {\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Error spans only, one service, last day\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"statusCodes\": [2],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Request (root span) volume trend\n\n```json\n{\n \"query\": {\n \"filterGroup\": [{ \"key\": \"is_root_span\", \"operator\": \"exact\", \"type\": \"span\", \"value\": true }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n# Reminders\n\n- Counts are **spans**, not traces — filter `is_root_span = true` to count requests/traces.\n- Zero-count rows are bucket filler; read non-zero rows for activity and zero rows for gaps.\n- Only the top 10 services per bucket are returned — narrow with `serviceNames` when a busy project drowns out the service you care about.\n- Use `apm-services-list`, `apm-attributes-list`, `apm-attribute-values-list` to discover values before filtering.",
"category": "Tracing",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 7c085786fc7d..2d9f7963c8b1 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -66433,7 +66433,7 @@ export namespace Schemas {
time: string;
/** Lower edge of the 1-2-5 series duration bucket in nanoseconds (1ms, 2ms, 5ms, 10ms, ...). 0 on the sentinel row that enumerates a time bucket with no matching spans. */
bucket_ns: number;
- /** Spans (or traces when rootSpans is true) in this cell. 0 only on sentinel rows. */
+ /** Traces in this cell, bucketed by root-span duration (the default, rootSpans=true). When rootSpans is false, every matching span is counted instead. 0 only on sentinel rows. */
count: number;
}
diff --git a/services/mcp/src/generated/tracing/api.ts b/services/mcp/src/generated/tracing/api.ts
index 51013fddfb19..cb257cd56a1d 100644
--- a/services/mcp/src/generated/tracing/api.ts
+++ b/services/mcp/src/generated/tracing/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 11 enabled ops
+ * PostHog API - MCP 12 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -471,6 +471,97 @@ export const TracingSpansDurationHistogramCreateBody = /* @__PURE__ */ zod.objec
.describe('The duration-histogram query to execute.'),
})
+export const TracingSpansLatencyHeatmapCreateParams = /* @__PURE__ */ zod.object({
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/."
+ ),
+})
+
+export const tracingSpansLatencyHeatmapCreateBodyQueryOneFilterGroupDefault = []
+export const tracingSpansLatencyHeatmapCreateBodyQueryOneRootSpansDefault = true
+
+export const TracingSpansLatencyHeatmapCreateBody = /* @__PURE__ */ zod.object({
+ query: zod
+ .object({
+ dateRange: zod
+ .object({
+ date_from: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Start of the date range. Accepts ISO 8601 timestamps or relative formats: -1h, -6h, -1d, -7d, etc.'
+ ),
+ date_to: zod
+ .string()
+ .nullish()
+ .describe('End of the date range. Same format as date_from. Omit or null for "now".'),
+ })
+ .optional()
+ .describe('Date range for the query. Defaults to last hour.'),
+ serviceNames: zod.array(zod.string()).optional().describe('Filter by service names.'),
+ statusCodes: zod
+ .array(zod.number())
+ .optional()
+ .describe(
+ 'Filter by OTel span status codes (0 Unset, 1 OK, 2 Error) — not HTTP status codes. Use [2] to select error spans.'
+ ),
+ filterGroup: zod
+ .array(
+ zod.object({
+ key: zod
+ .string()
+ .describe(
+ 'Attribute key. For type "span", use built-in fields (trace_id, span_id, duration, name, kind, status_code, is_root_span). For "span_attribute"\/"span_resource_attribute", use the attribute key (e.g. "http.method").'
+ ),
+ type: zod
+ .enum(['span', 'span_attribute', 'span_resource_attribute'])
+ .describe(
+ '* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ )
+ .describe(
+ '"span" filters built-in span fields. "span_attribute" filters span-level attributes. "span_resource_attribute" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute'
+ ),
+ operator: zod
+ .enum([
+ 'exact',
+ 'is_not',
+ 'icontains',
+ 'not_icontains',
+ 'regex',
+ 'not_regex',
+ 'gt',
+ 'lt',
+ 'is_set',
+ 'is_not_set',
+ ])
+ .describe(
+ '* `exact` - exact\n* `is_not` - is_not\n* `icontains` - icontains\n* `not_icontains` - not_icontains\n* `regex` - regex\n* `not_regex` - not_regex\n* `gt` - gt\n* `lt` - lt\n* `is_set` - is_set\n* `is_not_set` - is_not_set'
+ )
+ .describe(
+ 'Comparison operator.\n\n* `exact` - exact\n* `is_not` - is_not\n* `icontains` - icontains\n* `not_icontains` - not_icontains\n* `regex` - regex\n* `not_regex` - not_regex\n* `gt` - gt\n* `lt` - lt\n* `is_set` - is_set\n* `is_not_set` - is_not_set'
+ ),
+ value: zod
+ .unknown()
+ .optional()
+ .describe(
+ 'Value to compare against. String, number, or array of strings. Omit for is_set/is_not_set operators.'
+ ),
+ })
+ )
+ .default(tracingSpansLatencyHeatmapCreateBodyQueryOneFilterGroupDefault)
+ .describe('Property filters for the query.'),
+ rootSpans: zod
+ .boolean()
+ .default(tracingSpansLatencyHeatmapCreateBodyQueryOneRootSpansDefault)
+ .describe(
+ 'When true (default), bucket root-span durations only — a distribution of traces. When false, bucket every matching span — used with a span name filter for operation-scoped distributions.'
+ ),
+ })
+ .describe('The latency-heatmap query to execute.'),
+})
+
export const TracingSpansQueryCreateParams = /* @__PURE__ */ zod.object({
project_id: zod
.string()
diff --git a/services/mcp/src/tools/generated/tracing.ts b/services/mcp/src/tools/generated/tracing.ts
index fcaff2ba6c44..139fcee72025 100644
--- a/services/mcp/src/tools/generated/tracing.ts
+++ b/services/mcp/src/tools/generated/tracing.ts
@@ -8,6 +8,7 @@ import {
TracingSpansAttributesRetrieveQueryParams,
TracingSpansCountCreateBody,
TracingSpansDurationHistogramCreateBody,
+ TracingSpansLatencyHeatmapCreateBody,
TracingSpansQueryCreateBody,
TracingSpansServiceNamesRetrieveQueryParams,
TracingSpansSparklineCreateBody,
@@ -173,6 +174,30 @@ const apmSpansDurationHistogram = (): ToolBase<typeof ApmSpansDurationHistogramS
},
})
+const ApmSpansLatencyHeatmapSchema = TracingSpansLatencyHeatmapCreateBody
+
+const apmSpansLatencyHeatmap = (): ToolBase<
+ typeof ApmSpansLatencyHeatmapSchema,
+ Schemas._TracingLatencyHeatmapResponse
+> => ({
+ name: 'apm-spans-latency-heatmap',
+ schema: ApmSpansLatencyHeatmapSchema,
+ handler: async (context: Context, params: z.infer<typeof ApmSpansLatencyHeatmapSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.query !== undefined) {
+ body['query'] = params.query
+ }
+ const result = await context.api.request<Schemas._TracingLatencyHeatmapResponse>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/tracing/spans/latency-heatmap/`,
+ body,
+ })
+ const filtered = pickResponseFields(result, ['results']) as typeof result
+ return filtered
+ },
+})
+
const ApmSpansSparklineSchema = TracingSpansSparklineCreateBody
const apmSpansSparkline = (): ToolBase<typeof ApmSpansSparklineSchema, unknown> => ({
@@ -275,6 +300,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'apm-spans-aggregate': apmSpansAggregate,
'apm-spans-count': apmSpansCount,
'apm-spans-duration-histogram': apmSpansDurationHistogram,
+ 'apm-spans-latency-heatmap': apmSpansLatencyHeatmap,
'apm-spans-sparkline': apmSpansSparkline,
'apm-spans-tree': apmSpansTree,
'apm-trace-get': apmTraceGet,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/apm-spans-latency-heatmap.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/apm-spans-latency-heatmap.json
new file mode 100644
index 000000000000..835dce3017be
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/apm-spans-latency-heatmap.json
@@ -0,0 +1,99 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "query": {
+ "description": "The latency-heatmap query to execute.",
+ "properties": {
+ "dateRange": {
+ "description": "Date range for the query. Defaults to last hour.",
+ "properties": {
+ "date_from": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Start of the date range. Accepts ISO 8601 timestamps or relative formats: -1h, -6h, -1d, -7d, etc."
+ },
+ "date_to": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "End of the date range. Same format as date_from. Omit or null for \"now\"."
+ }
+ },
+ "type": "object"
+ },
+ "filterGroup": {
+ "default": [],
+ "description": "Property filters for the query.",
+ "items": {
+ "properties": {
+ "key": {
+ "description": "Attribute key. For type \"span\", use built-in fields (trace_id, span_id, duration, name, kind, status_code, is_root_span). For \"span_attribute\"/\"span_resource_attribute\", use the attribute key (e.g. \"http.method\").",
+ "type": "string"
+ },
+ "operator": {
+ "description": "Comparison operator.\n\n* `exact` - exact\n* `is_not` - is_not\n* `icontains` - icontains\n* `not_icontains` - not_icontains\n* `regex` - regex\n* `not_regex` - not_regex\n* `gt` - gt\n* `lt` - lt\n* `is_set` - is_set\n* `is_not_set` - is_not_set",
+ "enum": [
+ "exact",
+ "is_not",
+ "icontains",
+ "not_icontains",
+ "regex",
+ "not_regex",
+ "gt",
+ "lt",
+ "is_set",
+ "is_not_set"
+ ],
+ "type": "string"
+ },
+ "type": {
+ "description": "\"span\" filters built-in span fields. \"span_attribute\" filters span-level attributes. \"span_resource_attribute\" filters resource-level attributes.\n\n* `span` - span\n* `span_attribute` - span_attribute\n* `span_resource_attribute` - span_resource_attribute",
+ "enum": ["span", "span_attribute", "span_resource_attribute"],
+ "type": "string"
+ },
+ "value": {
+ "description": "Value to compare against. String, number, or array of strings. Omit for is_set/is_not_set operators."
+ }
+ },
+ "required": ["key", "type", "operator"],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "rootSpans": {
+ "default": true,
+ "description": "When true (default), bucket root-span durations only — a distribution of traces. When false, bucket every matching span — used with a span name filter for operation-scoped distributions.",
+ "type": "boolean"
+ },
+ "serviceNames": {
+ "description": "Filter by service names.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "statusCodes": {
+ "description": "Filter by OTel span status codes (0 Unset, 1 OK, 2 Error) — not HTTP status codes. Use [2] to select error spans.",
+ "items": {
+ "type": "number"
+ },
+ "type": "array"
+ }
+ },
+ "type": "object"
+ }
+ },
+ "required": ["query"],
+ "type": "object"
+}