> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Request Logs: Common Use Cases

> Common span query patterns for time ranges, users, and virtual accounts.

## Common Use Cases

> [accordion] Fetch all spans for a time interval
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch spans completed!")
> ```

> [accordion] Fetch all Root spans for a time interval
>
> A root span is the top-level span in a trace hierarchy that has no parent span.
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     parent_span_ids=[""],
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "parentSpanIds": [""],
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch root spans completed!")
> ```

> [accordion] Fetch all spans for virtual accounts
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     created_by_subject_types=["virtualaccount"],
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "createdBySubjectTypes": ["virtualaccount"],
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch virtual account spans completed!")
> ```

> [accordion] Fetch all spans for a virtual account `exampleaccount`
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     created_by_subject_slugs=["exampleaccount"],
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "createdBySubjectSlugs": ["exampleaccount"],
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch spans for virtual account completed!")
> ```

> [accordion] Fetch all spans for users
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     created_by_subject_types=["user"],
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "createdBySubjectTypes": ["user"],
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch user spans completed!")
> ```

> [accordion] Fetch all spans for a user with email [example@email.com](mailto:example@email.com)
>
> Define the time range for your query. Use ISO 8601 format for timestamps.
>
> ```python TrueFoundry SDK lines theme={"dark"}
> from truefoundry import client
> from truefoundry_sdk import SortDirection
>
> spans = client.traces.query_spans(
>     data_routing_destination="default",
>     start_time="2025-10-08T00:00:00.000Z",
>     end_time="2025-10-08T23:59:59.999Z",
>     created_by_subject_slugs=["example@email.com"],
>     limit=200,
>     sort_direction=SortDirection.DESC
> )
>
> # Process all spans across all pages
> for span in spans:
>     print(span.span_name, span.duration, span.span_attributes.get("tfy.span_type"))
> ```
>
> ```python HTTP API lines theme={"dark"}
> import requests
>
> page_token = None
> done = False
>
> while not done:
>     # Make API request
>     response = requests.post(
>         "https://{control_plane_url}/api/svc/v1/spans/query",
>         headers={
>             "Authorization": "Bearer YOUR_API_TOKEN",
>             "Content-Type": "application/json"
>         },
>         json={
>             "dataRoutingDestination": "default",
>             "startTime": "2025-10-08T00:00:00.000Z",
>             "endTime": "2025-10-08T23:59:59.999Z",
>             "createdBySubjectSlugs": ["example@email.com"],
>             "limit": 200,
>             "sortDirection": "desc",
>             "pageToken": page_token
>         }
>     )
>
>     response.raise_for_status()
>     data = response.json()
>
>     for span in data['data']:
>         print(span['spanName'], span['duration'], span['spanAttributes'].get("tfy.span_type"))
>
>     page_token = data['pagination'].get("nextPageToken")
>     done = page_token is None
>
> print("Fetch spans for user completed!")
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.