At three in the morning, nobody wants to write a query from scratch. These DQL query examples cover the questions on-call engineers ask every week: which services are failing, which hosts are saturating, which problems are still open, how long it takes to close them. Most of them rely on DQL summarize, which groups records that share the same values and aggregates them: count, average, percentile per service or per host.
Having these queries ready in a Notebook cuts diagnosis time, and therefore MTTR, and removes some toil: you no longer reinvent the same query at every incident. They also serve as a basis for the SLIs of an SLO.
The goal: leave with 15 testable queries, grouped by use, and know how to adapt them. Scope: DQL queries Grail, so these queries apply to Dynatrace SaaS only. Dynatrace Managed has no Grail; its equivalents go through Data Explorer, metric selectors and API v2, covered at the end of the article.
Prerequisites
- A Dynatrace SaaS environment with Grail, and access to Notebooks or Dashboards.
- Read permissions on the relevant tables (logs, spans, events, metrics); they depend on your IAM policy.
- Data actually ingested: OneAgent, OpenTelemetry Collector or both.
- The language basics: if
fetch,filterandsummarizemean nothing to you, start with DQL fundamentals.
An important warning: field names depend on the source. A log sent by OneAgent and a log received over OTLP do not always have the same attributes. Before copying a query, run fetch logs | limit 5 (or spans) and check that the fields used exist in your environment.
DQL query examples for logs
1. Top error sources over the last hour
fetch logs, from:now()-1h | filter loglevel == "ERROR" | summarize errors = count(), by:{host.name} | sort errors desc | limit 10 A record without host.name is not dropped: summarize puts it in a null group of its own, so check that row before reading the top 10. Replace host.name with k8s.namespace.name or service.name depending on what your logs carry.
2. Error curve over 24 hours
fetch logs, from:now()-24h | filter loglevel == "ERROR" | makeTimeseries errors = count(), interval:15m makeTimeseries turns records into a time series that can be charted directly. A sharp step on the curve often dates a deployment.
3. Search for a specific message
fetch logs, from:now()-2h | filter contains(content, "timeout") | fields timestamp, host.name, loglevel, content | sort timestamp desc | limit 50 4. Extract a status code from the text
fetch logs, from:now()-1h | filter contains(content, "status=") | parse content, "LD 'status=' INT:status" | summarize hits = count(), by:{status} | sort hits desc The parse command uses the Dynatrace Pattern Language: LD consumes text up to the literal, INT:status captures the integer into a new field. To industrialise this kind of extraction, see log pattern analysis.
5. Log volume by source
fetch logs, from:now()-24h | summarize records = count(), by:{log.source} | sort records desc | limit 20 Useful to spot a chatty source before it weighs on the ingestion bill.
DQL summarize examples for traces and services
6. p95 latency by service
fetch spans, from:now()-1h | filter request.is_root_span == true | summarize p95 = percentile(duration, 95), calls = count(), by:{dt.entity.service} | fieldsAdd service = entityName(dt.entity.service) | sort p95 desc The filter on request.is_root_span keeps only the entry span of each request in a service: you measure what the caller perceives, not every internal call.
7. Error rate by service
fetch spans, from:now()-1h | filter request.is_root_span == true | summarize total = count(), failed = countIf(request.is_failed == true), by:{dt.entity.service} | fieldsAdd error_rate = 100.0 * failed / total | fieldsAdd service = entityName(dt.entity.service) | sort error_rate desc This is the shape of an availability SLI. To turn it into an SLO, see how to choose SLIs with DQL.
8. Find a trace from its ID
fetch spans, from:now()-24h | filter toString(trace.id) == "4bf92f3577b34da6a3ce929d0e0e4736" | fields start_time, span.name, duration, dt.entity.service | sort start_time asc Handy when a trace ID turns up in a log or a ticket.
9. Slowest endpoints
fetch spans, from:now()-1h | filter request.is_root_span == true | summarize p90 = percentile(duration, 90), calls = count(), by:{span.name} | filter calls > 100 | sort p90 desc | limit 15 The filter on calls drops rare endpoints, whose percentile has no statistical meaning.
Infrastructure
10. Hosts above 80% CPU
timeseries cpu = avg(dt.host.cpu.usage), by:{dt.entity.host}, from:now()-2h | fieldsAdd host = entityName(dt.entity.host) | filter arrayAvg(cpu) > 80 timeseries reads metrics; arrayAvg computes the average of the series over the period so you can filter.
11. Host memory
timeseries mem = avg(dt.host.memory.usage), by:{dt.entity.host}, from:now()-6h | fieldsAdd host = entityName(dt.entity.host), peak = arrayMax(mem) | sort peak desc | limit 10 12. Kubernetes container restarts
timeseries restarts = sum(dt.kubernetes.container.restarts), by:{k8s.namespace.name, k8s.pod.name}, from:now()-24h | fieldsAdd total = arraySum(restarts) | filter total > 0 | sort total desc The metric name depends on your version of the Kubernetes integration: check it in the metrics browser or on docs.dynatrace.com before using it.
Problems and events
13. Problems open right now
fetch dt.davis.problems | filter event.status == "ACTIVE" | fields display_id, event.name, event.category, event.start | sort event.start desc 14. MTTR for the week
fetch dt.davis.problems, from:now()-7d | filter event.status == "CLOSED" | fieldsAdd minutes = toLong(event.end - event.start) / 60000000000 | summarize problems = count(), mttr_min = avg(minutes), p90_min = percentile(minutes, 90) The difference between two timestamps gives a duration, converted here to nanoseconds by toLong, then to minutes. The p90 says more than the average: a few long incidents are enough to skew it. This query feeds an incident review directly, see the blameless postmortem with DQL.
15. Problems by category over 30 days
fetch dt.davis.problems, from:now()-30d | summarize problems = count(), by:{event.category} | sort problems desc A category that grows month after month signals reliability debt. If the volume comes mainly from noise, read reducing Davis alert noise.
How to check that it works
- Open a Notebook, paste a query and run it. An empty table is not an error: widen the window first (
from:now()-7d). - If the editor flags an unknown field, run
fetch logs | limit 5orfetch spans | limit 5and compare the actual names. - Compare a figure with a known screen: the number of open problems from query 13 should match the Problems app over the same period.
- Watch the scanned data volume shown after execution: a query that scans terabytes deserves an earlier filter in the pipeline.
Best practices
- Filter early: put
filterright afterfetchand narrow the window. The query is faster and cheaper. - Always a limit when exploring:
limitavoids pulling back millions of rows. - One shared Notebook per team, with these queries commented: on-call starts from a common base.
- Name computed fields (
errors = count()): charts and exports become readable. - Version the queries that feed an SLO or an alert, like code.
Frequently asked questions
Do these queries work on Dynatrace Managed?
No. DQL and Grail are specific to the SaaS platform. On Managed, use Data Explorer and the API v2 metric selectors (/api/v2/metrics/query) for metrics, and the log viewer for text searches.
Why does my spans query return nothing?
Check the window, then the fields: request.is_root_span and dt.entity.service are set for services detected by Dynatrace. Pure OpenTelemetry spans may only expose service.name.
Does a DQL query consume budget?
Depending on your licensing model, data analysis may be billed by volume read. Check your contract and the pricing documentation; filtering early remains the best saving.
Conclusion
Fifteen queries cover most of operations: errors, latency, saturation, problems and MTTR. Store them in a team Notebook, adapt field names to your sources, and every incident starts one step ahead.
span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of its owner. Field and metric names change: check them in your environment and in the official documentation.
Originally published on span.observer. French version: https://span.observer/fr/requetes-dql-exemples-exploitation/.


