Common Use Cases
Fetch all spans for a time interval
Fetch all spans for a time interval
Define the time range for your query. Use ISO 8601 format for timestamps.
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"))
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!")
Fetch all Root spans for a time interval
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.
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"))
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!")
Fetch all spans for virtual accounts
Fetch all spans for virtual accounts
Define the time range for your query. Use ISO 8601 format for timestamps.
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"))
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!")
Fetch all spans for a virtual account `exampleaccount`
Fetch all spans for a virtual account `exampleaccount`
Define the time range for your query. Use ISO 8601 format for timestamps.
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"))
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!")
Fetch all spans for users
Fetch all spans for users
Define the time range for your query. Use ISO 8601 format for timestamps.
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"))
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!")
Fetch all spans for a user with email example@email.com
Fetch all spans for a user with email example@email.com
Define the time range for your query. Use ISO 8601 format for timestamps.
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"))
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!")