-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
ref(insights): Refactor Insights -> LLM charts #90094
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
Merged
billyvg
merged 8 commits into
master
from
billy/replay-76-refactor-charts-in-llmmonitoringcharts
Apr 24, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
353a3d8
ref(insights): Refactor Insights -> LLM charts
billyvg 9cc14a4
pass pageFilters
billyvg 60771e8
refactor to remove chartProperties
billyvg 4a10f67
revert changes
billyvg 2ffb132
remove base* widgets
billyvg fbb0c20
imports
billyvg d9cce33
imports
billyvg ee7f0b9
copy and paste bugs
billyvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,38 +2,15 @@ import {LinkButton} from 'sentry/components/core/button'; | |
import {ButtonBar} from 'sentry/components/core/button/buttonBar'; | ||
import {IconOpen} from 'sentry/icons'; | ||
import {t} from 'sentry/locale'; | ||
import type {Event} from 'sentry/types/event'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout'; | ||
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover'; | ||
import LlmEventNumberOfPipelinesChartWidget from 'sentry/views/insights/common/components/widgets/llmEventNumberOfPipelinesChartWidget'; | ||
import LlmEventTotalTokensUsedChartWidget from 'sentry/views/insights/common/components/widgets/llmEventTotalTokensUsedChartWidget'; | ||
import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL'; | ||
import { | ||
NumberOfPipelinesChart, | ||
TotalTokensUsedChart, | ||
} from 'sentry/views/insights/llmMonitoring/components/charts/llmMonitoringCharts'; | ||
import {SpanIndexedField} from 'sentry/views/insights/types'; | ||
import {SectionKey} from 'sentry/views/issueDetails/streamline/context'; | ||
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection'; | ||
|
||
interface Props { | ||
event: Event; | ||
} | ||
|
||
export default function LLMMonitoringSection({event}: Props) { | ||
export default function LLMMonitoringSection() { | ||
const moduleUrl = useModuleURL('ai'); | ||
const trace = event.contexts.trace; | ||
|
||
const {data} = useSpansIndexed( | ||
{ | ||
limit: 1, | ||
fields: [SpanIndexedField.SPAN_AI_PIPELINE_GROUP], | ||
search: new MutableSearch(`trace:${trace?.trace_id} id:"${trace?.span_id}"`), | ||
enabled: Boolean(trace?.span_id) && Boolean(trace?.trace_id), | ||
}, | ||
'api.ai-pipelines.view' | ||
); | ||
|
||
const aiPipelineGroup = data[0]?.[SpanIndexedField.SPAN_AI_PIPELINE_GROUP]; | ||
Comment on lines
-26
to
-36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into a new hook that is used in the new widgets |
||
|
||
const actions = ( | ||
<ButtonBar gap={1}> | ||
|
@@ -50,18 +27,14 @@ export default function LLMMonitoringSection({event}: Props) { | |
help={t('Charts showing how many tokens are being used')} | ||
actions={actions} | ||
> | ||
{aiPipelineGroup ? ( | ||
<ModuleLayout.Layout> | ||
<ModuleLayout.Half> | ||
<TotalTokensUsedChart groupId={aiPipelineGroup} /> | ||
</ModuleLayout.Half> | ||
<ModuleLayout.Half> | ||
<NumberOfPipelinesChart groupId={aiPipelineGroup} /> | ||
</ModuleLayout.Half> | ||
</ModuleLayout.Layout> | ||
) : ( | ||
'loading' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💀 |
||
)} | ||
<ModuleLayout.Layout> | ||
<ModuleLayout.Half> | ||
<LlmEventTotalTokensUsedChartWidget /> | ||
</ModuleLayout.Half> | ||
<ModuleLayout.Half> | ||
<LlmEventNumberOfPipelinesChartWidget /> | ||
</ModuleLayout.Half> | ||
</ModuleLayout.Layout> | ||
</InterimSection> | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
static/app/views/insights/common/components/widgets/hooks/useAiPipelineGroup.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover'; | ||
import {SpanIndexedField} from 'sentry/views/insights/types'; | ||
import {useGroupEvent} from 'sentry/views/issueDetails/useGroupEvent'; | ||
|
||
/** | ||
* Given an issue's groupId + eventId, fetch the AI | ||
* Pipeline's group ID via event's trace | ||
*/ | ||
export function useAiPipelineGroup({ | ||
groupId, | ||
eventId, | ||
}: { | ||
groupId: string; | ||
eventId?: string; | ||
}) { | ||
const { | ||
data: event, | ||
isPending: isGroupPending, | ||
error: groupError, | ||
} = useGroupEvent({groupId, eventId}); | ||
|
||
const trace = event?.contexts.trace; | ||
const { | ||
data, | ||
isPending: isSpanPending, | ||
error: spanError, | ||
} = useSpansIndexed( | ||
{ | ||
limit: 1, | ||
fields: [SpanIndexedField.SPAN_AI_PIPELINE_GROUP], | ||
search: new MutableSearch(`trace:${trace?.trace_id} id:"${trace?.span_id}"`), | ||
enabled: Boolean(trace?.span_id) && Boolean(trace?.trace_id), | ||
}, | ||
'api.ai-pipelines.view' | ||
); | ||
|
||
return { | ||
groupId: data[0]?.[SpanIndexedField.SPAN_AI_PIPELINE_GROUP], | ||
isPending: isGroupPending || isSpanPending, | ||
error: groupError || spanError, | ||
}; | ||
} |
50 changes: 50 additions & 0 deletions
50
static/app/views/insights/common/components/widgets/llmEventNumberOfPipelinesChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import {useAiPipelineGroup} from 'sentry/views/insights/common/components/widgets/hooks/useAiPipelineGroup'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmEventNumberOfPipelinesChartWidget( | ||
props: LoadableChartWidgetProps | ||
) { | ||
const params = useParams<{groupId: string; eventId?: string}>(); | ||
const {groupId, isPending, error} = useAiPipelineGroup(params); | ||
|
||
const theme = useTheme(); | ||
const aggregate = 'count()'; | ||
|
||
let query = 'span.category:"ai.pipeline"'; | ||
if (groupId) { | ||
query = `${query} span.group:"${groupId}"`; | ||
} | ||
const { | ||
data, | ||
isPending: spanMetricsSeriesIsPending, | ||
error: spanMetricsSeriesError, | ||
} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
enabled: !!groupId, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmEventNumberOfPipelinesChartWidget" | ||
isLoading={isPending || spanMetricsSeriesIsPending} | ||
error={error || spanMetricsSeriesError} | ||
title={t('Number of AI pipelines')} | ||
series={[{...data[aggregate], color: colors[1]}]} | ||
/> | ||
); | ||
} |
50 changes: 50 additions & 0 deletions
50
static/app/views/insights/common/components/widgets/llmEventTotalTokensUsedChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import {useAiPipelineGroup} from 'sentry/views/insights/common/components/widgets/hooks/useAiPipelineGroup'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmEventTotalTokensUsedChartWidget( | ||
props: LoadableChartWidgetProps | ||
) { | ||
const params = useParams<{groupId: string; eventId?: string}>(); | ||
const {groupId, isPending, error} = useAiPipelineGroup(params); | ||
|
||
const theme = useTheme(); | ||
const aggregate = 'sum(ai.total_tokens.used)'; | ||
|
||
let query = 'span.category:"ai"'; | ||
if (groupId) { | ||
query = `${query} span.ai.pipeline.group:"${groupId}"`; | ||
} | ||
const { | ||
data, | ||
isPending: spanMetricsSeriesIsPending, | ||
error: spanMetricsSeriesError, | ||
} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
enabled: !!groupId, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmEventTotalTokensUsedChartWidget" | ||
isLoading={isPending || spanMetricsSeriesIsPending} | ||
error={error || spanMetricsSeriesError} | ||
title={t('Total tokens used')} | ||
series={[{...data[aggregate], color: colors[0]}]} | ||
/> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
static/app/views/insights/common/components/widgets/llmGroupNumberOfPipelinesChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmGroupNumberOfPipelinesChartWidget( | ||
props: LoadableChartWidgetProps | ||
) { | ||
const {groupId} = useParams<{groupId: string}>(); | ||
const theme = useTheme(); | ||
const aggregate = 'count()'; | ||
|
||
const query = `span.category:"ai.pipeline" span.group:"${groupId}"`; | ||
const {data, isPending, error} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmGroupNumberOfPipelinesChartWidget" | ||
title={t('Number of AI pipelines')} | ||
series={[{...data[aggregate], color: colors[1]}]} | ||
isLoading={isPending} | ||
error={error} | ||
/> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
static/app/views/insights/common/components/widgets/llmGroupPipelineDurationChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmGroupPipelineDurationChartWidget( | ||
props: LoadableChartWidgetProps | ||
) { | ||
const {groupId} = useParams<{groupId: string}>(); | ||
const theme = useTheme(); | ||
const aggregate = 'avg(span.duration)'; | ||
|
||
const query = `span.category:"ai.pipeline" span.group:"${groupId}"`; | ||
const {data, isPending, error} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmGroupPipelineDurationChartWidget" | ||
title={t('Pipeline duration')} | ||
series={[{...data[aggregate], color: colors[2]}]} | ||
isLoading={isPending} | ||
error={error} | ||
/> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
static/app/views/insights/common/components/widgets/llmGroupTotalTokensUsedChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {useParams} from 'sentry/utils/useParams'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmGroupTotalTokensUsedChartWidget( | ||
props: LoadableChartWidgetProps | ||
) { | ||
const {groupId} = useParams<{groupId: string}>(); | ||
const theme = useTheme(); | ||
const aggregate = 'sum(ai.total_tokens.used)'; | ||
|
||
const query = `span.category:"ai" span.ai.pipeline.group:"${groupId}"`; | ||
const {data, isPending, error} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmGroupTotalTokensUsedChartWidget" | ||
title={t('Total tokens used')} | ||
series={[{...data[aggregate], color: colors[0]}]} | ||
isLoading={isPending} | ||
error={error} | ||
/> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
static/app/views/insights/common/components/widgets/llmNumberOfPipelinesChartWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {useTheme} from '@emotion/react'; | ||
|
||
import {t} from 'sentry/locale'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {InsightsLineChartWidget} from 'sentry/views/insights/common/components/insightsLineChartWidget'; | ||
import type {LoadableChartWidgetProps} from 'sentry/views/insights/common/components/widgets/types'; | ||
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries'; | ||
|
||
export default function LlmNumberOfPipelinesChartWidget(props: LoadableChartWidgetProps) { | ||
const theme = useTheme(); | ||
const aggregate = 'count()'; | ||
|
||
const query = 'span.category:"ai.pipeline"'; | ||
const {data, isPending, error} = useSpanMetricsSeries( | ||
{ | ||
yAxis: [aggregate], | ||
search: new MutableSearch(query), | ||
transformAliasToInputFormat: true, | ||
}, | ||
'api.ai-pipelines.view', | ||
props.pageFilters | ||
); | ||
|
||
const colors = theme.chart.getColorPalette(2); | ||
return ( | ||
<InsightsLineChartWidget | ||
{...props} | ||
id="llmNumberOfPipelinesChartWidget" | ||
title={t('Number of AI pipelines')} | ||
series={[{...data[aggregate], color: colors[1]}]} | ||
isLoading={isPending} | ||
error={error} | ||
/> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a yolo refactor, I don't have an issue that renders this component. @gggritso helped me look at some Sentry traces and it doesn't seem like this is used at all (at least in last 30 days)