Repository navigation
Expand file tree
/
Copy pathtelemetry-queries.sql
More file actions
211 lines (204 loc) · 10.8 KB
/
Copy pathtelemetry-queries.sql
File metadata and controls
211 lines (204 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
-- PostHog/HogQL examples for the thin OpenBot event producer; no database setup.
-- Replace the dates with verified rollout/reporting coverage before publishing.
-- Deduplicate stable properties.event_id in PostHog. distinct_id is transport
-- identity, not a person. Use known (deployment_id,user_id) scope for user metrics.
-- Unknown identity remains visible in A; no internal/external classification exists.
-- Production: environment='production', plus events sent before environment was
-- decided by the build (all 'unknown') whose openbot_version is not 'unknown'.
-- Events with no openbot_version at all predate it and are left out.
-- A. Received event copies, stable-ID duplicates, identity and freshness coverage.
SELECT event, properties.environment AS environment,
properties.deployment_id AS deployment_id,
count() AS received_copies,
count(DISTINCT properties.event_id) AS producer_events,
countIf(properties.event_id IS NULL OR properties.user_id IS NULL
OR properties.deployment_id IS NULL
OR properties.deployment_id='unknown') AS unknown_scope_copies,
max(timestamp) AS newest_received_utc
FROM events
WHERE event LIKE 'oss.runtime.openbot.%' AND properties.app_id='openbot'
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
AND timestamp < toDateTime('2026-11-04 00:00:00', 'UTC')
GROUP BY event,environment,deployment_id;
-- B. Accepted attempts and observed terminal outcomes. Missing is not failure.
WITH records AS (
SELECT properties.event_id AS event_id,any(event) AS name,
any(properties.deployment_id) AS deployment_id,
any(properties.user_id) AS user_id,any(properties.thread_id) AS thread_id,
any(properties.run_id) AS run_id,any(properties.trigger) AS trigger,
any(properties.outcome) AS outcome,
min(toDateTime(properties.occurred_at)) AS observed_utc
FROM events
WHERE event IN ('oss.runtime.openbot.run_accepted','oss.runtime.openbot.run_terminal')
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
GROUP BY event_id
)
SELECT a.trigger,t.outcome,count() AS accepted_attempts,
countIf(t.run_id IS NULL) AS missing_terminal,
countIf(t.run_id IS NULL AND a.observed_utc < now()-INTERVAL 30 MINUTE) AS missing_after_window
FROM records a LEFT JOIN records t
ON a.deployment_id=t.deployment_id AND a.user_id=t.user_id
AND a.thread_id=t.thread_id AND a.run_id=t.run_id
AND t.name='oss.runtime.openbot.run_terminal'
WHERE a.name='oss.runtime.openbot.run_accepted'
GROUP BY a.trigger,t.outcome;
-- Failed-run rate uses observed error/(success+error+cancelled+timeout).
-- Report unknown and missing separately. Child outcomes do not determine roots.
-- C. First observed ordinary human root success, computed from received events.
-- Use the entire verified collection period, not a rolling activity window.
WITH successes AS (
SELECT properties.event_id AS event_id,
any(properties.deployment_id) AS deployment_id,
any(properties.user_id) AS user_id,
min(toDateTime(properties.occurred_at)) AS observed_utc
FROM events
WHERE event='oss.runtime.openbot.run_terminal'
AND properties.trigger='human' AND properties.purpose='ordinary'
AND properties.is_root=true AND properties.outcome='success'
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
AND properties.deployment_id IS NOT NULL AND properties.deployment_id!='unknown'
AND properties.user_id IS NOT NULL
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
GROUP BY event_id
)
SELECT deployment_id,user_id,min(observed_utc) AS first_observed_success_utc
FROM successes GROUP BY deployment_id,user_id;
-- This is not historical/global first use. Desktop setup is a separate funnel.
-- Human return requires another ordinary human root; automation-only activity
-- and consuming a routine result are separate from initiating new work.
-- D. Capability stages/outcomes after producer-ID deduplication.
WITH capability AS (
SELECT properties.event_id AS event_id,
any(properties.capability) AS capability,any(properties.stage) AS stage,
any(properties.outcome) AS outcome,any(properties.source_event) AS source_event
FROM events
WHERE event='oss.runtime.openbot.capability'
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
AND timestamp < toDateTime('2026-11-04 00:00:00', 'UTC')
GROUP BY event_id
)
SELECT capability,stage,outcome,source_event,count() AS observed_operations
FROM capability GROUP BY capability,stage,outcome,source_event;
-- Setup, successful use, failures and interventions remain separate operations.
-- E. Join observed views/copies to terminal result_message_ids even when the
-- browser does not know run_id. LEFT JOIN retains unmatched consumption.
-- JSONExtractArrayRaw/arrayJoin follows PostHog's documented array-property form.
WITH terminals AS (
SELECT properties.event_id AS event_id,
any(properties.deployment_id) AS deployment_id,
any(properties.user_id) AS user_id,any(properties.thread_id) AS thread_id,
any(properties.run_id) AS run_id,any(properties.outcome) AS outcome,
any(properties.result_message_ids) AS result_message_ids
FROM events
WHERE event='oss.runtime.openbot.run_terminal'
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
GROUP BY event_id
), result_messages AS (
SELECT deployment_id,user_id,thread_id,run_id,outcome,
JSONExtractString(arrayJoin(JSONExtractArrayRaw(result_message_ids ?? '[]'))) AS message_id
FROM terminals
), consumption AS (
SELECT properties.event_id AS event_id,any(event) AS action,
any(properties.deployment_id) AS deployment_id,
any(properties.user_id) AS user_id,any(properties.thread_id) AS thread_id,
any(properties.message_id) AS message_id,
any(properties.consumption_surface) AS surface,
min(toDateTime(properties.occurred_at)) AS observed_utc
FROM events
WHERE event IN ('oss.runtime.openbot.result_viewed','oss.runtime.openbot.result_copied')
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
AND timestamp >= toDateTime('2026-11-03 00:00:00', 'UTC')
GROUP BY event_id
)
SELECT c.event_id,c.deployment_id,c.user_id,c.thread_id,c.message_id,
c.action,c.surface,c.observed_utc,t.run_id,t.outcome,
t.run_id IS NULL AS missing_execution_join
FROM consumption c LEFT JOIN result_messages t
ON c.deployment_id=t.deployment_id AND c.user_id=t.user_id
AND c.thread_id=t.thread_id AND c.message_id=t.message_id;
-- No matching execution is unknown coverage, not evidence of success/failure.
-- No view/copy is unobserved consumption, not dissatisfaction. Notification
-- open and usefulness have no event here; do not infer them from delivery.
-- F. Nudges (the ask to star OpenBot on GitHub, and any later one): people shown,
-- following and dismissing, per nudge, place and the win that made it due. Each
-- event_id is one person, nudge, action and place, so counts are people. Clicked
-- is following the nudge (for the star nudge, opening the repository), not a
-- GitHub star; GitHub's own count is the outcome. 'settings' has no shown event.
SELECT properties.nudge_id AS nudge,
properties.nudge_place AS place,
properties.nudge_moment AS moment,
count(DISTINCT if(event='oss.runtime.openbot.nudge_shown',
properties.event_id, NULL)) AS people_shown,
count(DISTINCT if(event='oss.runtime.openbot.nudge_clicked',
properties.event_id, NULL)) AS people_clicked,
count(DISTINCT if(event='oss.runtime.openbot.nudge_dismissed',
properties.event_id, NULL)) AS people_dismissed
FROM events
WHERE event IN ('oss.runtime.openbot.nudge_shown',
'oss.runtime.openbot.nudge_clicked',
'oss.runtime.openbot.nudge_dismissed')
AND properties.app_id='openbot'
AND (properties.environment='production'
OR (properties.environment='unknown'
AND coalesce(properties.openbot_version,'unknown')!='unknown'))
AND properties.event_id IS NOT NULL
GROUP BY nudge, place, moment;
-- G. OpenBot Desktop installations linked to OpenBot Cloud people
-- (desktop_installation_linked; docs/TELEMETRY.md). Each event_id is one
-- person and installation, so distinct event_ids are links, however often
-- and by whichever sign-in (the window's page, Move to Cloud) they were
-- reported. Desktop's own events carry the installation id as their deployment_id;
-- the person's OpenBot Cloud events carry the link's deployment_id and user_id.
-- A join, not a merge: no PostHog person is aliased.
-- One row per link: the keys to the person's OpenBot Cloud events
-- (cloud_deployment_id, cloud_user_id) and the installation's Desktop events
-- as delivered, before and after the link. Join the Cloud events on those keys
-- for what the person did in OpenBot Cloud. No link exists before the server
-- change is deployed: set the links' start to that date, and the Desktop
-- events' start as far back as the question needs.
WITH links AS (
SELECT properties.event_id AS link_id,
any(properties.installation_id) AS installation_id,
any(properties.deployment_id) AS cloud_deployment_id,
any(properties.user_id) AS cloud_user_id,
min(timestamp) AS linked_at
FROM events
WHERE event='oss.runtime.openbot.desktop_installation_linked'
AND timestamp >= toDateTime('2026-12-04 00:00:00', 'UTC')
AND properties.app_id='openbot'
AND properties.environment='production'
AND properties.event_id IS NOT NULL
GROUP BY link_id
),
desktop AS (
SELECT properties.deployment_id AS installation_id,
min(timestamp) AS first_desktop_event,
count() AS desktop_events
FROM events
WHERE event LIKE 'oss.desktop.%'
AND timestamp >= toDateTime('2026-11-01 00:00:00', 'UTC')
AND properties.deployment_id IN (SELECT installation_id FROM links)
GROUP BY installation_id
)
SELECT l.installation_id, l.cloud_deployment_id, l.cloud_user_id, l.linked_at,
d.first_desktop_event, d.desktop_events
FROM links l
LEFT JOIN desktop d ON d.installation_id=l.installation_id;