Skip to content

Commit

Permalink
[AI Assistant] Add scopes telemetry to AI Assistant events (#197983)
Browse files Browse the repository at this point in the history
## Summary

This adds telemetry to the Observability and Search assistant to judge
whether it's search or observability.
  • Loading branch information
sphilipse authored Oct 30, 2024
1 parent 3a8bd70 commit 74cf0e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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.',
},
},
},
};

0 comments on commit 74cf0e4

Please sign in to comment.