hey folks, does anyone have a cheeky query on hand to get all of the descendants (not just immediate children) of a specific span_id? i've done the naive implementation of recessively querying children with separate queries to phoenix and it works but it is a wee bit slow
馃挕聽Hint: Mention RunLLM in the thread for followups.
here鈥檚 how the Ui does it
from httpx import Client
import pandas as pd
query = """
query ($spanId: GlobalID!) {
node(id: $spanId) {
... on Span {
descendants {
id
context {
spanId
}
}
}
}
}
"""
def get_descendants(span_id: str) -> pd.DataFrame:
response = Client(base_url="http://localhost:6006").post(
"graphql",
json={
"query": query,
"variables": {
"spanId": span_id,
},
},
)
spans = response.json()["data"]["node"]["descendants"]
return pd.json_normalize(spans)
span_id = "U3BhbjoyMQ==" # replace with your span id
df = get_descendants(span_id)
df
you need to get the span node id from the UI
can also use the graphql endpoint
oh wait -- is there any way to get span node id using python interfaces? sorry, i confused the span node id with the span id
Reviving this thread... Is there a way to do this using phoenix.Client and leveraging OpenTelemetry's span_id? I need to fetch all descendants of a root span.
Sorry I missed the follow-up question here. My apologies. Currently the only way to do this would be via the OTEL trace_id instead as shown below.
from httpx import Client
import pandas as pd
query = """
query($traceId: ID!, $projectId: GlobalID!) {
node(id: $projectId) {
... on Project {
trace(traceId: $traceId) {
spans {
edges {
node {
id
spanId
parentId
trace {
traceId
}
}
}
}
}
}
}
}
"""
def get_spans(trace_id: str, project_id: str) -> pd.DataFrame:
response = Client(base_url="http://localhost:6006").post(
"graphql",
json={
"query": query,
"variables": {
"projectId": project_id,
"traceId": trace_id,
},
},
)
spans = response.json()["data"]["node"]["trace"]["spans"]["edges"]
df = pd.json_normalize(spans)
df.columns = df.columns.str.replace('node.', '')
return df
project_id = "UHJvamVjdDox" # replace with your project node id
trace_id = "9f344b7a20422dd4989aaf01826bdfd9" # replace with your trace OTEL id
df = get_spans(trace_id, project_id)
df
