Improving Query Performance for Phoenix Otel Span Properties Filtering in Arize UI
👋 The otel docs for phoenix specify some specific properties that you can attach to your spans, but then filtering on them in the UI seems to end up with some poorly performing queries. Query from expanded failed request in screenshot
query SpansTableAsideQuery(
$id: ID!
$timeRange: TimeRange!
$filterCondition: String
) {
project: node(id: $id) {
__typename
... on Project {
name
description
timeRangeTraceCount: traceCount(timeRange: $timeRange, filterCondition: $filterCondition)
costSummary(timeRange: $timeRange, filterCondition: $filterCondition) {
total {
cost
}
prompt {
cost
}
completion {
cost
}
}
latencyMsP50: latencyMsQuantile(probability: 0.5, timeRange: $timeRange, filterCondition: $filterCondition)
latencyMsP99: latencyMsQuantile(probability: 0.99, timeRange: $timeRange, filterCondition: $filterCondition)
spanAnnotationNames
traceAnnotationsNames
documentEvaluationNames
}
id
}
}translates to this in postgres (side note, there doesn't seem to be anything that is filtering to root spans only despite root spans only being selected?)
duration: 60829.069 ms execute __asyncpg_stmt_c14f__/__asyncpg_portal_c152__: SELECT traces.project_rowid, count(DISTINCT traces.id) AS count
FROM traces JOIN spans ON traces.id = spans.trace_rowid
WHERE CAST((spans.attributes #>> $1) AS VARCHAR) = $2::VARCHAR AND traces.project_rowid IN ($4::INTEGER) AND traces.start_time >= $3::TIMESTAMP WITH TIME ZONE GROUP BY traces.project_rowidIt seems like for some of these properties that we would want to have more optimal paths to the data. It looks like session id already is, but in addition, user id, tags, and metadata might be nice.
