Skip to content
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
3 changes: 3 additions & 0 deletions static/app/views/insights/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export enum SpanFields {
GEN_AI_REQUEST_MODEL = 'gen_ai.request.model',
GEN_AI_RESPONSE_MODEL = 'gen_ai.response.model',
GEN_AI_TOOL_NAME = 'gen_ai.tool.name',
GEN_AI_COST_INPUT_TOKENS = 'gen_ai.cost.input_tokens',
GEN_AI_COST_OUTPUT_TOKENS = 'gen_ai.cost.output_tokens',
GEN_AI_COST_TOTAL_TOKENS = 'gen_ai.cost.total_tokens',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing AI Cost Fields in Number Fields

The new GEN_AI_COST_INPUT_TOKENS, GEN_AI_COST_OUTPUT_TOKENS, and GEN_AI_COST_TOTAL_TOKENS fields are in SpanFields but missing from SpanNumberFields. These are numeric cost values, like GEN_AI_USAGE_TOTAL_COST, and are typically formatted as dollars.

Fix in Cursor Fix in Web

GEN_AI_USAGE_INPUT_TOKENS = 'gen_ai.usage.input_tokens',
GEN_AI_USAGE_INPUT_TOKENS_CACHED = 'gen_ai.usage.input_tokens.cached',
GEN_AI_USAGE_OUTPUT_TOKENS = 'gen_ai.usage.output_tokens',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import type {Project} from 'sentry/types/project';
import {trackAnalytics} from 'sentry/utils/analytics';
import type {RenderFunctionBaggage} from 'sentry/utils/discover/fieldRenderers';
import {FieldKey} from 'sentry/utils/fields';
import {formatDollars} from 'sentry/utils/formatters';
import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
import {ellipsize} from 'sentry/utils/string/ellipsize';
import {looksLikeAJSONArray} from 'sentry/utils/string/looksLikeAJSONArray';
import {looksLikeAJSONObject} from 'sentry/utils/string/looksLikeAJSONObject';
import type {AttributesFieldRendererProps} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
import {AttributesTree} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
import type {TraceItemResponseAttribute} from 'sentry/views/explore/hooks/useTraceItemDetails';
import {SpanFields} from 'sentry/views/insights/types';
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
import {FoldSection} from 'sentry/views/issueDetails/streamline/foldSection';
import {TraceDrawerComponents} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/styles';
Expand Down Expand Up @@ -165,6 +167,18 @@ export function Attributes({
};
return <StyledLink to={target}>{props.item.value}</StyledLink>;
},
[SpanFields.GEN_AI_COST_INPUT_TOKENS]: (props: CustomRenderersProps) => {
return formatDollars(+Number(props.item.value).toFixed(10));
},
[SpanFields.GEN_AI_COST_OUTPUT_TOKENS]: (props: CustomRenderersProps) => {
return formatDollars(+Number(props.item.value).toFixed(10));
},
[SpanFields.GEN_AI_COST_TOTAL_TOKENS]: (props: CustomRenderersProps) => {
return formatDollars(+Number(props.item.value).toFixed(10));
},
[SpanFields.GEN_AI_USAGE_TOTAL_COST]: (props: CustomRenderersProps) => {
return formatDollars(+Number(props.item.value).toFixed(10));
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Precision Loss in AI Cost Renderers

The AI cost custom renderers use toFixed(10) for precision, but the unary + operator immediately converts the result back to a number. This reintroduces floating point precision issues and removes trailing zeros, undermining the goal of accurate cost display.

Fix in Cursor Fix in Web

};

// Some attributes (semantic or otherwise) look like they contain JSON-encoded
Expand Down
Loading