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(notebooks): add telemetry for markdown notebook architecture (#67562)

Anna Szellaa24f47c795d
diff --git a/frontend/src/models/notebooksModel.ts b/frontend/src/models/notebooksModel.ts
index a1aaa411923e..27cb73828bc7 100644
--- a/frontend/src/models/notebooksModel.ts
+++ b/frontend/src/models/notebooksModel.ts
@@ -128,6 +128,7 @@ export const notebooksModel = kea<notebooksModelType>([
posthog.capture(`notebook created`, {
short_id: notebook.short_id,
+ is_markdown: useMarkdownNotebook,
})
void addProductIntent({
diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
index c5856658fd76..0be51dc285b5 100644
--- a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
@@ -119,7 +119,7 @@ export function Notebook({
const isContentWidthExpanded = isMarkdownNotebook ? isMarkdownExpanded : isExpanded
const canUpgradeToMarkdownNotebooks = !!featureFlags[FEATURE_FLAGS.MARKDOWN_NOTEBOOKS]
const upgradeToMarkdownNotebook = (): void => {
- openUpgradeToMarkdownNotebookDialog({ content, comments, setLocalContent })
+ openUpgradeToMarkdownNotebookDialog({ shortId, content, comments, setLocalContent })
}
return (
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts b/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
index 57fd1fcdf2cd..170fabc05e23 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
+++ b/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
@@ -660,6 +660,11 @@ export const notebookLogic = kea<notebookLogicType>([
)
actions.ackLocalSteps(stepsJson, String(sendable.clientID))
refreshTreeItem('notebook', String(values.notebook.short_id))
+ posthog.capture('notebook saved', {
+ short_id: values.notebook.short_id,
+ save_path: 'tiptap_collab',
+ is_markdown: false,
+ })
return response
} catch (error: any) {
if (error.status === 409 && error.data?.steps) {
@@ -693,6 +698,12 @@ export const notebookLogic = kea<notebookLogicType>([
})
return values.notebook
}
+ posthog.capture('notebook save failed', {
+ short_id: values.notebook.short_id,
+ save_path: 'tiptap_collab',
+ is_markdown: false,
+ status: error.status,
+ })
throw error
}
}
@@ -727,6 +738,11 @@ export const notebookLogic = kea<notebookLogicType>([
: undefined,
})
refreshTreeItem('notebook', String(values.notebook.short_id))
+ posthog.capture('notebook saved', {
+ short_id: values.notebook.short_id,
+ save_path: 'markdown_realtime',
+ is_markdown: true,
+ })
return response
} catch (error: any) {
if (error.status === 409 && error.data?.updates) {
@@ -738,6 +754,10 @@ export const notebookLogic = kea<notebookLogicType>([
diff: TextChange[]
base_crc?: number | null
}[]
+ posthog.capture('notebook markdown save conflict retried', {
+ short_id: values.notebook.short_id,
+ missed_updates: updates.length,
+ })
let serverMarkdown: string | null = baseMarkdown
for (const update of updates) {
if (
@@ -755,6 +775,10 @@ export const notebookLogic = kea<notebookLogicType>([
if (serverMarkdown === null) {
// Replay didn't fit our baseline — reload; the editor merges
// local edits over the fresh server state via remoteValue.
+ posthog.capture('notebook markdown full reload', {
+ short_id: values.notebook.short_id,
+ reason: 'save_replay_failed',
+ })
actions.loadNotebook()
return values.notebook
}
@@ -779,9 +803,19 @@ export const notebookLogic = kea<notebookLogicType>([
if (error.status === 410) {
// Missed range not replayable (trimmed / mixed writers): full reload,
// the editor merges local edits over the fresh server state.
+ posthog.capture('notebook markdown full reload', {
+ short_id: values.notebook.short_id,
+ reason: 'stream_trimmed',
+ })
actions.loadNotebook()
return values.notebook
}
+ posthog.capture('notebook save failed', {
+ short_id: values.notebook.short_id,
+ save_path: 'markdown_realtime',
+ is_markdown: true,
+ status: error.status,
+ })
throw error
}
}
@@ -810,6 +844,11 @@ export const notebookLogic = kea<notebookLogicType>([
}
refreshTreeItem('notebook', String(values.notebook.short_id))
+ posthog.capture('notebook saved', {
+ short_id: values.notebook.short_id,
+ save_path: 'legacy_patch',
+ is_markdown: isMarkdownNotebookContent(notebookContent),
+ })
return response
} catch (error: any) {
if (error.code === 'conflict') {
@@ -841,6 +880,12 @@ export const notebookLogic = kea<notebookLogicType>([
actions.showConflictWarning()
return null
}
+ posthog.capture('notebook save failed', {
+ short_id: values.notebook.short_id,
+ save_path: 'legacy_patch',
+ is_markdown: isMarkdownNotebookContent(notebookContent),
+ status: error.status,
+ })
throw error
}
},
@@ -1465,6 +1510,16 @@ export const notebookLogic = kea<notebookLogicType>([
}
}
// Version gap, diff-less ping, or a diff that doesn't fit our base: full reload.
+ if (isMarkdownNotebookContent(notebook.content)) {
+ posthog.capture('notebook markdown full reload', {
+ short_id: notebook.short_id,
+ reason: !event.diff
+ ? 'missing_diff'
+ : event.version !== notebook.version + 1
+ ? 'version_gap'
+ : 'diff_mismatch',
+ })
+ }
actions.loadNotebook()
},
processPendingMarkdownStreamEvents: () => {
@@ -1491,7 +1546,13 @@ export const notebookLogic = kea<notebookLogicType>([
toastId: `notebook-merge-conflict-${values.shortId}`,
button: {
label: 'Review',
- action: () => actions.showMarkdownMergeConflictDetails(conflicts),
+ action: () => {
+ posthog.capture('notebook markdown merge conflict reviewed', {
+ short_id: values.notebook?.short_id,
+ conflict_count: conflicts.length,
+ })
+ actions.showMarkdownMergeConflictDetails(conflicts)
+ },
},
}
)
@@ -1760,6 +1821,7 @@ export const notebookLogic = kea<notebookLogicType>([
if (!skipCapture) {
posthog.capture('notebook content changed', {
short_id: values.notebook?.short_id,
+ is_markdown: isMarkdownNotebookContent(values.content),
})
}
@@ -1870,6 +1932,10 @@ export const notebookLogic = kea<notebookLogicType>([
},
discardLocalChanges: () => {
+ posthog.capture('notebook collab conflict resolved', {
+ short_id: values.notebook?.short_id,
+ choice: 'discard',
+ })
// Reload remounts the editor so it re-initialises with the server's content.
actions.clearLocalContent()
window.location.reload()
@@ -1906,6 +1972,10 @@ export const notebookLogic = kea<notebookLogicType>([
title: newTitle,
})
lemonToast.success('Saved your unsaved changes to a new notebook.')
+ posthog.capture('notebook collab conflict resolved', {
+ short_id: values.notebook.short_id,
+ choice: 'copy_to_new',
+ })
actions.dismissCollabConflict()
actions.clearLocalContent()
await openNotebook(created.short_id, NotebookTarget.Scene)
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.tsx b/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.tsx
index 1712c26ecfc2..1b9eeaf6a30a 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/notebookUpgradeDialog.tsx
@@ -1,3 +1,7 @@
+import posthog from 'posthog-js'
+
+import { lemonToast } from '@posthog/lemon-ui'
+
import { NotebookPropValue } from 'lib/components/MarkdownNotebook/types'
import { JSONContent } from 'lib/components/RichContentEditor/types'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
@@ -12,6 +16,7 @@ import {
} from './markdownNotebookV2'
type OpenUpgradeToMarkdownNotebookDialogProps = {
+ shortId?: string
content: JSONContent | null | undefined
/** The notebook's discussion comments — inline threads are embedded into the markdown. */
comments?: CommentType[] | null
@@ -73,6 +78,7 @@ function getMentionLabel(memberId: number): string | null {
}
export function openUpgradeToMarkdownNotebookDialog({
+ shortId,
content,
comments,
setLocalContent,
@@ -96,15 +102,26 @@ export function openUpgradeToMarkdownNotebookDialog({
primaryButton: {
children: 'Convert to Markdown notebooks',
type: 'primary',
- onClick: () =>
- setLocalContent(
- buildMarkdownNotebookContent(
- convertNotebookContentToMarkdown(content, {
- commentRepliesByMarkId: buildCommentRepliesByMarkId(comments),
- getMentionLabel,
- })
- )
- ),
+ onClick: () => {
+ const startedAt = performance.now()
+ try {
+ const markdown = convertNotebookContentToMarkdown(content, {
+ commentRepliesByMarkId: buildCommentRepliesByMarkId(comments),
+ getMentionLabel,
+ })
+ setLocalContent(buildMarkdownNotebookContent(markdown))
+ posthog.capture('notebook converted to markdown', {
+ short_id: shortId,
+ source_node_count: content?.content?.length ?? 0,
+ markdown_length: markdown.length,
+ duration_ms: Math.round(performance.now() - startedAt),
+ })
+ } catch (error) {
+ posthog.capture('notebook markdown conversion failed', { short_id: shortId })
+ posthog.captureException(error as Error, { action: 'notebook markdown conversion' })
+ lemonToast.error('Could not convert this notebook to Markdown notebooks.')
+ }
+ },
size: 'small',
},
secondaryButton: {