Skip to content

Commit

Permalink
chore(ai-monitoring): Add a unit to total cost (getsentry#70484)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-sentry authored May 8, 2024
1 parent 50b4ed3 commit 6b530ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
18 changes: 9 additions & 9 deletions static/app/views/aiMonitoring/PipelinesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ type Row = Pick<
| 'avg(span.duration)'
| 'sum(span.duration)'
| 'ai_total_tokens_used()'
| 'ai_total_tokens_used(c:spans/ai.total_cost@none)'
| 'ai_total_tokens_used(c:spans/ai.total_cost@usd)'
>;

type Column = GridColumnHeader<
| 'span.description'
| 'spm()'
| 'avg(span.duration)'
| 'ai_total_tokens_used()'
| 'ai_total_tokens_used(c:spans/ai.total_cost@none)'
| 'ai_total_tokens_used(c:spans/ai.total_cost@usd)'
>;

const COLUMN_ORDER: Column[] = [
Expand All @@ -62,7 +62,7 @@ const COLUMN_ORDER: Column[] = [
width: 180,
},
{
key: 'ai_total_tokens_used(c:spans/ai.total_cost@none)',
key: 'ai_total_tokens_used(c:spans/ai.total_cost@usd)',
name: t('Total cost'),
width: 180,
},
Expand Down Expand Up @@ -130,24 +130,24 @@ export function PipelinesTable() {
fields: [
'span.ai.pipeline.group',
'ai_total_tokens_used()',
'ai_total_tokens_used(c:spans/ai.total_cost@none)',
'ai_total_tokens_used(c:spans/ai.total_cost@usd)',
],
});

const rows: Row[] = (data as Row[]).map(baseRow => {
const row: Row = {
...baseRow,
'ai_total_tokens_used()': 0,
'ai_total_tokens_used(c:spans/ai.total_cost@none)': 0,
'ai_total_tokens_used(c:spans/ai.total_cost@usd)': 0,
};
if (!tokensUsedLoading) {
const tokenUsedDataPoint = tokensUsedData.find(
tokenRow => tokenRow['span.ai.pipeline.group'] === row['span.group']
);
if (tokenUsedDataPoint) {
row['ai_total_tokens_used()'] = tokenUsedDataPoint['ai_total_tokens_used()'];
row['ai_total_tokens_used(c:spans/ai.total_cost@none)'] =
tokenUsedDataPoint['ai_total_tokens_used(c:spans/ai.total_cost@none)'];
row['ai_total_tokens_used(c:spans/ai.total_cost@usd)'] =
tokenUsedDataPoint['ai_total_tokens_used(c:spans/ai.total_cost@usd)'];
}
}
return row;
Expand Down Expand Up @@ -237,8 +237,8 @@ function renderBodyCell(
</Link>
);
}
if (column.key === 'ai_total_tokens_used(c:spans/ai.total_cost@none)') {
const cost = row['ai_total_tokens_used(c:spans/ai.total_cost@none)'];
if (column.key === 'ai_total_tokens_used(c:spans/ai.total_cost@usd)') {
const cost = row['ai_total_tokens_used(c:spans/ai.total_cost@usd)'];
if (cost) {
if (cost < 0.01) {
return <span>US {cost * 100}¢</span>;
Expand Down
7 changes: 2 additions & 5 deletions static/app/views/aiMonitoring/aiMonitoringDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ export default function AiMonitoringPage({params}: Props) {
'span.category': 'ai',
'span.ai.pipeline.group': groupId,
}),
fields: [
'ai_total_tokens_used()',
'ai_total_tokens_used(c:spans/ai.total_cost@none)',
],
fields: ['ai_total_tokens_used()', 'ai_total_tokens_used(c:spans/ai.total_cost@usd)'],
enabled: Boolean(groupId),
referrer: 'api.ai-pipelines.view',
});
Expand Down Expand Up @@ -137,7 +134,7 @@ export default function AiMonitoringPage({params}: Props) {
title={t('Total Cost')}
value={
tokenUsedMetric[
'ai_total_tokens_used(c:spans/ai.total_cost@none)'
'ai_total_tokens_used(c:spans/ai.total_cost@usd)'
]
}
unit={CurrencyUnit.USD}
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/starfish/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export type SpanMetricsResponse = {
'http_response_rate(4)': number;
'http_response_rate(5)': number;
} & {
'ai_total_tokens_used(c:spans/ai.total_cost@none)': number;
'ai_total_tokens_used(c:spans/ai.total_cost@usd)': number;
} & {
['project']: string;
['project.id']: number;
Expand Down

0 comments on commit 6b530ff

Please sign in to comment.