During an incident, the query that answers the question is never a plain fetch | filter | summarize. You need to map an error to the owning team, link a business event to the logs of the same trace, extract an ID buried in a message, or smooth a noisy series to see the trend. That is the ground covered by advanced DQL.

Four tools cover most of it: lookup to enrich, join to correlate, parse to structure, and the moving array functions to reason over time. Used well, they shorten MTTR: fewer trips between screens, one query shared in the incident Notebook.

The goal of this tutorial: write, for each of these tools, a query that is useful in operations and know how to check its result. The content applies to Dynatrace SaaS (Grail and DQL); Dynatrace Managed does not run DQL on Grail.

Prerequisites

  • A Dynatrace SaaS environment with Grail, and access to Notebooks.
  • DQL basics: fetch, filter, fields, summarize (see the module on DQL fundamentals).
  • Logs and spans ingested, ideally with trace_id set on the logs.

lookup or join: what is the difference?

lookup join
Use Enrich each row with attributes from a reference table Combine two datasets on a condition
Multiple matches Only the first matching record is kept One row per matching pair: volume can grow
Default prefix for added fields lookup. right.
Rows without a match Kept, added fields set to null Depends on kind: inner, leftOuter, outer

Simple rule: if you want « one more column », use lookup. If you want « two stories side by side », use join.

Advanced DQL in practice: four queries step by step

Step 1: enrich with lookup

A reference table stored in Grail (a lookup file loaded with load) turns a technical code into readable information. Example: add the label of each HTTP code to spans.

fetch spans, from:now()-1h | filter isNotNull(http.response.status_code) | lookup [ load "/lookups/http_status_codes" ], sourceField: http.response.status_code, lookupField: code, prefix: "status." | summarize nb = count(), by:{ http.response.status_code, status.label } | sort nb desc 

Key lines: sourceField names the field in the main query, lookupField the one in the table. The prefix avoids name clashes; without it, fields arrive prefixed with lookup.. Here, status.label assumes your file has a label column: adapt it to the real content.

The table can also be a subquery. To attach to each host the number of business events it emitted:

fetch dt.entity.host | fields id, entity.name | lookup [ fetch bizevents | summarize events = count(), by:{ dt.entity.host } ], sourceField: id, lookupField: dt.entity.host, prefix: "biz." 

Step 2: correlate with join

A business event failed; what did the logs of the same trace say? join links the two sources on trace_id:

fetch bizevents, from:now()-2h | filter event.type == "checkout.failed" | limit 100 | join [ fetch logs, from:now()-2h | filter loglevel == "ERROR" ], kind: leftOuter, on: { trace_id }, executionOrder: leftFirst, fields: { log.timestamp = timestamp, content } | fields timestamp, trace_id, log.timestamp, content 

Key lines: kind: leftOuter keeps events with no matching log (fields set to null), which also reveals instrumentation gaps. executionOrder: leftFirst runs the left side first, capped at 100 rows, which avoids exceeding the right-side size limit. fields brings back only the useful columns. When names differ, write on: left[dt.entity.host] == right[id].

Step 3: structure with parse

An application log holds the information, but inside a sentence. parse applies a DPL (Dynatrace Pattern Language) pattern and creates typed fields:

fetch logs, from:now()-3h | filter contains(content, "AddItemAsync") | parse content, "LD 'userId=' LD:userId ', productId=' LD:productId ', quantity=' INT:productQuantity" | summarize total = sum(productQuantity), by:{ productId } | sort total desc | limit 10 

Key lines: LD consumes text up to the next literal, INT captures a typed integer, and the name after : becomes the field. For a JSON log, the JSON matcher extracts the keys you want directly:

| parse content, "JSON{ STRING:path, INT:integrationLatency }(flat=true)" 

If a pattern appears in all your queries, move it to ingest time in OpenPipeline: you pay for it once instead of recomputing it at every read. Log pattern analysis helps find those recurring patterns.

Step 4: reason over time with moving functions

DQL has no OVER clause as SQL does. The equivalent goes through time series: timeseries or makeTimeseries produce arrays, and the functions arrayMovingAvg, arrayMovingMax, arrayMovingMin, arrayMovingSum, arrayDelta or arrayCumulativeSum compute a window over those arrays.

timeseries cpu = avg(dt.host.cpu.usage), interval:1m, by:{ dt.entity.host } | fieldsAdd cpu_5m = arrayMovingAvg(cpu, 5) | fieldsAdd pic_5m = arrayMovingMax(cpu, 5) 

With a one-minute interval, a window of 5 elements gives a five-minute moving average. The window is expressed in number of points, not duration, and is capped at 60. The first points lack a full history: widen from: so you do not misread them.

Same principle on logs, through makeTimeseries:

fetch logs, from:now()-6h | filter loglevel == "ERROR" | makeTimeseries erreurs = count(), interval:5m | fieldsAdd tendance = arrayMovingAvg(erreurs, 6), variation = arrayDelta(erreurs) 

How to check that it works

  • lookup: count rows before and after; the number must be identical. Then filter isNull(status.label) to list codes missing from the table.
  • join: compare count() before and after. A sharp increase signals multiple matches; a null content signals logs without trace_id (see the operations DQL queries for more checks).
  • parse: add | filter isNull(productId) | limit 20 to see the rows the pattern does not recognise.
  • moving functions: plot the raw series and the smoothed one on the same Notebook chart; the second should follow the first with a visible lag.

Best practices

  • Filter before enriching: filter and limit before join or lookup cut the volume read and the query cost.
  • Name your prefixes: prefix: "biz." reads better than lookup. six months later.
  • Bound the time range on both sides of a join: a subquery without from: uses the default window, which is not necessarily the main query’s.
  • Version incident queries in a shared Notebook: they become a runbook.

Frequently asked questions

Why does my join return more rows than the source?

Each left row is repeated for every match on the right. Deduplicate the right side with summarize or dedup, or switch to lookup if one match is enough.

Where should a reference table for lookup live?

In a lookup file loaded into Grail, read with load "/lookups/...". For a table that changes often, a subquery on events or entities saves you maintaining a file.

Can a moving average cover a duration rather than a number of points?

Not directly: the window counts elements. Set interval in timeseries or makeTimeseries, then work out how many points match the duration you want.

Conclusion

lookup enriches without duplicating, join correlates two sources, parse turns a message into data, and moving functions give the trend. These four tools cover most incident questions. Keep the queries that helped: the next investigation will start one step ahead.

span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of its owner. DQL syntax changes over time: check commands and parameters in the official documentation.

Originally published on span.observer. French version: https://span.observer/fr/dql-avance-lookup-join-parse/.