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

[AI Assistant] Add scopes telemetry to AI Assistant events #197983

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useLastUsedPrompts } from '../hooks/use_last_used_prompts';
import { FunctionListPopover } from '../chat/function_list_popover';
import { PromptEditorFunction } from './prompt_editor_function';
import { PromptEditorNaturalLanguage } from './prompt_editor_natural_language';
import { useScopes } from '../hooks/use_scopes';

export interface PromptEditorProps {
disabled: boolean;
Expand All @@ -42,6 +43,7 @@ export function PromptEditor({
onSendTelemetry,
onSubmit,
}: PromptEditorProps) {
const scopes = useScopes();
const containerRef = useRef<HTMLDivElement>(null);

const [mode, setMode] = useState<'prompt' | 'function'>(
Expand Down Expand Up @@ -121,16 +123,15 @@ export function PromptEditor({

setInnerMessage(undefined);
setMode('prompt');

onSendTelemetry({
type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat,
payload: message,
payload: { ...message, scopes },
});
} catch (_) {
setInnerMessage(oldMessage);
setMode(oldMessage.function_call?.name ? 'function' : 'prompt');
}
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit]);
}, [addLastUsedPrompt, innerMessage, loading, onSendTelemetry, onSubmit, scopes]);

// Submit on Enter
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { AnalyticsServiceSetup, AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import { AssistantScope } from '@kbn/ai-assistant-common';
import type { Message } from '../../common';
import { chatFeedbackEventSchema, ChatFeedback } from './schemas/chat_feedback';
import { insightFeedbackEventSchema, InsightFeedback } from './schemas/insight_feedback';
Expand All @@ -17,7 +18,10 @@ const schemas = [chatFeedbackEventSchema, insightFeedbackEventSchema, userSentPr
export type TelemetryEventTypeWithPayload =
| { type: ObservabilityAIAssistantTelemetryEventType.ChatFeedback; payload: ChatFeedback }
| { type: ObservabilityAIAssistantTelemetryEventType.InsightFeedback; payload: InsightFeedback }
| { type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat; payload: Message };
| {
type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat;
payload: Message & { scopes: AssistantScope[] };
};

export const registerTelemetryEventTypes = (analytics: AnalyticsServiceSetup) => {
schemas.forEach((schema) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

import type { RootSchema } from '@kbn/core/public';
import { AssistantScope } from '@kbn/ai-assistant-common';
import type { Message } from '../../../common';

export const messageSchema: RootSchema<Message> = {
export const messageSchema: RootSchema<Message & { scopes: AssistantScope[] }> = {
'@timestamp': {
type: 'text',
_meta: {
Expand Down Expand Up @@ -74,4 +75,13 @@ export const messageSchema: RootSchema<Message> = {
},
},
},
scopes: {
type: 'array',
items: {
type: 'text',
_meta: {
description: 'The scopes that were used when generating the message.',
},
},
},
};