Rewatch: add OpenTelemetry tracing support#8370
Rewatch: add OpenTelemetry tracing support#8370cknitt merged 12 commits intorescript-lang:masterfrom
Conversation
a79a52c to
ece9e1b
Compare
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0429522fe
ℹ️ 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".
| unsafe { | ||
| std::env::remove_var("OTEL_EXPORTER_OTLP_ENDPOINT"); | ||
| std::env::remove_var("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"); | ||
| } |
There was a problem hiding this comment.
Serialize env var mutation in telemetry tests
init_telemetry_without_env_is_noop mutates process-global environment variables using unsafe std::env::remove_var without any synchronization, but Rust tests run in parallel by default, so another test reading/writing env vars concurrently can trigger undefined behavior or flaky failures. Please guard this section with a shared Mutex (or otherwise force serial execution) before mutating OTEL env vars.
Useful? React with 👍 / 👎.
Add optional OTLP tracing export to rewatch, controlled by the OTEL_EXPORTER_OTLP_ENDPOINT environment variable. When set, rewatch exports spans via HTTP OTLP; when unset, tracing is a no-op. Instrument key build system functions (initialize_build, incremental_build, compile, parse, clean, format, packages) with tracing spans and attributes such as module counts and package names. Restructure main.rs to support telemetry lifecycle (init/flush/shutdown) and fix show_progress to use >= LevelFilter::Info so -v/-vv don't suppress progress messages. Also print 'Finished compilation' in plain_output mode during watch full rebuilds. Cherry-picked from rescript-lang#8241.
Propagate parent span through rayon in build.parse so build.parse_file spans are properly nested under build.parse instead of appearing as orphaned root spans. Enrich build.compile_file span with package, suffix, module_system, and namespace attributes for better observability. Cherry-picked from rescript-lang#8241.
Tracing spans are thread-local, so compile_file spans created inside Rayon's par_iter had no parent connection to the compile_wave span on the main thread. Pass the wave span explicitly via `parent: &wave_span` to establish the correct parent-child relationship. Cherry-picked from rescript-lang#8241.
Replace the ad-hoc split-by-/-or-backslash + take-last-two-parts logic with Path::file_name, which handles platform separators correctly and is simpler to reason about. The attribute is informational only, so reducing to the file name (e.g. `ppx.exe`) is strictly more readable than the previous two-segment join.
The dirty_modules attribute on build.parse required a full iteration over build_state.modules every parse phase, even when no subscriber was listening. Gate behind tracing::enabled!(INFO) so incremental rebuilds don't eat that O(N) scan when telemetry is off.
Add a table to the OpenTelemetry section listing the env vars rewatch responds to and what each does. All config is via standard OTEL vars — no rewatch-specific knobs — so this is the full surface area.
Lets callers pass folder arguments to functions taking &Path without the cryptic `as &str` deref-coercion cast: Path::new(&build_args.folder as &str) -> build_args.folder.as_ref() FolderArg already had a Deref<Target = str> impl, so this is the analogous addition for the &Path direction.
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
be38941 to
f43dcc6
Compare
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
Summary
Cherry-picked telemetry-only subset of #8241. Adds optional OTLP tracing export to rewatch, controlled by the
OTEL_EXPORTER_OTLP_ENDPOINTenvironment variable. When unset, tracing is a no-op.telemetrymodule wiring uptracing+opentelemetry-otlpwith a batch HTTP exporter and aTelemetryGuardthat flushes on drop.#[instrument]/info_span!coverage acrossinitialize_build,incremental_build,compile,parse,clean,packages,format, and the watcher full-compile trigger.build.parse_fileandbuild.compile_filespans nest correctly under their parents (these are otherwise orphaned because tracing spans are thread-local).ctrlc"termination" feature enabled so SIGTERM/SIGHUP also trigger the guard's Drop — required to flush buffered spans when stopped by a container/systemd/kill.AGENTS.md.The original PR also included a Vitest test harness, CI/Makefile/scripts changes, and two unrelated UX tweaks. Those are excluded here — the UX tweaks will follow in separate PRs.
Test plan
cargo build --release --manifest-path rewatch/Cargo.tomlcargo test --manifest-path rewatch/Cargo.toml(68/68 pass)cargo clippy --manifest-path rewatch/Cargo.toml --all-targets --all-features(clean)OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 ./rewatch buildwith Jaeger running🤖 Generated with Claude Code