Homeโ€บ๐Ÿ“Š Data & UIโ€บModule 41 min read ยท 5/15

Querying the Grail

Hands-on2 exercises

The useDql Hook

One hook, one query, live data from Grail:

import { useDql } from "@dynatrace-sdk/react-hooks";

const { data, error, isLoading } = useDql({
  query: `fetch dt.entity.host
    | fields entity.name, cpuCores, osType
    | sort entity.name asc
    | limit 20`
});

Two DQL Commands

fetch โ†’ entities, logs, events, spans, problems (rows of data) timeseries โ†’ metrics over time (charts) smartscapeNodes โ†’ topology queries (entities + relationships)
// Entities
`fetch dt.entity.host | fields entity.name, cpuCores`

// Metrics
`timeseries avg(dt.host.cpu.usage), by:{dt.entity.host}, from:-2h`

// Logs
`fetch logs | filter contains(content, "error") | limit 50`

// Spans (distributed traces)
`fetch spans | filter request.is_root_span == true
 | summarize count(), by:{dt.service.name}`

// Problems
`fetch dt.davis.problems, from:now()-24h
 | filter not(dt.davis.is_duplicate) and event.status == "ACTIVE"
 | fields display_id, event.name, event.category`

// Metric discovery
`fetch metric.series, from:now()-1h
 | filter contains(metric.key, "cpu")
 | summarize count(), by:{metric.key}`

โš ๏ธ Common DQL pitfalls: loglevel not log.level, by: {field1, field2} needs curly braces, sort `count()` desc needs backticks, filter in(field, "a", "b") not field in ["a","b"].

๐Ÿง  Quick Check

Which DQL command do you use to query metric time series data?

Handling States

if (isLoading) return <ProgressCircle />;
if (error) return <Text>Error: {error.message}</Text>;
// data.records is an array of rows

โš ๏ธ Always handle loading and error states. DQL queries can take 1-5 seconds.

Data Shape

DQL returns data.records (array of objects) and data.types (column metadata). Strato components like DataTable and TimeseriesChart consume this directly.

๐Ÿ’ก Use convertToColumns(data) for DataTable and convertToTimeseries(data) for TimeseriesChart โ€” they handle the conversion automatically.

๐Ÿง  Quick CheckQuestion 2

What React hook fetches DQL data in a Dynatrace App?

What's Next

Module 5 โ€” The Strato component library: DataTable, buttons, layouts.