# Get a trace

Get the spans of a trace from a source and its connected sources, as a compact tree. Repeated sibling spans under one parent, such as the same query, route or call, are collapsed into one row. Reads at most 5,000 spans of the trace from each source, the newest first. Connected sources are read too.

[endpoint]
method = "GET"
base_url = "https://telemetry.betterstack.com"
path = "/api/v4/sources/{source_id}/traces/{trace_id}"

[[path_param]]
name = "source_id"
required = true
type = "string"
description = "Spans source the trace is read from, along with the source's connected sources. Get the source ID via [List sources](/docs/logs/api/list-all-existing-sources/)."

[[path_param]]
name = "trace_id"
required = true
type = "string"
description = "The trace ID, such as `8260a352ac09d8099d76828730511db6`. Letters, digits, `-` and `_`, up to 128 characters."

[[query_param]]
name = "start_time"
type = "string"
description = "Start of the time range to look for the trace's spans in. Accepts an ISO 8601 timestamp, in UTC when it has no time zone, a relative time like `now-1h` or `now-2h45m`, or a Unix timestamp in seconds, milliseconds, microseconds or nanoseconds. Defaults to `now-1h`, so set it for an older trace."

[[query_param]]
name = "end_time"
type = "string"
description = "End of the time range, in the same forms as `start_time`. Must be after `start_time`. Defaults to `now`."

[[query_param]]
name = "team_id"
type = "string"
description = "Team to use, such as `t123`. Get the ID via [List teams](/docs/uptime/api/teams/list/). Required when you can access more than one team."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = "Returns the trace."
body = '''
{
  "data": {
    "id": "8260a352ac09d8099d76828730511db6",
    "type": "trace",
    "attributes": {
      "trace_id": "8260a352ac09d8099d76828730511db6",
      "start_time": "2026-11-22T16:18:47.901782Z",
      "duration_ms": 67055.097,
      "root_service": "frontend",
      "root_operation": "GET /checkout",
      "span_count": 169,
      "error_count": 2,
      "services": [
        "load-generator",
        "frontend",
        "checkout",
        "payment"
      ],
      "spans": [
        {
          "depth": 0,
          "span_id": "8b72f69cf7620b9c",
          "name": "user_checkout_multi",
          "kind": "internal",
          "span_type": "app",
          "service": "load-generator",
          "source_id": "4689",
          "offset_ms": 336.909,
          "duration_ms": 15512.637,
          "span_count": 1,
          "status": "ok",
          "event_count": 0,
          "detail": "",
          "exceptions": []
        },
        {
          "depth": 1,
          "span_id": "ab74fd4608ddcc2d",
          "parent_span_id": "8b72f69cf7620b9c",
          "name": "user_add_to_cart",
          "kind": "internal",
          "span_type": "app",
          "service": "load-generator",
          "source_id": "4689",
          "offset_ms": 337.203,
          "duration_ms": 494.702,
          "span_count": 4,
          "avg_duration_ms": 123.676,
          "max_duration_ms": 181.529,
          "status": "ok",
          "event_count": 0,
          "detail": "",
          "exceptions": []
        },
        {
          "depth": 2,
          "span_id": "c84588e3c3ba8a81",
          "parent_span_id": "ab74fd4608ddcc2d",
          "name": "POST",
          "kind": "client",
          "span_type": "http",
          "service": "load-generator",
          "source_id": "4689",
          "offset_ms": 833.212,
          "duration_ms": 15012.933,
          "span_count": 1,
          "status": "error",
          "event_count": 0,
          "detail": "POST http://frontend-proxy:8080/api/checkout -> 504",
          "exceptions": []
        }
      ],
      "truncated_row_count": 0,
      "orphaned_span_count": 0,
      "warnings": []
    }
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "errors": "Invalid Team API token. How to find your Team API token: https://betterstack.com/docs/logs/api/getting-started/#obtaining-a-logtail-api-token"
}
'''

[[response]]
status = 403
description = "With an OAuth token, the user's role doesn't grant Live tail in the source's team, or the API token's scopes don't include this product."
body = '''
{
  "errors": "You don't have permission to view live tail in this team. Your Better Stack role restricts this action. Ask an organization admin to update your role's permissions."
}
'''

[[response]]
status = 404
description = "The `source_id` value isn't one of your sources, or no span of the trace is in the time range. Set an earlier `start_time` for an older trace."
body = '''
{
  "errors": "Resource with the provided ID was not found"
}
'''

[[response]]
status = 422
description = "A parameter is unknown, or a value is refused and `invalid_values` names it. `trace_id` has characters other than letters, digits, `-` and `_`, `start_time` or `end_time` is invalid, `end_time` isn't after `start_time`, or the source doesn't hold spans."
body = '''
{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "trace_id": "trace_id must be a trace id: letters, digits, - and _."
  }
}
'''

[[response]]
status = 422
description = "The time range holds too many spans of the source to read. `errors` says why, and `refusal` lists time windows that each fit, the same way [Run a query](/docs/logs/api/query/) does. Ask for a shorter time range around the trace."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the trace, such as `8260a352ac09d8099d76828730511db6`."

[[param]]
name = "type"
type = "string"
description = "Always `trace`."

[[param]]
name = "trace_id"
type = "string"
description = "The trace's ID."

[[param]]
name = "start_time"
type = "datetime"
description = "When the trace's first span started, in UTC with microseconds. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "duration_ms"
type = "number"
description = "Milliseconds from the start of the first span to the end of the last one. Listing traces reads this source's spans, and getting a trace reads its connected sources' spans too."

[[param]]
name = "root_service"
type = "string or null"
description = "The service of the trace's root span. When the time range doesn't hold the root span, it's the service of the trace's first span. `null` when that span has no service. Returned by list only."

[[param]]
name = "root_operation"
type = "string or null"
description = "The name of the trace's root span. When the time range doesn't hold the root span, it's the name of the trace's first span. `null` when that span has no name. Returned by list only."

[[param]]
name = "span_count"
type = "integer"
description = "Number of spans found for the trace. Listing traces counts this source's spans, and getting a trace counts its connected sources' spans too."

[[param]]
name = "error_count"
type = "integer"
description = "Number of failed spans. A span failed when its status is an error, its HTTP response status is 400 or higher, or its gRPC status isn't `OK`. Listing traces reads this source's spans, and getting a trace reads its connected sources' spans too."

[[param]]
name = "services"
type = "array of strings"
description = "The services the trace's spans come from, in the order they first appear. Returned by get only."

[[param]]
name = "spans"
type = "array of objects"
description = "The trace's spans as a tree, one row per span in depth-first order, starting with the root spans. Repeated sibling spans are collapsed into one row. A span whose parent isn't in the trace starts a tree of its own after the root spans. At most 500 rows are returned. Returned by get only."

[[param]]
name = "spans[].depth"
type = "integer"
description = "How deep the row sits in the tree, from `0` for a root span."

[[param]]
name = "spans[].span_id"
type = "string"
description = "The span's ID. On a collapsed row, the ID of its slowest span."

[[param]]
name = "spans[].parent_span_id"
type = "string"
description = "The ID of the parent span. Left out on a root span."

[[param]]
name = "spans[].name"
type = "string"
description = "The span's name."

[[param]]
name = "spans[].kind"
type = "string"
description = "The span's kind, such as `server`, `client` or `internal`."

[[param]]
name = "spans[].span_type"
type = "string"
description = "What the span does, read from its attributes.<br/>Valid values:<br/>`db`: A database call.<br/>`http`: An HTTP request.<br/>`rpc`: A remote procedure call.<br/>`messaging`: A message queue operation.<br/>`app`: Anything else."

[[param]]
name = "spans[].service"
type = "string"
description = "The service the span comes from. Empty when the span names none."

[[param]]
name = "spans[].source_id"
type = "string"
description = "The ID of the source the span was read from, which is this source or one of its connected sources."

[[param]]
name = "spans[].offset_ms"
type = "number"
description = "Milliseconds from the trace's start to the start of the span. On a collapsed row, to the start of its first span."

[[param]]
name = "spans[].duration_ms"
type = "number"
description = "The span's duration in milliseconds. On a collapsed row, the total of its spans' durations."

[[param]]
name = "spans[].span_count"
type = "integer"
description = "How many spans the row stands for. A row of more than 1 is a collapsed row, which groups similar sibling spans under one parent, such as the same database query, route or call."

[[param]]
name = "spans[].avg_duration_ms"
type = "number"
description = "Average duration of the collapsed row's spans in milliseconds. Left out when `span_count` is 1."

[[param]]
name = "spans[].max_duration_ms"
type = "number"
description = "Duration of the collapsed row's slowest span in milliseconds. Left out when `span_count` is 1."

[[param]]
name = "spans[].status"
type = "string"
description = "Whether the span failed.<br/>Valid values:<br/>`ok`: The span didn't fail.<br/>`error`: The span failed, or on a collapsed row, any of its spans failed."

[[param]]
name = "spans[].event_count"
type = "integer"
description = "Number of events recorded on the span, or on all of a collapsed row's spans."

[[param]]
name = "spans[].detail"
type = "string"
description = "One line about what the span did, such as the database and statement, the HTTP method, URL and response status, or the called method, cut to 300 characters. Empty when the span has none of these attributes."

[[param]]
name = "spans[].exceptions"
type = "array of objects"
description = "Up to 5 exceptions recorded on the span or the collapsed row's spans, as an empty list when there are none."

[[param]]
name = "spans[].exceptions[].type"
type = "string"
description = "The exception's type. Left out when it has none."

[[param]]
name = "spans[].exceptions[].message"
type = "string"
description = "The exception's message, cut to 200 characters. Left out when it has none."

[[param]]
name = "truncated_row_count"
type = "integer"
description = "Number of rows left out of `spans` past the first 500. Returned by get only."

[[param]]
name = "orphaned_span_count"
type = "integer"
description = "Number of spans whose parent span isn't in the trace, for example because it wasn't sampled or falls outside the time range. A span without its parent starts a tree of its own in `spans`. Returned by get only."

[[param]]
name = "warnings"
type = "array of strings"
description = "Problems reading the trace, such as a connected source that couldn't be queried, whose spans are then missing from `spans`. An empty list when there are none. Returned by get only."
[/params]

#### Example cURL

```shell
[label A trace from the last 6 hours]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/traces/8260a352ac09d8099d76828730511db6?start_time=now-6h" \
  --header "Authorization: Bearer $TOKEN"
```
