From 419433ea68b10d01e0988b60ce79d0b181797fd6 Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Mon, 2 Dec 2024 12:22:50 -0500 Subject: [PATCH] [Obs AI Assistant] Send custom telemetry event on Insight response (#202353) ## Summary ### Problem There is no custom Telemetry event for Insights at the moment. Therefore the clicks are differentiated based on the HTML of the elements of the UI, however sometimes these clicks can come from clusters with a connector or without a connector. Because of this behaviour there is no way to differentiate which clusters have a GenAI connector and which clusters don't. ### Solution - Introduce a custom Telemetry event - `InsightResponse = 'observability_ai_assistant_insight_response'` - Send this event when the LLM generates a response for an insight. ### Checklist - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../public/analytics/index.ts | 12 ++++++++- .../analytics/schemas/insight_response.ts | 25 +++++++++++++++++++ .../public/analytics/telemetry_event_type.ts | 1 + .../public/components/insight/insight.tsx | 11 ++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/schemas/insight_response.ts diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/index.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/index.ts index 049c5a1e65fb0..422ef625cdc64 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/index.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/index.ts @@ -10,10 +10,16 @@ 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'; +import { insightResponseEventSchema, InsightResponse } from './schemas/insight_response'; import { userSentPromptEventSchema } from './schemas/user_sent_prompt'; import { ObservabilityAIAssistantTelemetryEventType } from './telemetry_event_type'; -const schemas = [chatFeedbackEventSchema, insightFeedbackEventSchema, userSentPromptEventSchema]; +const schemas = [ + chatFeedbackEventSchema, + insightFeedbackEventSchema, + userSentPromptEventSchema, + insightResponseEventSchema, +]; export type TelemetryEventTypeWithPayload = | { type: ObservabilityAIAssistantTelemetryEventType.ChatFeedback; payload: ChatFeedback } @@ -21,6 +27,10 @@ export type TelemetryEventTypeWithPayload = | { type: ObservabilityAIAssistantTelemetryEventType.UserSentPromptInChat; payload: Message & { scopes: AssistantScope[] }; + } + | { + type: ObservabilityAIAssistantTelemetryEventType.InsightResponse; + payload: InsightResponse; }; export const registerTelemetryEventTypes = (analytics: AnalyticsServiceSetup) => { diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/schemas/insight_response.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/schemas/insight_response.ts new file mode 100644 index 0000000000000..e46eabf7316c0 --- /dev/null +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/schemas/insight_response.ts @@ -0,0 +1,25 @@ +/* + * 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 { EventTypeOpts } from '@kbn/core/public'; +import { ObservabilityAIAssistantTelemetryEventType } from '../telemetry_event_type'; + +export interface InsightResponse { + '@timestamp': string; +} + +export const insightResponseEventSchema: EventTypeOpts = { + eventType: ObservabilityAIAssistantTelemetryEventType.InsightResponse, + schema: { + '@timestamp': { + type: 'text', + _meta: { + description: 'The timestamp of the last response from the LLM.', + }, + }, + }, +}; diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/telemetry_event_type.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/telemetry_event_type.ts index e15ae317a7730..17f9c1d53acde 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/telemetry_event_type.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/analytics/telemetry_event_type.ts @@ -9,4 +9,5 @@ export enum ObservabilityAIAssistantTelemetryEventType { ChatFeedback = 'observability_ai_assistant_chat_feedback', InsightFeedback = 'observability_ai_assistant_insight_feedback', UserSentPromptInChat = 'observability_ai_assistant_user_sent_prompt_in_chat', + InsightResponse = 'observability_ai_assistant_insight_response', } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/plugins/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index e5168470be8f1..680a92f559f0a 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -81,6 +81,17 @@ function ChatContent({ next(initialMessagesRef.current); }, [next]); + useEffect(() => { + if (state !== ChatState.Loading && lastAssistantResponse) { + chatService.sendAnalyticsEvent({ + type: ObservabilityAIAssistantTelemetryEventType.InsightResponse, + payload: { + '@timestamp': lastAssistantResponse['@timestamp'], + }, + }); + } + }, [state, lastAssistantResponse, chatService]); + return ( <>