-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Agent Builder] APM error AI insights #243734
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
Open
viduni94
wants to merge
42
commits into
elastic:main
Choose a base branch
from
viduni94:agent-builder-error-sample-contextual-insights
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
cc0410c
Attachment for APM error (inline)
viduni94 3a28d9a
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 1ccbfd1
Use feature flag to determine which contextual insights to show
viduni94 35603e5
Use feature flag to determine which contextual insights to show
viduni94 10483ab
Introduce tools to fetch error details when needed for the error atta…
viduni94 8f8c78f
Update tool name
viduni94 a3d5ed8
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 4982c72
Finalize prompts and instructions
viduni94 5da195b
Optionally test with Obs Agent
viduni94 af0ac1d
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 3bb2c87
Inline contextual insights summary
viduni94 3cf2b6e
Inline contextual insights summary
viduni94 aee61ef
Remove attachment-specific tools
viduni94 6ee9a8e
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 fbf77c1
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 f77d911
Use common component and rename folders to agent_builder
viduni94 cbff403
Consume common attachment
viduni94 1d5a789
Remove error attachment
viduni94 ad40e30
Revert minor change
viduni94 de7aa86
Update route folder
viduni94 22f8f7a
Remove unused tools
viduni94 0cefbe2
Update attachment ID
viduni94 8cbf990
Update descriptions
viduni94 dac8c5b
Rename file
viduni94 6ee275c
Add todos
viduni94 3f61d56
Remove extra newline
viduni94 68d173e
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 58787be
Fix conflicts
viduni94 49e4ace
Update return type
viduni94 e97411b
Use hook exposed by agent builder for connector selection
viduni94 68cc56f
Use hook exposed by agent builder for connector selection
viduni94 3299c90
Use data registry and move the error AI insights route to the observa…
viduni94 1b33932
Bring back the error attachment
viduni94 e224c63
Add server-side system prompt
viduni94 d3f9665
Attach error when the flyout is opened from that page
viduni94 6b822e9
Add comment
viduni94 7afd665
Add guardrail
viduni94 08c553a
Add data fetchers
viduni94 42c338a
Remove comment
viduni94 185c3c4
Merge branch 'main' into agent-builder-error-sample-contextual-insights
viduni94 a8adac0
Changes from node scripts/lint_ts_projects --fix
kibanamachine d8a8a2d
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine 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
11 changes: 11 additions & 0 deletions
11
x-pack/solutions/observability/plugins/apm/common/agent_builder/attachment_ids.ts
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,11 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| // Duplicate of the attachment type ID defined in @kbn/observability-agent-plugin/server/attachments | ||
| // Re-defined here to avoid cross-plugin dependency cycles | ||
| export const OBSERVABILITY_AI_INSIGHT_ATTACHMENT_TYPE_ID = 'observability.ai_insight'; | ||
| export const OBSERVABILITY_ERROR_ATTACHMENT_TYPE_ID = 'observability.error'; |
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
x-pack/solutions/observability/plugins/apm/common/agent_builder/get_is_obs_agent_enabled.ts
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,19 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { CoreStart } from '@kbn/core/public'; | ||
| import { | ||
| OBSERVABILITY_AGENT_FEATURE_FLAG, | ||
| OBSERVABILITY_AGENT_FEATURE_FLAG_DEFAULT, | ||
| } from './feature_flag'; | ||
|
|
||
| export function getIsObservabilityAgentEnabled(coreStart: CoreStart): boolean { | ||
| return coreStart.featureFlags.getBooleanValue( | ||
| OBSERVABILITY_AGENT_FEATURE_FLAG, | ||
| OBSERVABILITY_AGENT_FEATURE_FLAG_DEFAULT | ||
| ); | ||
| } |
File renamed without changes.
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
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
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
137 changes: 137 additions & 0 deletions
137
...omponents/app/error_group_details/error_sampler/error_sample_agent_builder_ai_insight.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,137 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
| import React, { useMemo, useState } from 'react'; | ||
| import { EuiSpacer } from '@elastic/eui'; | ||
| import { AiInsight } from '@kbn/observability-agent-builder'; | ||
| import { useConnectorSelection } from '@kbn/onechat-plugin/public'; | ||
| import { | ||
| OBSERVABILITY_AI_INSIGHT_ATTACHMENT_TYPE_ID, | ||
| OBSERVABILITY_ERROR_ATTACHMENT_TYPE_ID, | ||
| } from '../../../../../common/agent_builder/attachment_ids'; | ||
| import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context'; | ||
| import { getIsObservabilityAgentEnabled } from '../../../../../common/agent_builder/get_is_obs_agent_enabled'; | ||
| import { useAnyOfApmParams } from '../../../../hooks/use_apm_params'; | ||
| import { useTimeRange } from '../../../../hooks/use_time_range'; | ||
| import type { APIReturnType } from '../../../../services/rest/create_call_apm_api'; | ||
|
|
||
| export function ErrorSampleAgentBuilderAiInsight({ | ||
| error, | ||
| transaction, | ||
| }: APIReturnType<'GET /internal/apm/services/{serviceName}/errors/{groupId}/error/{errorId}'>) { | ||
| const { onechat, core, inference } = useApmPluginContext(); | ||
| const isObservabilityAgentEnabled = getIsObservabilityAgentEnabled(core); | ||
|
|
||
| const { query } = useAnyOfApmParams( | ||
| '/services/{serviceName}/errors/{groupId}', | ||
| '/mobile-services/{serviceName}/errors-and-crashes/errors/{groupId}', | ||
| '/mobile-services/{serviceName}/errors-and-crashes/crashes/{groupId}' | ||
| ); | ||
| const { rangeFrom, rangeTo, environment, kuery } = query; | ||
| const { start, end } = useTimeRange({ rangeFrom, rangeTo }); | ||
|
|
||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [summary, setSummary] = useState(''); | ||
| const [context, setContext] = useState(''); | ||
|
|
||
| const { selectedConnector, defaultConnectorId } = useConnectorSelection(); | ||
|
|
||
| const fetchAiInsights = async () => { | ||
| setIsLoading(true); | ||
| try { | ||
| const response = await core.http.post<{ summary: string; context: string }>( | ||
| '/internal/observability_agent_builder/ai_insights/error', | ||
| { | ||
| body: JSON.stringify({ | ||
| serviceName: error.service.name, | ||
| errorId: error.error.id, | ||
| start, | ||
| end, | ||
| environment, | ||
| kuery, | ||
| connectorId: selectedConnector ?? defaultConnectorId ?? '', | ||
| }), | ||
| } | ||
| ); | ||
|
|
||
| setSummary(response?.summary ?? ''); | ||
| setContext(response?.context ?? ''); | ||
| } catch (e) { | ||
| setSummary(''); | ||
| setContext(''); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const attachments = useMemo(() => { | ||
| if (!onechat || !isObservabilityAgentEnabled) { | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| id: 'apm_error_details_screen_context_attachment', | ||
| type: 'screen_context', | ||
| data: { | ||
| app: 'apm', | ||
| url: window.location.href, | ||
| description: `APM error details page for ${error.service.name}`, | ||
| }, | ||
| hidden: true, | ||
| }, | ||
| { | ||
| id: 'apm_error_details_ai_insight_attachment', | ||
| type: OBSERVABILITY_AI_INSIGHT_ATTACHMENT_TYPE_ID, | ||
| data: { | ||
| summary, | ||
| context, | ||
| }, | ||
| }, | ||
| { | ||
| id: 'apm_error_details_error_attachment', | ||
| type: OBSERVABILITY_ERROR_ATTACHMENT_TYPE_ID, | ||
| data: { | ||
| errorId: error.error.id, | ||
| serviceName: error.service.name, | ||
| environment, | ||
| start, | ||
| end, | ||
| }, | ||
| }, | ||
| ]; | ||
| }, [error, onechat, isObservabilityAgentEnabled, summary, context, environment, start, end]); | ||
|
|
||
| if (!onechat || !isObservabilityAgentEnabled || !inference) { | ||
| return <></>; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <AiInsight | ||
| title={i18n.translate('xpack.apm.errorAiInsight.titleLabel', { | ||
| defaultMessage: "What's this error?", | ||
| })} | ||
| description={i18n.translate('xpack.apm.errorAiInsight.descriptionLabel', { | ||
| defaultMessage: 'Get helpful insights from our Elastic AI Agent', | ||
| })} | ||
| content={summary} | ||
| isLoading={isLoading} | ||
| onOpen={fetchAiInsights} | ||
| onStartConversation={() => { | ||
| onechat.openConversationFlyout({ | ||
| attachments, | ||
| sessionTag: 'apm-error-ai-insight', | ||
| newConversation: true, | ||
| }); | ||
| }} | ||
| /> | ||
| <EuiSpacer size="s" /> | ||
| </> | ||
| ); | ||
| } |
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.