Skip to content
betterstack-alchemyUnofficial

Telemetry.DashboardChart

Kind ResourceType id BetterStack.Telemetry.DashboardChartSource src/Telemetry/DashboardChart.tsLive test available A live lifecycle test exists: it runs against the offline mock by default and against the real API under bun run test:live. This records that the test exists, not a dated live run (see Compatibility). Test file: test/Telemetry/DashboardChart.test.ts.

A chart on a Dashboard, backed by one or more queries. The Chart helpers build chartType, queries and settings (and the time-series SQL every chart repeats); spread them into the props next to dashboardId and the chart’s place on the 12-column grid (x, y, w, h). Without x/y the API places the chart at the first free spot, or in the section named by section (create-only).

dashboardId and section replace the chart when changed; everything else updates in place. queries and settings are compared against the previous deploy rather than the live chart (the API fills in query ids, editor blocks and setting defaults), so an edit made in the web app is not reverted until they change here. Removing description or explanation clears it. Alerts on the chart are Alerts with its dashboardId and chartId.

Requests by status, stacked

const Chart = BetterStack.Telemetry.Chart;
const app = yield* BetterStack.Telemetry.Dashboard("app", { name: "Production app" });
yield* BetterStack.Telemetry.DashboardChart("requests", {
dashboardId: app.id,
...Chart.line({
name: "Requests by status",
sql: Chart.timeSeries({ series: Chart.json(["message_json", "status"], "Int32") }),
settings: { stacking: "stack", legend: "shown_below" },
}),
x: 0, y: 0, w: 12, h: 4,
});

Hand-written queries, as the API takes them

yield* BetterStack.Telemetry.DashboardChart("slow", {
dashboardId: app.id,
chartType: "table_chart",
name: "Slowest endpoints",
queries: [
{
queryType: "sql_expression",
sqlQuery:
"SELECT JSONExtract(raw, 'path', 'Nullable(String)') AS path, avg(JSONExtract(raw, 'duration_ms', 'Nullable(Float64)')) AS value FROM {{source}} WHERE dt BETWEEN {{start_time}} AND {{end_time}} GROUP BY path ORDER BY value DESC LIMIT 10",
},
],
});

By its dashboard and id

const existing = BetterStack.Telemetry.DashboardChart.lookup({ dashboardId: "1234", id: "5678" });

By its dashboard and name (fails with AmbiguousLookup when several charts on the dashboard share it)

const latency = BetterStack.Telemetry.DashboardChart.lookup({ dashboardId: "1234", name: "Latency" });

chartType "line_chart" | "bar_chart" | "pie_chart" | "scatter_chart" | "gauge_chart" | "number_chart" | "heatmap_chart" | "table_chart" | "map_chart" | "text_chart" | "t… required

Chart type. Only a line_chart can have more than one query. An update can't change it to a type the chart's existing queries or alerts don't work with. Changing it in an update without queries turns Drag & drop queries into sql_expression queries with the same SQL.

dashboardId string required

queries CreateDashboardChartRequestQueriesItem[] required

The chart's queries: sql_expression, tail_query or static_text (see Chart). Only a line_chart holds more than one. Updating a chart replaces all of them. Compared against the previous deploy, not the live chart (the API fills in ids and editor blocks).

description string | null

Chart description.

explanation string | null

Explanation of what the chart shows. AI SRE and the chart's AI summary use it.

h number

Grid height.

name string

Chart name.

query string

One query for the chart, written in SQL, instead of queries. The query's FROM must name a source, as {{source}} or a source variable of the dashboard. The chart's settings are worked out from the query's columns, and the settings you send override them. For a static_text_chart, query holds the chart's text. A chart created with query goes on the first free spot, so query can't be sent with x or y.

section string

Name of the dashboard section to put the new chart in, at the section's first free spot. The section is created below everything else when the dashboard has none by that name. Can't be combined with x or y.

settings CreateDashboardChartRequestSettings

Display settings for the chart_type, such as unit, axes, legend, stacking and decimal places. An update replaces all of them. Switching x_axis_type to or from category in an update without queries turns the chart's Drag & drop queries into sql_expression queries with the same SQL. Defaults to an empty object.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

w number

Grid width.

x number

The chart's horizontal position on the 12-column grid, from 0 at the left.

y number

The chart's vertical position on the grid, from 0 at the top.

dashboardId string always set

The dashboard the chart is on.

id string always set

The dashboard_chart's id.

chartType "line_chart" | "bar_chart" | "pie_chart" | "scatter_chart" | "gauge_chart" | "number_chart" | "heatmap_chart" | "table_chart" | "map_chart" | "text_chart" | "t…

Chart type. Only a line_chart can have more than one query. An update can't change it to a type the chart's existing queries or alerts don't work with. Changing it in an update without queries turns Drag & drop queries into sql_expression queries with the same SQL.

description string | null

Chart description.

explanation string | null

Explanation of what the chart shows. AI SRE and the chart's AI summary use it.

h number

Grid height.

name string

Chart name.

queries DashboardChartQueriesItem[]

The chart's queries. You can write sql_expression, tail_query and static_text queries. Other types, such as query_builder, pql_expression and PromQL, are returned but can't be written. Updating a chart replaces all of its queries. A chart created or updated with query gets a single query built from it. A chart other than static_text_chart needs at least one query, and only a line_chart can have more than one.

settings DashboardChartSettings

Display settings for the chart_type, such as unit, axes, legend, stacking and decimal places. An update replaces all of them. Switching x_axis_type to or from category in an update without queries turns the chart's Drag & drop queries into sql_expression queries with the same SQL.

teamId string

Team that owns the chart's dashboard, such as t123.

w number

Grid width.

x number

The chart's horizontal position on the 12-column grid, from 0 at the left.

y number

The chart's vertical position on the grid, from 0 at the top.

DashboardChart.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

dashboardId string required

The dashboard it is on.

teamId string

Team that owns the dashboard, such as t123. Defaults to the credentials' team.