Telemetry event instrumentation
Telemetry event instrumentation gives Insights a small, stable view of product use. It records product milestones, user activity, source outcomes, query failures, and site shape for product decisions while keeping customer data out of the event stream. The event catalogue in docs/telemetry.md is the contract shared by the client, the server, and Pulse. The parent page, Telemetry and product analytics, gives the wider product context.
Event model
Event definitions
Each event has a past-tense name and a flat set of low-cardinality properties. The catalogue defines when the event fires, which workflow owns it, and which values may leave the site. This keeps reports stable when a screen, error message, or internal data shape changes.
The main event groups are:
| Group | Purpose | Examples |
|---|---|---|
| Product milestones | Show how sites move through analytical work | workbook_created, query_created, chart_created, dashboard_created |
| Activity | Show use by authors, viewers, and shared readers | workbook_opened, dashboard_viewed, workbook_template_used |
| Sharing | Show when access expands | share_granted |
| Source and store outcomes | Show source adoption and import health | data_source_created, data_source_tested, data_store_imported |
| Query failures | Show the kind of run failure and where it occurred | query_failed |
| Site scan | Describe site shape and data-store fit | site_profile, site_queries, site_tables |
The event name identifies the business fact. A property carries a controlled variation such as an interface, surface, source type, outcome, or bucket. Names of user records, SQL, table columns, titles, email addresses, and record IDs are not event properties.
References: docs/telemetry.md• L28-40 docs/telemetry.md• L50-93
Event context
Every event carries the app version and an entry cohort. The cohort describes how the site came to run Insights: an ERPNext site or an Insights site without ERPNext. Pulse supplies site, user, team, and time context.
The browser gets the same two values from site information as the server derives for the site. This lets reports compare client and server events without treating the two paths as different products.
References: insights/telemetry.py• L20-32 insights/telemetry.py• L92-98 frontend/…/session.ts• L18-35 frontend/…/telemetry.ts• L5-16
Client instrumentation
Client event capture
The Vue client exposes one small capture wrapper around the framework telemetry plug-in. It adds the common event context before sending the event, so feature code only supplies the event name and workflow-specific properties.
The plug-in is enabled after a logged-in session is known. Client instrumentation is used for immediate interface signals such as creating a chart or dashboard and adding charts to a dashboard. Server calls remain responsible for milestones and outcomes that must also cover API, import, shared-link, or guest flows.
The client therefore reports intent or visible assembly actions, while the server records durable facts. This split prevents a browser-only event from being mistaken for a completed server operation.
References: frontend/…/main.ts• L25-29 frontend/…/telemetry.ts• L7-16 frontend/…/workbook.ts• L39-41 frontend/…/workbook.ts• L105-124 frontend/…/workbook.ts• L146-157 frontend/…/dashboard.ts• L107-109 frontend/…/dashboard.ts• L161-175
Server instrumentation
Server event capture
The server is the source of truth for events tied to saved documents, access changes, requests, and job results. Its capture helper adds the common context and sends through the Frappe telemetry client. A telemetry error is suppressed so collection cannot fail the user action it reports.
Backend instrumentation sits at domain boundaries:
- Workbook insertion records creation. Workbook and dashboard view methods record daily activity.
- Sharing APIs and document controllers record newly granted user, organization, team, or public access.
- Data-source creation, connection tests, and data-store import completion record source outcomes.
- Query execution records a failure once at the common execution boundary.
References: insights/telemetry.py• L24-38 insights/…/insights_workbook.py• L69-75 insights/…/insights_workbook.py• L238-258 insights/…/insights_dashboard_v3.py• L85-103
Activity events
Activity events measure use without turning every page load into a new row. Opening a workbook or viewing a dashboard passes interval="1d", which limits the event to one row per user per day. The view methods also update the local View Log only when the same user has not viewed the same resource in the last five minutes.
Public dashboard guests use the shared Guest identity. Their daily event is therefore site-level, while the site scan counts five-minute public view windows as a lower bound on public views. The activity signal covers both named users and anonymous public reading without exposing the public reader's identity.
References: insights/…/insights_workbook.py• L239-258 insights/…/insights_dashboard_v3.py• L86-103 insights/telemetry_scan.py• L227-259 docs/telemetry.md• L69-77
Sharing events
Sharing telemetry records a change in access, not the people or resource names involved. The event groups the resource kind with the grant target and a count. Workbook and dashboard sharing count only newly added users or newly created organization/public grants. Team changes count new resource grants, and a public chart records its first public transition.
This makes repeated saves quiet and keeps the event useful for adoption reports. Revocations are defined as a future event rather than being mixed into share_granted.
References: insights/telemetry.py• L35-38 insights/…/workbooks.py• L242-247 insights/…/insights_dashboard_v3.py• L471-477 insights/…/insights_team.py• L72-84 insights/…/insights_chart_v3.py• L105-115 docs/telemetry.md• L60-67 docs/telemetry.md• L116-117
Source outcome events
Source instrumentation follows the source lifecycle. Saving a non-site source records its type and whether SSL is enabled. A connection test records whether the source answered and, on failure, a closed error kind. An import records its outcome, whether it reached the row limit, row and duration buckets, and whether it resumed from a bookmark.
The source path never sends credentials, host names, account names, table names, or SQL. The buckets support size and speed reports without allowing one event to identify a customer dataset.
References: insights/…/insights_data_source_v3.py• L89-92 insights/…/insights_data_source_v3.py• L437-454 insights/…/data_warehouse.py• L753-769 insights/telemetry.py• L40-59
Query failure events
Query failure telemetry is attached to the common execute boundary. All query surfaces use that boundary, so builder, SQL, script, and chart-generated runs report a failure through the same path and report it once when execution raises.
The server maps exception classes to a closed error_kind set: permission, timeout, connection, refused, syntax, unknown_column, or other. It also records the query interface, whether the data store was used, the source type when one source can be identified, and the request caller. The caller is classified as session, token, guest, or job from request and session state. The event does not send the error message, SQL, table names, or column names. This protects data while keeping failures comparable across translated or reworded messages.
Busy-server and cancelled runs are excluded because the client retries them or the reader stopped the run. Other capture errors are suppressed so failure reporting cannot change query behavior.
References: insights/…/insights_query_v3.py• L264-304 insights/telemetry.py• L100-145 docs/telemetry.md• L57
Site activity scanning
Scan schedule
The site scan is a daily scheduler action that describes the site as a whole. It sends three separate events: site_profile for identity, age, footprint, and people; site_queries for query styles and operation shapes; and site_tables for queried standard tables and data-store fit.
The scan starts only when Pulse telemetry is enabled. It builds each event independently, so one failed event does not prevent the other two from being sent. The scheduler provides the daily gate instead of an event interval because an early scheduler tick could otherwise cause Pulse to drop that day's event.
References: insights/telemetry_scan.py• L76-99 docs/telemetry.md• L79-93
Query and table summaries
The scan reduces stored query definitions to counts and known categories. It counts builder, SQL, and script queries, data-store use, operation kinds, filter variants, joins, aggregations, and known expression functions. Unknown values become other or are omitted from name lists.
For table use, the scan follows query references to the tables that queries actually read. It names only standard doctypes from Frappe-published apps. Custom tables and third-party app tables contribute to counts but do not leave the site by name. A chart is classified as fitting, unknown, or not connected to a table based on available catalog estimates and store settings.
References: insights/telemetry_scan.py• L262-357 insights/telemetry_scan.py• L359-378 insights/telemetry_scan.py• L392-449 insights/telemetry.py• L66-90
Row estimate collection
The table-fit part of the scan uses row estimates already maintained by supported source catalogs. It asks only for tables that queries read, stores the estimate with the table metadata, and skips a source that does not answer. A missing estimate produces an unknown fit rather than a false over-limit result.
This work belongs to the scan and not to query execution or import. A site with telemetry disabled is not asked to read source catalogs because the work would add customer-side load for an event that Pulse would discard.
References: insights/telemetry_scan.py• L509-536 insights/telemetry_scan.py• L539-561 insights/telemetry_scan.py• L618-627 insights/telemetry_scan.py• L76-87
Collection safeguards
Data minimization
Telemetry uses controlled names, enums, booleans, counts, and buckets. Lists have a small fixed limit. Standard app and doctype names may be reported only when the Frappe publisher rules identify them as standard; other names are counted without being named.
The three scan events are each kept below Pulse's 4096-byte property limit. The scan first limits lists and then removes list items until the common event context and event properties fit. This protects the transport contract even when a site has many tables, operations, or expression functions.
References: docs/telemetry.md• L28-40 insights/telemetry_scan.py• L29-31 insights/telemetry_scan.py• L101-122 insights/telemetry.py• L66-90
Failure isolation
Telemetry is best-effort. The general server sender suppresses capture errors, query failure capture suppresses its own telemetry errors, and the scan logs a failed event while continuing with the remaining scan events. Product actions and scheduled work therefore do not depend on Pulse availability.
The safeguards have different scopes. Capture failure protects the user action, event-size control protects the Pulse property limit, and source-scan gating protects a site from catalog work when collection is off.
References: insights/telemetry.py• L24-33 insights/…/insights_query_v3.py• L277-285 insights/telemetry_scan.py• L95-99 insights/telemetry_scan.py• L101-122
Collection flow
The following flow shows how a product action becomes a bounded event or stops without affecting the action.
flowchart LR
A[Product action] --> B{Client or server boundary}
B -->|Client signal| C[Telemetry wrapper]
B -->|Saved fact or outcome| D[Server capture]
C --> E[Common event context]
D --> E
E --> F{Collection enabled and safe}
F -->|Yes| G[Pulse event]
F -->|No or capture error| H[Product action continues]
I[Daily scheduler] --> J[Site scan]
J --> K[Three bounded scan events]
K --> F
The client and server paths meet at the same event contract, while the scheduler supplies the separate site-wide scan path. No path sends raw query or source content.
Change checklist
When these files or sections are changed, remember to consider these:
- Update docs/telemetry.md in the same change as a new event or property. Keep the event name, firing boundary, and allowed value set aligned.
- Keep
app_versionandentryconsistent between frontend/…/telemetry.ts and insights/telemetry.py so client and server reports remain comparable. - When a workflow gains a new completion path, place its milestone or outcome at the server boundary rather than adding a browser-only duplicate.
- When a share path changes, preserve the distinction between a new grant and a repeated save. Keep resource and target values within the closed event vocabulary.
- When query exception classes change, update
error_kindmapping and its closed list together. Do not use exception text as the event value. - When authentication paths change, keep
callerlimited to the documented request and job categories. Do not derive it from an unverified header. - When scan lists or event properties grow, recheck the shared event context, list limit, and 4096-byte cap. Keep telemetry-off scans free of source catalog reads.
- When source or table naming rules change, verify that standard names remain allowed and custom names remain count-only.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Pulse capture raises an exception | The product action could fail if telemetry is allowed to escape | The server capture helper suppresses telemetry exceptions |
| A query failure is captured from a message instead of its exception class | Translation or wording changes move the same failure between report categories | error_kind maps exception classes to a closed list |
| A source connection fails during a site scan | A scan can report the source as too large even though its catalog did not answer | The scan skips the source and classifies affected charts as unknown |
| A site has telemetry disabled | Catalog reads add load even though Pulse will drop the event | run_site_scan exits before building any scan event |
| A sharing update is saved more than once | Reports overcount access grants | Sharing code compares new access with existing access before capture |
| Scan lists exceed the Pulse property limit | Pulse drops or rejects an oversized event | Lists are capped and trimmed below 4096 bytes |
| A query reads several source types | The event claims a source type that is not unique | source_type reports unknown unless one source can be identified |
Key files
| File | Why to read it |
|---|---|
| docs/telemetry.md | The event names, properties, privacy rules, daily behavior, and scan contract |
| insights/telemetry.py | Shared server capture, site cohort, value buckets, standard-name rules, caller classification, and failure categories |
| frontend/…/telemetry.ts | Client capture wrapper and common event context |
| frontend/…/main.ts | Client telemetry plug-in activation after login |
| insights/…/insights_workbook.py | Workbook creation and activity instrumentation |
| insights/…/insights_dashboard_v3.py | Dashboard activity and sharing instrumentation |
| insights/…/insights_query_v3.py | Common query execution boundary and failure reporting |
| insights/…/insights_data_source_v3.py | Source creation and connection-test outcomes |
| insights/…/data_warehouse.py | Data-store import outcome reporting |
| insights/telemetry_scan.py | Daily site scan, table-fit summaries, size limits, and catalog safeguards |