Getting Started with the Wildcard Widget

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

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.

  1. Navigate to an existing dashboard with a useful widget (Top List of database queries).
  2. Use the widget menu or use the keyboard shortcut (Ctrl/CMD + C) to copy the widget.
  3. In a new dashboard, add a Wildcard widget.
  4. In the editor, clear the default query ().
  5. 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:

  1. Expand the Data Preview to identify the fields returned from the query.
  2. 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:

  1. Click the Define Visual tab.
  2. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux) to open the Command Palette.
  3. 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.
  1. 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"
          }
        ]
      }
    }
    
  2. Click Save Edits.
  3. At the top of your query editor, click the Define Visual tab.
  4. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux) to open the Command Palette.
  5. Select Auto-select chart. The graph should automatically change from a bar chart to a scatterplot.

Step 4: Add a context menu

To add interactivity to your graph, enable context menu support.

  1. 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"
     }
      ]
    }
  2. Run and save the widget.
  3. 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