Skip to content

ENG-9166 feat(otel): compile spans (2/3) - #6900

Open
FarhanAliRaza wants to merge 1 commit into
farhan/eng-9166-reflex-otelfrom
farhan/eng-9166-reflex-otel-3
Open

ENG-9166 feat(otel): compile spans (2/3)#6900
FarhanAliRaza wants to merge 1 commit into
farhan/eng-9166-reflex-otelfrom
farhan/eng-9166-reflex-otel-3

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Part of #6227 (ENG-9166). Stack: 1/32/3 (this) → 3/3. Base is farhan/eng-9166-reflex-otel (1/3); the diff is one commit.

What

  • App._compile runs inside a reflex.compile span (reflex.compile.trigger, reflex.compile.dry_run); the compile stages get explicit child spans in compiler.py: reflex.compile.evaluate_pages, .pages, .copy_assets, .install_frontend_packages, .write.
  • otel.span() / otel.compile_span() helpers (no-op nullcontext when disabled; compile is not a hot path).

Log correlation (trace_id/span_id on JSON log records) was split out of this stack: it needs the JsonHandler from the logging pipeline (#6863) and will follow as a small PR once that lands (#6903).

Tests

test_otel.py (span helpers, compile_span attributes/nesting), test_app.py::test_compile_emits_stage_spans (real compile, stages nest under reflex.compile).

@FarhanAliRaza
FarhanAliRaza requested a review from a team as a code owner August 17, 2026 20:57
@linear-code

linear-code Bot commented Aug 17, 2026

Copy link
Copy Markdown

ENG-9166

@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR instruments application compilation with an OpenTelemetry root span and nested stage spans while remaining inert when tracing is disabled.

  • Adds generic and compile-specific span context-manager helpers.
  • Wraps App._compile in a compile span carrying trigger and dry-run attributes.
  • Instruments page evaluation, page compilation, asset copying, package installation, and disk writes.
  • Adds unit and integration coverage for span attributes, nesting, and disabled behavior.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/otel.py Adds no-op-aware generic and compile span helpers with compile metadata attributes.
reflex/app.py Wraps the existing compile and telemetry-accounting flow in the new root compile span.
reflex/compiler/compiler.py Adds child spans around the major compile stages without changing their underlying operations.
tests/units/reflex_base/test_otel.py Covers disabled helpers, compile attributes, and parent-child span relationships.
tests/units/test_app.py Verifies a real compile emits root and stage spans with the expected hierarchy.

Reviews (4): Last reviewed commit: "feat(otel): compile spans" | Re-trigger Greptile

Comment thread reflex/compiler/compiler.py
@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing farhan/eng-9166-reflex-otel-3 (acf9a22) with farhan/eng-9166-reflex-otel (b0d7618)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e88ec4f6ef

ℹ️ 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".

Comment thread packages/reflex-otel/src/reflex_otel/__init__.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 28 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/reflex-otel/src/reflex_otel/__init__.py Outdated
Comment thread pyproject.toml
Comment thread packages/reflex-base/src/reflex_base/otel.py
Comment thread news/6227.feature.md
Comment thread packages/reflex-otel/pyproject.toml
Comment thread packages/reflex-base/pyproject.toml Outdated
Comment thread packages/reflex-base/src/reflex_base/otel.py
Comment thread reflex/app.py
@FarhanAliRaza FarhanAliRaza changed the title ENG-9166 feat(otel): compile spans and trace ids on JSON log records (2/3) ENG-9166 feat(otel): compile spans (2/3) Aug 17, 2026
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-9166-reflex-otel-3 branch from e88ec4f to 1f5b784 Compare August 17, 2026 21:21
@FarhanAliRaza
FarhanAliRaza requested a review from Alek99 as a code owner August 17, 2026 21:21
@FarhanAliRaza
FarhanAliRaza changed the base branch from farhan/eng-10963-log-5-deprecate-console to farhan/eng-9166-reflex-otel August 17, 2026 21:21
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-9166-reflex-otel-3 branch from 1f5b784 to 7c86654 Compare August 17, 2026 21:35
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-9166-reflex-otel-3 branch from 7c86654 to acf9a22 Compare August 17, 2026 21:53

@Alek99 Alek99 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial compile trace works locally, but the common backend-startup/stateful-marker path omits one advertised stage.

with console.timing("Evaluate Pages (Backend)"):
with (
console.timing("Evaluate Pages (Backend)"),
otel.span("reflex.compile.evaluate_pages"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Include the stateful-marker backend evaluation in reflex.compile.evaluate_pages

When .web/backend exists and stateful_pages.json is present, the earlier branch evaluates each marked page with _compile_page(..., save_page=False) and returns at line 1171 before this span is entered. I reproduced that normal backend_startup path with an OTLP exporter: only the reflex.compile root was emitted even though page evaluation ran. Please wrap the marker-driven loop in the same stage span (or factor both paths through a shared helper) and cover the early-return marker path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants