# Match nested span data based on time in DQL

**URL:** <https://community.dynatrace.com/t/match-nested-span-data-based-on-time-in-dql/54697>\
**Category:** DQL\
**Tags:** dql, spans, lookup\
**Created:** [January 21, 2026, 2:47pm UTC](https://community.dynatrace.com/t/match-nested-span-data-based-on-time-in-dql/54697 "2026-01-21T14:47:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimGiants92](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SimGiants92](https://community.dynatrace.com/u/SimGiants92)\
**Post date:** [January 21, 2026, 2:47pm UTC](https://community.dynatrace.com/t/match-nested-span-data-based-on-time-in-dql/54697/1 "2026-01-21T14:47:36Z")

</div>

Hello, wondering if this is possible using DQL i gave it a solid try but cannot do it.  
I have the opentelemetry plugin installed on jenkins sending data to dynatrace.  
I would like to use the trace/span data to see all the pipelines that a given computer was used on.  
The problem is only the first span contains the pipeline name and url (ci.pipeline.id and ci.pipeline.url)  
And later in the trace some spans contain the computer name (jenkins.computer.name). So far no problem. I have the query below that uses a lookup to match the data.  
There is an exception though , if a pipeline is called by another pipeline they are all part of the same trace. In that case the query below can return wrong results.  
I need a way to find the span that contains the computer name that happened the closest in time after the span that contains the pipeline name. Wondering if a DQL magician knows how to do this?

This is what i already have:

```markup
fetch spans
| filter jenkins.instance.name == $Controller
| filter isNotNull(ci.pipeline.id)
| lookup [
    fetch spans
    | filter jenkins.computer.name == $Computer
    | filter jenkins.instance.name == $Controller
    | fields trace.id,span.name,jenkins.computer.name
  ], sourceField:trace.id, lookupField:trace.id
| filter isNotNull(lookup.trace.id)
| dedup trace.id
| sort start_time asc
| fields start_time,duration,lookup.jenkins.computer.name,ci.pipeline.id,ci.pipeline.run.url

```

---

<div class="post-metadata">

**Author:** ![t\_pawlak](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/t_pawlak/32/14991_2.png) [@t\_pawlak](https://community.dynatrace.com/u/t_pawlak)\
**Post date:** [January 22, 2026, 12:23pm UTC](https://community.dynatrace.com/t/match-nested-span-data-based-on-time-in-dql/54697/2 "2026-01-22T12:23:33Z")

</div>

Hi,  
IMO&nbsp;Yes, it’s possible, but lookup can’t reliably pick the “closest in time” span when multiple pipeline spans exist.  
Try use&nbsp;join, compute the time delta, keep only positive deltas.  
here example:

```markup
fetch spans
| filter jenkins.instance.name == "jenkins-prod"
| filter jenkins.computer.name == "agent-01"
| fields trace.id,
         computer_start = start_time,
         computer_span = span.name,
         jenkins.computer.name
| join [
    fetch spans
    | filter jenkins.instance.name == "jenkins-prod"
    | filter isNotNull(ci.pipeline.id)
    | fields trace.id,
             pipeline_start = start_time,
             ci.pipeline.id,
             ci.pipeline.run.url
  ],
  on: { left[trace.id] == right[trace.id] }
| fieldsAdd delta = computer_start - right.pipeline_start
| filter delta >= 0
| sort delta asc
| dedup trace.id, computer_start
| fields computer_start,
         jenkins.computer.name,
         right.ci.pipeline.id,
         right.ci.pipeline.run.url,
         delta
| sort computer_start asc

```

---

<div class="post-metadata">

**Author:** ![SimGiants92](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@SimGiants92](https://community.dynatrace.com/u/SimGiants92)\
**Post date:** [January 22, 2026, 7:48pm UTC](https://community.dynatrace.com/t/match-nested-span-data-based-on-time-in-dql/54697/3 "2026-01-22T19:48:45Z")

</div>

Thank you so much for the answer! Unfortunately it does not work it still gives a random pipeline id in the case of nested pipelines. I did not consider the possibility of parallel pipelines in the same trace id. I got something working with nested lookup going to the parent span id each time but its not pretty. i am still looking for an elegant solution.
