---
title: Query distributed trace data
source: https://docs.newrelic.com/docs/distributed-tracing/ui-data/query-distributed-trace-data
---

You can query your [distributed tracing](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/get-started/introduction-distributed-tracing) data in several ways:

-   The search bar at top of the [distributed tracing UI](https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/understand-use-distributed-tracing-data)
-   [NRQL query](#example-nrql-queries)
-   [NerdGraph GraphiQL explorer](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/query-distributed-trace-data-using-graphql-api)

To learn about trace structure, see [How distributed tracing works](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/get-started/how-new-relic-distributed-tracing-works).

## Example NRQL queries

> #### 💡 TIP
>
> You can also construct complex queries in the search bar at the top of the [distributed tracing UI](https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/understand-use-distributed-tracing-data).

Some example NRQL queries:

**Datastore time percentile for an app**

````sql
SELECT percentile(duration, 50, 95) FROM Span WHERE category = 'datastore' 
AND appName = 'YOUR_APP_NAME' SINCE 4 hours ago TIMESERIES 1 minute
```

````

**Datastore query time for an app, faceted by host**

````sql
SELECT average(duration) FROM Span WHERE appName = 'YOUR_APP_NAME' 
AND category = 'datastore' FACET host TIMESERIES 1 minute
```

````

**Average duration for a method of a service, faceted by host**

````sql
SELECT average(duration) FROM Span WHERE appName = 'YOUR_APP_NAME'
AND name = 'FUNCTION_NAME' FACET host TIMESERIES 1 minute
```

````

**Histogram of external services called by a service, faceted by external URI**

````sql
SELECT histogram(duration, 10, 60) FROM Span WHERE category = 'http'
AND appName = 'YOUR_APP_NAME' FACET `http.url` SINCE 4 hours ago
```

````

**Average duration for external calls across all applications**

````sql
SELECT average(duration) FROM Span WHERE category = 'http'
SINCE 4 hours ago FACET `http.url` TIMESERIES 1 minute
```

````

## Example NerdGraph queries [#graphql-queries]

You can also use [NerdGraph](https://docs.newrelic.com/docs/apis/graphql-api/get-started/introduction-new-relic-nerdgraph) to query your trace data using the API. For more information, see the [NerdGraph distributed tracing data query examples](https://docs.newrelic.com/docs/apis/graphql-api/tutorials/query-distributed-trace-data-using-graphql-api).

## Can't find data? [#issues]

Having trouble finding data when querying? See [Troubleshooting: missing data](https://docs.newrelic.com/docs/apm/distributed-tracing/troubleshooting/troubleshooting-missing-trace-data).
