Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(logs): track sql tab opens, query runs, and saves (#57669)

Jon McCallum7ba1d6ae3d7f
diff --git a/products/logs/frontend/LogsScene.tsx b/products/logs/frontend/LogsScene.tsx
index 85b5b2850f87..3ab5d65ef4e2 100644
--- a/products/logs/frontend/LogsScene.tsx
+++ b/products/logs/frontend/LogsScene.tsx
@@ -127,7 +127,12 @@ const LogsSceneTabbedContent = (): JSX.Element => {
)}
<LemonTabs<LogsSceneActiveTab>
activeKey={activeTab}
- onChange={(key) => setActiveTab(key)}
+ onChange={(key) => {
+ if (key === 'sql' && activeTab !== 'sql') {
+ posthog.capture('logs sql tab opened')
+ }
+ setActiveTab(key)
+ }}
tabs={tabs}
sceneInset
/>
diff --git a/products/logs/frontend/components/LogsSqlEditor/LogsSqlEditor.tsx b/products/logs/frontend/components/LogsSqlEditor/LogsSqlEditor.tsx
index 0b25e77371b0..1932310e7a00 100644
--- a/products/logs/frontend/components/LogsSqlEditor/LogsSqlEditor.tsx
+++ b/products/logs/frontend/components/LogsSqlEditor/LogsSqlEditor.tsx
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions, useMountedLogic, useValues } from 'kea'
import { useEffect } from 'react'
import { SQLEditor } from 'scenes/data-warehouse/editor/SQLEditor'
@@ -8,7 +8,9 @@ import { SQLEditorMode } from 'scenes/data-warehouse/editor/sqlEditorModes'
import { NodeKind } from '~/queries/schema/schema-general'
import { ChartDisplayType } from '~/types'
-import { logsSceneLogic } from 'products/logs/frontend/logsSceneLogic'
+import { getLogsSqlEditorTabId, logsSceneLogic } from 'products/logs/frontend/logsSceneLogic'
+
+import { logsSqlEditorTrackingLogic } from './logsSqlEditorTrackingLogic'
const DEFAULT_LOGS_QUERY = 'SELECT * FROM logs LIMIT 10'
@@ -17,11 +19,12 @@ export interface LogsSqlEditorProps {
}
export const LogsSqlEditor = ({ id }: LogsSqlEditorProps): JSX.Element => {
- const sqlEditorTabId = `logs-sql-editor-${id}`
+ const sqlEditorTabId = getLogsSqlEditorTabId(id)
const { keepSqlEditorMounted } = useActions(logsSceneLogic)
const logic = sqlEditorLogic({ tabId: sqlEditorTabId, mode: SQLEditorMode.Embedded })
const { queryInput } = useValues(logic)
const { setQueryInput, setSourceQuery, runQuery } = useActions(logic)
+ useMountedLogic(logsSqlEditorTrackingLogic({ sqlEditorTabId }))
useEffect(() => {
keepSqlEditorMounted(sqlEditorTabId)
diff --git a/products/logs/frontend/components/LogsSqlEditor/logsSqlEditorTrackingLogic.ts b/products/logs/frontend/components/LogsSqlEditor/logsSqlEditorTrackingLogic.ts
new file mode 100644
index 000000000000..212a3861ec17
--- /dev/null
+++ b/products/logs/frontend/components/LogsSqlEditor/logsSqlEditorTrackingLogic.ts
@@ -0,0 +1,48 @@
+import { connect, kea, key, listeners, path, props } from 'kea'
+import posthog from 'posthog-js'
+
+import { SaveAsMenuItem } from 'scenes/data-warehouse/editor/editorSceneLogic'
+import { sqlEditorLogic } from 'scenes/data-warehouse/editor/sqlEditorLogic'
+import { SQLEditorMode } from 'scenes/data-warehouse/editor/sqlEditorModes'
+
+import type { logsSqlEditorTrackingLogicType } from './logsSqlEditorTrackingLogicType'
+
+export interface LogsSqlEditorTrackingLogicProps {
+ sqlEditorTabId: string
+}
+
+const captureSaved = (target: SaveAsMenuItem['action']): void => {
+ posthog.capture('logs sql query saved', { target })
+}
+
+export const logsSqlEditorTrackingLogic = kea<logsSqlEditorTrackingLogicType>([
+ path(['products', 'logs', 'frontend', 'components', 'LogsSqlEditor', 'logsSqlEditorTrackingLogic']),
+ props({} as LogsSqlEditorTrackingLogicProps),
+ key((props) => props.sqlEditorTabId),
+ connect((props: LogsSqlEditorTrackingLogicProps) => ({
+ actions: [
+ sqlEditorLogic({ tabId: props.sqlEditorTabId, mode: SQLEditorMode.Embedded }),
+ [
+ 'runQuery as sqlEditorRunQuery',
+ 'saveAsViewSubmit as sqlEditorSaveAsViewSubmit',
+ 'saveAsInsightSubmit as sqlEditorSaveAsInsightSubmit',
+ 'saveAsEndpointSubmit as sqlEditorSaveAsEndpointSubmit',
+ ],
+ ],
+ })),
+ listeners(({ cache }) => ({
+ sqlEditorRunQuery: () => {
+ // Skip the auto-init runQuery dispatched by LogsSqlEditor's first mount.
+ // Trade-off: on revisit (queryInput already set, no auto-init), the user's first
+ // manual run is also skipped. Acceptable under-count for an alpha metric.
+ if (!cache.firstRunSeen) {
+ cache.firstRunSeen = true
+ return
+ }
+ posthog.capture('logs sql query run')
+ },
+ sqlEditorSaveAsViewSubmit: () => captureSaved('view'),
+ sqlEditorSaveAsInsightSubmit: () => captureSaved('insight'),
+ sqlEditorSaveAsEndpointSubmit: () => captureSaved('endpoint'),
+ })),
+])
diff --git a/products/logs/frontend/logsSceneLogic.tsx b/products/logs/frontend/logsSceneLogic.tsx
index 52adcc80142b..0acb09781a7b 100644
--- a/products/logs/frontend/logsSceneLogic.tsx
+++ b/products/logs/frontend/logsSceneLogic.tsx
@@ -35,6 +35,8 @@ import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/lo
import type { logsSceneLogicType } from './logsSceneLogicType'
+export const getLogsSqlEditorTabId = (id: string): string => `logs-sql-editor-${id}`
+
export type LogsSceneActiveTab = 'viewer' | 'services' | 'alerts' | 'sql' | 'configuration'
const VALID_ACTIVE_TABS: LogsSceneActiveTab[] = ['viewer', 'services', 'alerts', 'sql', 'configuration']
export const DEFAULT_ACTIVE_TAB: LogsSceneActiveTab = 'viewer'