Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't join spans on count traces query #182

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions app-server/src/db/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,31 @@ pub async fn count_traces(
date_range: &Option<DateRange>,
text_search_filter: Option<String>,
) -> Result<i64> {
let mut query = QueryBuilder::<Postgres>::new("WITH ");
add_traces_info_expression(&mut query, date_range, project_id)?;
let mut query = QueryBuilder::<Postgres>::new(
"WITH traces_info AS (
SELECT
id,
start_time,
end_time,
version,
release,
user_id,
session_id,
metadata,
project_id,
input_token_count,
output_token_count,
total_token_count,
input_cost,
output_cost,
cost,
success,
trace_type,
EXTRACT(EPOCH FROM (end_time - start_time)) as latency,
CASE WHEN success = true THEN 'Success' ELSE 'Failed' END status
FROM traces
WHERE start_time IS NOT NULL AND end_time IS NOT NULL AND trace_type = 'DEFAULT')",
);
query.push(
"
SELECT
Expand All @@ -471,6 +494,7 @@ pub async fn count_traces(
}
query.push(" WHERE project_id = ");
query.push_bind(project_id);
add_date_range_to_query(&mut query, date_range, "start_time", Some("end_time"))?;

add_filters_to_traces_query(&mut query, &filters);

Expand Down
1 change: 1 addition & 0 deletions app-server/src/traces/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl Span {
.get("SpanAttributes.LLM_PROMPTS.0.content")
.is_some()
{
// handling the LiteLLM auto-instrumentation
let input_messages = input_chat_messages_from_prompt_content(
&attributes,
"SpanAttributes.LLM_PROMPTS",
Expand Down
33 changes: 21 additions & 12 deletions frontend/components/traces/sessions-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export default function SessionsTable({ onRowClick }: SessionsTableProps) {
<span className="text-gray-500">Trace</span>
</div>
),
id: 'type'
id: 'type',
size: 120
},
{
accessorFn: (row) => (row.data.id === null ? '-' : row.data.id),
Expand All @@ -156,42 +157,50 @@ export default function SessionsTable({ onRowClick }: SessionsTableProps) {

return (row.data as SessionPreview).duration.toFixed(3) + 's';
},
header: 'Duration'
header: 'Duration',
size: 100,
},
{
accessorFn: (row) => '$' + row.data.inputCost?.toFixed(5),
header: 'Input cost',
id: 'input_cost'
id: 'input_cost',
size: 120,
},
{
accessorFn: (row) => '$' + row.data.outputCost?.toFixed(5),
header: 'Output cost',
id: 'output_cost'
id: 'output_cost',
size: 120,
},
{
accessorFn: (row) => '$' + row.data.cost?.toFixed(5),
header: 'Total cost',
id: 'cost'
id: 'cost',
size: 120,
},
{
accessorFn: (row) => row.data.inputTokenCount,
header: 'Input token count',
id: 'input_token_count'
header: 'Input tokens',
id: 'input_token_count',
size: 120,
},
{
accessorFn: (row) => row.data.outputTokenCount,
header: 'Output token count',
id: 'output_token_count'
header: 'Output tokens',
id: 'output_token_count',
size: 120,
},
{
accessorFn: (row) => row.data.totalTokenCount,
header: 'Token count',
id: 'total_token_count'
header: 'Total tokens',
id: 'total_token_count',
size: 120,
},
{
accessorFn: (row) => (row.data as SessionPreview).traceCount,
header: 'Trace Count',
id: 'trace_count'
id: 'trace_count',
size: 120,
}
];

Expand Down