✨ Send telemetry for WebGL renderer failures (#12987)

* ✨ Send telemetry for WebGL renderer failures

WebGL renderer failures left no trace in the audit log, so we could not
tell why people switch WebGL off.

- Send webgl-unavailable when the "WebGL is not available" modal shows,
  with the init error.
- Send webgl-context-lost, webgl-context-restored and webgl-reload-failed
  from the WASM renderer.
- Add the active renderer (wasm or svg) to handled-exception,
  unhandled-exception, exception-page and open-workspace-file.
- Add environment details to the WebGL events and to
  enable/disable-webgl-rendering: normalized GPU family and backend, max
  texture size, device memory, CPU cores and whether the app runs inside
  Electron. The full GPU renderer string is not sent, as it can help
  fingerprint a device.

Closes #12984

AI-assisted-by: claude-opus-5-5

* ⚡ Avoid throwaway WebGL contexts in renderer telemetry

WebGL events no longer create a context to read GPU details; the
settings, menu and unavailable modal create one at most once.

AI-assisted-by: claude-opus-5-5

* 🐛 Refresh remembered GPU details on each renderer init

A restored context can run on another GPU, so read it on every init
instead of only the first one.

AI-assisted-by: claude-opus-5-5

* ⚡ Never create a WebGL context for renderer telemetry

WebGL events send GPU details only when the renderer has already read
them on init, instead of probing a throwaway context.

AI-assisted-by: claude-opus-5-5

---------

Co-authored-by: Elena Torro <elenatorro@gmail.com>
This commit is contained in:
andrés gonzález 2026-11-13 11:59:12 +01:00 committed by GitHub
parent 976f016481
commit 097ff41e03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 139 additions and 11 deletions

View File

@ -314,7 +314,8 @@
::ev/name "open-workspace-file"
::ev/origin "workspace"
:file-id file-id
:team-id team-id)))))))
:team-id team-id
:renderer (features/get-active-renderer state))))))))
(defn- restore-pending-changes
"Applies the edits still waiting to be saved to a freshly loaded `file`.

View File

@ -16,6 +16,7 @@
[app.main.data.nitrate :as dnt]
[app.main.data.notifications :as ntf]
[app.main.data.workspace :as-alias dw]
[app.main.features :as features]
[app.main.repo :as rp]
[app.main.router :as rt]
[app.main.store :as st]
@ -410,7 +411,8 @@
:hint hint
:href (rt/get-current-href)
:report report
:occurrences occurrences})))
:occurrences occurrences
:renderer (features/get-active-renderer @st/state)})))
(defn submit-report
"Report the error report to the audit log subsystem, subject to the

View File

@ -85,6 +85,13 @@
"feature not supported")
(contains? (:features state) feature))
(defn get-active-renderer
"Name of the renderer active in `state`, for telemetry: `wasm` (WebGL) or
`svg`, or nil before the features are initialized."
[state]
(when (contains? state :features)
(if (active-feature? state "render-wasm/v1") "wasm" "svg")))
(defn active-features?
"Given a state and a set of features, check if the features are all enabled."
([state a]

View File

@ -20,6 +20,7 @@
[app.main.ui.ds.foundations.typography :as t]
[app.main.ui.ds.foundations.typography.heading :refer [heading*]]
[app.main.ui.ds.foundations.typography.text :refer [text*]]
[app.render-wasm.api.webgl :as webgl]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.theme :as theme]
@ -101,10 +102,11 @@
handle-render-change
(mf/use-fn
(fn [enabled?]
(st/emit! (ev/event {::ev/name (if enabled?
"enable-webgl-rendering"
"disable-webgl-rendering")
::ev/origin "settings"})
(st/emit! (ev/event (assoc (webgl/get-environment)
::ev/name (if enabled?
"enable-webgl-rendering"
"disable-webgl-rendering")
::ev/origin "settings"))
(du/update-profile-props {:renderer (if enabled? :wasm :svg)})
(ntf/success (if enabled?
(tr "webgl.toast.webgl-render-enabled")

View File

@ -42,6 +42,7 @@
[app.main.ui.ds.foundations.assets.icon :as i :refer [icon*]]
[app.main.ui.hooks.resize :as r]
[app.plugins.register :as preg]
[app.render-wasm.api.webgl :as webgl]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
@ -965,8 +966,9 @@
(dom/reload-current-window true))
(fn [_]
(st/emit! (ntf/error (tr "errors.generic"))))))
(st/emit! (ev/event {::ev/name ev-name
::ev/origin "workspace:menu"})
(st/emit! (ev/event (assoc (webgl/get-environment)
::ev/name ev-name
::ev/origin "workspace:menu"))
(ptk/data-event ::ev/force-persist {})))))
open-plugins-manager

View File

@ -16,6 +16,7 @@
[app.common.types.component :as ctk]
[app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl]
[app.main.data.event :as ev]
[app.main.data.modal :as modal]
[app.main.data.workspace :as dw]
[app.main.data.workspace.transforms :as dwt]
@ -58,6 +59,7 @@
[app.main.ui.workspace.viewport.viewport-ref :as vp-ref :refer [create-viewport-ref]]
[app.main.ui.workspace.viewport.widgets :as widgets]
[app.render-wasm.api :as wasm.api]
[app.render-wasm.api.webgl :as webgl]
[app.render-wasm.rulers-state :as rs]
[app.util.debug :as dbg]
[app.util.text-editor :as ted]
@ -70,6 +72,10 @@
;; --- Viewport
;; Retries after the first failed WebGL context init before showing the
;; "WebGL unavailable" modal.
(def ^:private ^:const max-init-retries 3)
(defn- apply-modifiers-to-objects
[objects modifiers]
(->> modifiers
@ -460,21 +466,28 @@
(let [timeout-id-ref (volatile! nil)
unmounted? (volatile! false)
modal-shown? (volatile! false)
init-error (volatile! nil)
show-unavailable
(fn []
(when-not (or @unmounted? @modal-shown?)
(vreset! modal-shown? true)
(reset! canvas-init? false)
(st/emit! (modal/show {:type :webgl-unavailable}))))
(st/emit! (modal/show {:type :webgl-unavailable})
(ev/event (assoc (webgl/get-environment)
::ev/name "webgl-unavailable"
::ev/origin "workspace"
:hint (or @init-error "no webgl2 context"))))))
try-init
(fn try-init [retries]
(when-not @unmounted?
(vreset! init-error nil)
(let [init? (try
(wasm.api/init-canvas-context canvas)
(catch :default e
(js/console.error "Error initializing canvas context:" e)
(vreset! init-error (ex-message e))
false))]
(cond
init?
@ -490,7 +503,7 @@
(->> @wasm.api/module
(p/fmap (fn [ready?]
(when ready?
(try-init 3)))))
(try-init max-init-retries)))))
(fn []
(vreset! unmounted? true)
(when-let [timeout-id @timeout-id-ref]

View File

@ -33,6 +33,7 @@
[app.common.types.text :as txt]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.event :as-alias ev]
[app.main.data.helpers :as dsh]
[app.main.data.notifications :as ntf]
[app.main.data.render-wasm :as drw]
@ -2389,6 +2390,17 @@
(set-render-options! new-dpr)
(resize-viewbox css-w css-h)))))
(defn- emit-webgl-event
"Send a WebGL audit event with the environment details. Built as a plain
data event so this namespace does not load `app.main.data.event`, which
the worker build cannot run."
[event-name props]
(st/emit! (ptk/data-event ::ev/event
(merge (webgl/get-environment)
props
{::ev/name event-name
::ev/origin "workspace"}))))
(defn- on-webgl-context-lost
[event]
(dom/prevent-default event)
@ -2405,7 +2417,8 @@
:type :toast
:level :warning
:timeout 5000}))
(st/emit! (drw/context-lost)))
(st/emit! (drw/context-lost))
(emit-webgl-event "webgl-context-lost" {}))
(defn- on-webgl-context-restored
[event]
@ -2422,6 +2435,7 @@
;; only after the full reload so layout/viewport sync runs
;; against a live renderer with `wasm/ready?` true.
(st/emit! (drw/context-restored))
(emit-webgl-event "webgl-context-restored" {})
(listen-tiles-render-complete-once! end-context-loss-overlay!)
(st/async-emit!
(ntf/show {:content (tr "webgl.webgl-context-recovered.toast")
@ -2472,6 +2486,7 @@
(let [{:keys [context handle]} result]
(set! wasm/gl-context-handle handle)
(set! wasm/gl-context context)
(webgl/remember-gpu-info context)
;; `init-context` already ran `_init` through `_set_browser` in
;; order. Publish the handles, then mark live before sizing so the
@ -2609,6 +2624,9 @@
(p/catch
(fn [cause]
(ug/dispatch! (ug/event "penpot:wasm:reload-failed"))
(emit-webgl-event "webgl-reload-failed"
{:hint (ex-message cause)
:code (some-> (ex-data cause) :code name)})
(reset! wasm/reloading? false)
(reset! wasm/context-lost? true)
(clear-canvas)

View File

@ -11,6 +11,7 @@
[app.common.math :as mth]
[app.common.render-wasm.helpers :as h]
[app.common.render-wasm.wasm :as wasm]
[cuerdas.core :as str]
[promesa.core :as p]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -314,3 +315,73 @@ void main() {
(resolve false)))
(set! (.-src img) uri))))
(p/resolved false)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Environment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- get-gpu-family
"Normalize a GPU renderer string to a GPU family. Telemetry sends the
family, not the full string, which can help fingerprint a device."
[renderer]
(let [renderer (str/lower renderer)
has? (fn [& parts] (some #(str/includes? renderer %) parts))]
(cond
(has? "swiftshader") "swiftshader"
(has? "llvmpipe" "softpipe") "llvmpipe"
(has? "microsoft basic render") "microsoft-basic-render"
(has? "apple") "apple"
(has? "nvidia" "geforce" "quadro") "nvidia"
(has? "amd" "radeon") "amd"
(has? "intel") "intel"
(has? "adreno") "adreno"
(has? "mali") "mali"
(has? "powervr") "powervr"
:else "other")))
(defn- get-gpu-backend
"Graphics API behind the WebGL implementation (ANGLE names it in the
renderer string), or nil when the string does not say."
[renderer]
(let [renderer (str/lower renderer)
has? (fn [& parts] (some #(str/includes? renderer %) parts))]
(cond
(has? "direct3d11" "d3d11") "d3d11"
(has? "direct3d9" "d3d9") "d3d9"
(has? "metal") "metal"
(has? "vulkan") "vulkan"
(has? "opengl") "opengl")))
(defn- read-gpu-info
"GPU details of a live WebGL context, or nil when it is lost."
[^js gl]
(when-not (.isContextLost gl)
(let [^js ext (.getExtension gl "WEBGL_debug_renderer_info")
renderer (or (when ext
(.getParameter gl (.-UNMASKED_RENDERER_WEBGL ext)))
(.getParameter gl (.-RENDERER gl)))]
(when (string? renderer)
{:gpu-family (get-gpu-family renderer)
:gpu-backend (get-gpu-backend renderer)
:max-texture-size (.getParameter gl (.-MAX_TEXTURE_SIZE gl))}))))
(defonce ^:private gpu-info
(volatile! nil))
(defn remember-gpu-info
"Keep the GPU details of `gl`, a context the renderer just created, so
later events can send them after that context is lost."
[gl]
(when-let [info (try (read-gpu-info gl) (catch :default _ nil))]
(vreset! gpu-info info)))
(defn get-environment
"Environment details for WebGL telemetry: GPU family, GPU backend and max
texture size when already remembered, device memory, CPU cores and
whether the app runs inside Electron. Never creates a WebGL context."
[]
(let [^js navigator js/navigator]
(assoc @gpu-info
:device-memory (.-deviceMemory navigator)
:cpu-cores (.-hardwareConcurrency navigator)
:electron (str/includes? (.-userAgent navigator) "Electron/"))))

View File

@ -174,6 +174,18 @@
(t/is (= 1 (count events)))
(t/is (= 1 (:occurrences (deref (first events)))))))
(t/deftest submit-report-carries-the-active-renderer
(let [submit (fn [state hint]
(with-redefs [st/state (atom state)]
(capture-reports!
#(errors/submit-report :event-name "handled-exception"
:report "report"
:hint hint
:cause (error-cause :hint hint)))))]
(t/is (= "wasm" (:renderer (deref (first (submit {:features #{"render-wasm/v1"}} "a"))))))
(t/is (= "svg" (:renderer (deref (first (submit {:features #{}} "b"))))))
(t/is (nil? (:renderer (deref (first (submit {} "c"))))))))
(t/deftest invalid-report-does-not-consume-a-reservation
(let [cause (error-cause :type :network :hint "boom")
events (capture-reports!