ENG-9166 feat(otel): browser tracing plugin — traceparent per event, web vitals, render timing (3/3) - #6901
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThe PR adds opt-in browser OpenTelemetry instrumentation and wires it into the generated frontend event and socket lifecycle.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/.templates/web/utils/state.js | Adds optional frontend telemetry callbacks around event sending and socket connect/disconnect handling; no eligible unresolved follow-up issue remains. |
| packages/reflex-otel/src/reflex_otel/otel.js | Implements browser tracing, web-vital reporting, socket spans, and optional React Profiler spans. |
| packages/reflex-otel/src/reflex_otel/plugin.py | Adds the compile-time plugin, validated sampling configuration, frontend assets and dependencies, environment data, and source patching. |
| tests/units/reflex_otel/test_plugin.py | Covers endpoint resolution, generated configuration, static assets, entry patching, profiling aliasing, idempotency, and sampling validation. |
| docs/api-reference/observability.md | Documents backend and browser OpenTelemetry setup, emitted telemetry, defaults, sampling, and public-header constraints. |
Reviews (7): Last reviewed commit: "fix(otel): reject out-of-range sample_ra..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81df35005c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
81df350 to
cd466c4
Compare
cd466c4 to
e732a12
Compare
e732a12 to
e8571d8
Compare
Alek99
left a comment
There was a problem hiding this comment.
The browser → backend → chained-event parentage, production render spans, FCP, and TTFB all worked in a local Reflex app. These remaining browser-policy/lifecycle issues are not covered by the happy path.
e8571d8 to
d3bfbe1
Compare
…web vitals to the current navigation
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Part of #6227 (ENG-9166). Stack: 1/3 → 2/3 → 3/3 (this). Base is
farhan/eng-9166-reflex-otel-3; the diff is the two commits on top of 2/3.What
reflex_otel.OtelPlugin(add torx.Config(plugins=[...])) compiles a small OpenTelemetry web bundle into the frontend:PRODUCERspan and a W3Ctraceparent, so one user interaction is one trace: browser → backendSERVERevent → chainedINTERNALevents;web_vital.LCP/CLS/INP/FCP/TTFB) as spans with value/rating attributes;socket.connect/socket.disconnectspans (unintentional disconnects marked ERROR);render_timing=True:react.renderspan per React commit via a root<Profiler>; the plugin aliasesreact-dom/client → react-dom/profilinginvite.config.jsbecause<Profiler>is a no-op in production builds otherwise. Off by default (span volume). Verified in a--env prodbuild.Wiring:
get_frontend_dependencies(pinned@opentelemetry/*,web-vitals),get_static_assets(utils/otel.js),update_env_json(OTELentry: endpoint, service name, headers, flags),add_modify_taskonentry.client.js(import + root wrap). Endpoint defaults followOTEL_EXPORTER_OTLP_TRACES_ENDPOINT/OTEL_EXPORTER_OTLP_ENDPOINT→/v1/traces; must allow CORS.headersare compiled into the public bundle (documented).Framework seam:
state.jscallswindow.__reflex_otel?.onEventSend/onSocketConnect/onSocketDisconnect— undefined unless the plugin is active.Docs: new
docs/api-reference/observability.md(backend + frontend setup, hot-reload-safe guard, metrics table). Log correlation is out of this stack (follow-up: #6903).Known limitation: the browser has no per-event completion signal, so the browser event span has no duration; it exists to carry the trace context.
Tests
tests/units/reflex_otel/test_plugin.py(env/endpoint resolution, asset, env.json, entry patch idempotency + warning, profiling alias patch).