Getting Started with the Wildcard Widget
Overview
The Wildcard widget is a powerful and flexible visualization tool in Datadog that lets you build custom visual representations using the Vega-Lite grammar.
Tutorial Objectives
By the end of this tutorial, you will be able to:
- Use Vega-Lite concepts to define visualizations in Wildcard widgets.
- Import a query from an existing widget.
Prerequisites
- A Datadog account with access to Notebooks or Dashboards.
- You have telemetry such as APM trace data or request duration metrics.
- You are familiar with basic Datadog widgets and dashboards and can add a widget and edit it.
Step 1: Import an existing query
Rather than starting from scratch, import a request from an existing widget. Copy the query from a widget you’re interested in exploring further (such as a Top List). To get started, you can use widgets from your prebuilt dashboards.
- Navigate to an existing dashboard with a useful widget (Top List of database queries).
- Use the widget menu or use the keyboard shortcut (Ctrl/CMD + C) to copy the widget.
- In a new dashboard, add a Wildcard widget.
- In the editor, clear the default query (
). - Paste the copied request with Ctrl/Cmd + V. The query and associated fields carry over automatically.
Step 2: Refine the query
In the query editor:
- Expand the Data Preview to identify the fields returned from the query.
- Next to your query, click As to add an alias to your query. This adds clarity, for example, rename
p50:trace.http.request{*} by {service}
→ p50
.
Step 3: Auto-generate a visualization
At the top of the query editor:
- Click the Define Visual tab.
- Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux) to open the Command Palette.
- Select Auto-select chart.
Datadog automatically creates a visualization based on your query.
Tip: Use the Command Palette (Cmd + Shift + P) to auto-select a chart type based on your query, add or edit encodings, or rotate axes/switch chart types.
- In a new Wildcard widget, click the JSON tab of the query editor and paste the following query:
{
"response_format": "scalar",
"queries": [
{
"query": "avg:system.cpu.user{*} by {env}",
"data_source": "metrics",
"name": "query1",
"aggregator": "last"
},
{
"query": "max:system.cpu.user{*} by {env}",
"data_source": "metrics",
"name": "query2",
"aggregator": "last"
}
],
"formulas": [
{ "formula": "query1" },
{ "formula": "query2" }
],
"sort": {
"count": 15,
"order_by": [
{
"type": "formula",
"index": 0,
"order": "desc"
}
]
}
}
- Click Save Edits.
- At the top of your query editor, click the Define Visual tab.
- Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux) to open the Command Palette.
- Select Auto-select chart. The graph should automatically change from a bar chart to a scatterplot.
To add interactivity to your graph, enable context menu support.
- In the visual JSON editor, copy and paste the following example bar chart widget to see how to add a context menu. This example includes a Tooltip and Context Menu configurations.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Bar chart showing CPU usage by environment with Datadog context menu support",
"data": {
"name": "table1"
},
"mark": "bar",
"encoding": {
"x": {
"field": "env",
"type": "nominal",
"sort": "-y",
"title": "Environment"
},
"y": {
"field": "query1",
"type": "quantitative",
"title": "CPU Usage (%)"
},
"tooltip": [
{
"field": "env",
"type": "nominal"
},
{
"field": "query1",
"type": "quantitative",
"title": "CPU Usage (%)"
},
{
"field": "timestamp",
"type": "temporal",
"title": "Timestamp"
}
]
},
"params": [
{
"name": "datadogPointSelection",
"select": "point"
}
]
}
- Run and save the widget.
- On your dashboard, find the widget you just created and click any data point in graph to bring up a context menu.
For more information, see Using Vega-Lite with Wildcard Widgets in Datadog.
Next Steps
Wildcard widgets support a wide range of customizations, including:
For more inspiration, see Datadog Wildcard widget examples and Vega-Lite Examples.
Further reading
Additional helpful documentation, links, and articles: