/betterstack:errors-queryfrom Better Stack
Loads instructions for querying Better Stack exception data with SQL, including exception counts, trends, first/last occurrence, affected users, and raw stack traces.
Ships in Better Stack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Better Stack runs SQL in two places, and both take the query as this skill writes it, with the template variables {{source}}, {{time}}, {{start_time}} and {{end_time}}:
create_dashboard_chart, update_dashboard_chart, create_alert): the dashboard resolves the variables. Chart queries always read the source's metrics collection.query, render_chart): pass source_id, source_type (logs, spans, metrics, web_events or exceptions), start_time and end_time (now-3h, now-1d, or an ISO 8601 datetime) and no table; the tool builds the source's collections for {{source}} and resolves {{time}} to a bucket that suits the range.
First call the help tool for the data type with the source ID (query_help for logs and spans, metrics_query_help for metrics, errors_query_help for errors) for the syntax.
Add a LIMIT. Metrics queries read no S3, so query never sizes or splits them. A query over raw events (exceptions, logs, spans, web_events) differs from the examples in one place: filter time with dt >= {{start_time}} AND dt < {{end_time}}, not {{time}} BETWEEN {{start_time}} AND {{end_time}}, the dashboards' form, which drops the rows of the range's first partial bucket and which query cannot split. Then a template that lists the newest rows (ORDER BY dt DESC LIMIT n, no aggregate, GROUP BY, DISTINCT or subquery), or one that only aggregates (count(), countIf(), sum(), sumIf(), min() or max() beside its GROUP BY columns, no HAVING, DISTINCT or subquery) over at most 300,000,000 rows, needs one query call however wide its range: query reads the range in time windows itself, merges the rows and says how far it read. A query of any other shape whose range is too wide for one call, in query or render_chart, is refused without running, with the time windows that each fit, newest first: run it once per window, each as start_time and end_time, and merge the results: rows concatenate, count() and sum() add up, min() and max() combine, and an average needs sum() and count() per window. quantile() and uniq() don't merge, so narrow the range or the filters until one call holds them.Error tracking has two data planes:
errors and error tools and changed with update_error. Never infer state from SQL.error tool; attach or file one with link_error_issue / create_error_issue (through the team's Better Stack integration, so state changes post comments on the issue), detach with remove_error_issue.Query the source's metrics table (source_type: 'metrics'). The schema is fixed for all Errors sources - query it directly, no source_fields discovery needed:
sum(exceptions_count). exceptions_count is a plain UInt64 per-row column: the number of exceptions in that row. Aggregate it with sum(...), never countMerge(...) (it is not an aggregate-state column). It self-scopes - it is 0 on non-exception rows - so you do not need a _row_type filter to isolate exceptions.countMerge(events_count). events_count totals every row type (spans, logs, web events, exceptions) and double-counts span event vs. duration rows, so it over-counts exceptions. Reach for it only when you deliberately want all row types at once.pattern - plain column holding the error-group hash: the same hash the errors tool returns and the error tool takes. Filter on it to scope any query to one error groupenvironment - plain column (production, staging, ...)uniqMerge(user_uniq) affected users, minMerge(seen_at_min) / maxMerge(seen_at_max) exact first/last occurrence, anyLastMerge(type_last) / anyLastMerge(message_last) / anyLastMerge(call_site_file_last) / anyLastMerge(call_site_function_last) group metadataExceptions over time:
SELECT {{time}} AS time,
sum(exceptions_count) AS "Exceptions"
FROM {{source}}
WHERE {{time}} BETWEEN {{start_time}} AND {{end_time}}
GROUP BY time
ORDER BY time
Per-pattern trend with readable labels ("errors by pattern"): there is no plain message column - group by pattern (the stable identity) and label the series with the message merge column. No hash-to-message mapping needed:
SELECT {{time}} AS time,
anyLastMerge(message_last) AS series,
sum(exceptions_count) AS "Errors"
FROM {{source}}
WHERE {{time}} BETWEEN {{start_time}} AND {{end_time}}
GROUP BY time, pattern
ORDER BY time
series resolves per (time, pattern) group, so each pattern renders as one line labeled by its message. Prefix with the type when helpful: concat(anyLastMerge(type_last), ': ', anyLastMerge(message_last)) AS series.
Group metadata / first & last occurrence of one error pattern - pass a start_time spanning the source's retention (e.g. now-30d), otherwise first_seen is clipped to the query window:
SELECT
anyLastMerge(type_last) AS type,
anyLastMerge(message_last) AS message,
minMerge(seen_at_min) AS first_seen,
maxMerge(seen_at_max) AS last_seen,
sum(exceptions_count) AS occurrences,
uniqMerge(user_uniq) AS users,
groupUniqArray(environment) AS environments
FROM {{source}}
WHERE {{time}} BETWEEN {{start_time}} AND {{end_time}}
AND pattern = '<hash>'
GROUP BY pattern
Add {{time}} AS time, ... GROUP BY time bucketing to trend any of these per error pattern.
query with source_type: 'exceptions'. Raw-JSON dialect like logs: event payload in the raw column read with JSONExtractCaseInsensitive(raw, ...), the error-group hash in the _pattern column (not pattern, which only the metrics table has), dt timestamps. Use a narrow time window around a known occurrence (e.g. maxMerge(seen_at_max) from the metrics query) - full-range scans over raw exceptions are slow.
Build exception trend charts from the metrics collection (queries above). Raw exceptions are for query drill-downs: stack traces, payload inspection, sample events.
metrics-query - merge functions, template variables, and the general metrics dialect; load it when writing metrics queries beyond the canonical ones abovelogs-query - the raw-JSON extraction dialect used by raw exception eventsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
17 skills in this plugin
/chart-alertsGuide for creating and managing Better Stack chart alerts. Load when asked to set up alerting, create alerts on charts, or configure monitoring thresholds./chart-generationComplete reference for chart types, units, and settings on Better Stack dashboards. Load right before creating charts - after the queries are built with the query skills./chart-stylingBetter Stack chart styling and advanced settings reference - series colors and order, number chart coloring thresholds, heatmap color categories, gauge bounds, y-axis tuning, custom units, and the per-key settings table with cross-setting gotchas. Load when configuring how a chart looks beyond defaults, or when unsure which settings key applies to a chart type./collector-queriesProven metrics queries for Better Stack Collector sources (the source tool's Platform "Collector") - per-host node_* metrics, per-container and per-service container_resources_*, requests and errors by destination, TCP health, and the container-level saturation checks that host averages hide. Load after metrics-query when the source platform is Collector, for health checks, resource questions and service dashboards./connect-betterstackConnect the Better Stack MCP server and check that it works. Use when the user installs the Better Stack plugin or asks to set it up, when a Better Stack request comes in but no Better Stack tools (such as `incidents`, `monitors`, `query`, `documentation`) are available, or when a Better Stack tool fails with "unauthorized", 401 or "needs authentication". Tells the user exactly how to connect in the app they are using (ChatGPT, Codex, Cursor, Antigravity, Claude Code, Claude chat and Cowork, Claude Tag in Slack). Once connected, suggests what to set up next from what the account has, such as Claude investigating every new incident or fixing errors on a schedule. Also use when the user asks what Better Stack can do for them./dashboard-builderGuide for building Better Stack dashboards. Load when asked to create a dashboard or add multiple charts in Better Stack.npx claudepluginhub betterstackhq/claude-plugin --plugin betterstack