Skip to content

fix(observed): correct enrichment, processor and test-harness behavior - #712

Draft
Evgenii (Vaiz) wants to merge 3 commits into
mainfrom
u/vaiz/2026/08/28/observed-api-fixes
Draft

fix(observed): correct enrichment, processor and test-harness behavior#712
Evgenii (Vaiz) wants to merge 3 commits into
mainfrom
u/vaiz/2026/08/28/observed-api-fixes

Conversation

@Vaiz

@Vaiz Evgenii (Vaiz) commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting.

Problem

Behavioral and ergonomics defects in observed and observed_testing, each confirmed against main. Unlike the sibling documentation pull requests, this one changes code.

What changes

Runtime

  • Slot::push, Sink::push_enrichment and EnrichmentTransfer allocated an Arc node and touched every captured slot even when the enrichment layer was empty. An empty layer now returns a no-op guard and leaves the slot untouched. push_for takes the same early return, so an empty targeted layer allocates nothing either. Guard merge and drop semantics are unchanged; new tests cover the empty push, the merged-guard case, and the transfer path.
  • The early return lives in push and push_for, where the layer is still owned. The private EnrichmentTransfer::push_entries briefly repeated the check, but by then both callers had already returned, so that half of its guard could never be true; the mutation gate caught it as a surviving ||/&& mutant and it is removed.

Test harness

  • ExpectedEvent::new documented itself as expecting a log event but set expect_log: false, so every caller had to add .log() to get the documented behavior. It now sets true. The type also claimed partial matching while PartialEq compares body, dimensions, metric and disabled exactly; the documentation now says so. Redundant .log() calls are removed and a fieldless-log test pins the new default. observed_testing is not published, so this reaches no external consumer.

Examples and benchmarks

  • support/otel.rs exported the emitting crate as code.namespace, an attribute OpenTelemetry has deprecated. The mapping is removed and the test that pinned it now asserts absence.
  • layered_app/token_issuer.rs hand-built DataClass::new("microsoft", "PublicNonPersonalData") instead of using the shared taxonomy constant, and recorded validation failures as an up-down counter carrying a constant failure_count: 1. A failure count only increases, so it is now a fieldless counter.
  • The emit_context benchmark group named operations its bodies do not perform: attach_emitter constructs and drops a Sink, and emit_event_no_emitter emits through Sink::noop(). The group, functions and identifiers are renamed to match. This changes benchmark identifiers, so historical series under the old names do not carry over.

Withdrawn after review

Two changes were reverted in b9639949:

  • Default no-op EventProcessor::flush. A default body lets a processor that buffers telemetry silently skip flushing it, with no error and no compile-time signal. The repeated Ok(()) in stateless processors is the cheaper cost. flush stays a required method.
  • Documenting EnrichmentEntry. The type is public only because Rust cannot hide a type the derive expansion must reference. It is not a stable construction API, and #[derive(Enrichment)] remains the single supported route, so it is back to #[doc(hidden)].

Effects

  • An empty enrichment layer, targeted or not, costs no allocation and no slot write.
  • ExpectedEvent::new matches its documentation; assertions that relied on the previous default change meaning.
  • Exported telemetry no longer carries the deprecated code.namespace attribute.
  • Benchmark identifiers in the sink-operations group change; comparisons against earlier runs need remapping.
  • No public API change. EventProcessor and the enrichment re-exports are as they were on main.

Validation

just anvil-fmt, just anvil-clippy, just anvil-readme-check, just anvil-spellcheck, cargo +1.96.1 test -p observed -p observed_testing, cargo +1.96.1 build -p observed --examples, cargo +1.96.1 check -p observed --benches, and a cargo mutants run scoped to crates/observed/src/enrichment/slot.rs all pass.

Copilot AI lite review requested due to automatic review settings August 28, 2026 14:27
@Vaiz
Evgenii (Vaiz) marked this pull request as draft August 28, 2026 14:31

Copilot AI 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.

Pull request overview

This PR fixes several behavioral and ergonomics issues across the observed runtime and the observed_testing harness, with additional cleanup to examples/benchmarks and OpenTelemetry log-record mapping to remove deprecated metadata.

Changes:

  • Optimize enrichment pushes so empty enrichment layers become true no-ops (avoiding unnecessary slot writes / guard work) and add coverage tests for the empty/merged/transfer cases.
  • Make EventProcessor::flush optional via a default no-op implementation and remove redundant flush implementations from examples.
  • Correct observed_testing::ExpectedEvent defaults/docs to match exact-match behavior and make ExpectedEvent::new actually default to expecting a log signal; update docs/tests accordingly.
  • Remove deprecated code.namespace emission from the OTel mapping and update the integration test assertion.
  • Rename the sink-related benchmark group and identifiers to match what the benchmarks actually do.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/observed/tests/otel_log_record.rs Updates OTel integration test to assert deprecated code.namespace is not exported.
crates/observed/src/sink/core.rs Returns a no-op enrichment guard early when the enrichment entry set is empty.
crates/observed/src/processing/processor.rs Provides a default no-op implementation for EventProcessor::flush.
crates/observed/src/enrichment/slot.rs Adds empty-layer short-circuits in enrichment push paths, introduces Guard::empty, and adds coverage tests.
crates/observed/src/enrichment/mod.rs Makes EnrichmentEntry publicly documented (removes #[doc(hidden)]).
crates/observed/src/enrichment/enrichment_trait.rs Adds a manual Enrichment implementation example to docs.
crates/observed/examples/*.rs Removes redundant flush implementations now covered by the trait default.
crates/observed/examples/support/otel.rs Removes deprecated code.namespace attribute mapping from OTel log records.
crates/observed/examples/layered_app/token_issuer.rs Uses shared taxonomy constant and switches failure metric to a monotonic counter.
crates/observed/benches/observed_benchmarks.rs Renames sink-operation benchmark group and identifiers for accuracy.
crates/observed_testing/src/mock_processor.rs Fixes ExpectedEvent defaults/docs to be exact-match and to expect log by default; adds a pinning test.
crates/observed_testing/src/lib.rs Updates crate docs example to remove redundant .log() usage.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/observed/src/enrichment/slot.rs Outdated
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

⚠️ Potential breaking changes detected

cargo semver-checks flagged the following on this PR. This is informational -- breaking changes between commits are expected; the major-version bump happens at release time, not on every PR.

observed

     Cloning origin/main
    Building observed v0.25.0 (current)
       Built [   5.655s] (current)
     Parsing observed v0.25.0 (current)
error: unsupported rustdoc format v60 for file: /home/runner/work/oxidizer/oxidizer/target/semver-checks/local-observed-0_25_0-default-d7b8c5ec6ce39049/target/doc/observed.json
(supported formats are v55, v56, v57)

observed_testing

     Cloning origin/main
    Building observed_testing v0.0.0 (current)
       Built [   6.102s] (current)
     Parsing observed_testing v0.0.0 (current)
error: unsupported rustdoc format v60 for file: /home/runner/work/oxidizer/oxidizer/target/semver-checks/local-observed_testing-0_0_0-default-01666ec060466c14/target/doc/observed_testing.json
(supported formats are v55, v56, v57)

observed_utils

     Cloning origin/main
    Building observed_utils v0.2.0 (current)
       Built [   5.806s] (current)
     Parsing observed_utils v0.2.0 (current)
error: unsupported rustdoc format v60 for file: /home/runner/work/oxidizer/oxidizer/target/semver-checks/local-observed_utils-0_2_0-default-01666ec060466c14/target/doc/observed_utils.json
(supported formats are v55, v56, v57)

Comment thread crates/observed/src/enrichment/enrichment_trait.rs Outdated
Comment thread crates/observed/src/processing/processor.rs Outdated
Comment thread crates/observed/src/sink/core.rs Outdated
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (356dc63) to head (41920bf).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #712   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files         563      563           
  Lines       61068    61080   +12     
=======================================
+ Hits        61068    61080   +12     
Flag Coverage Δ
linux 64.3% <100.0%> (?)
linux-arm 67.9% <100.0%> (?)
windows 68.6% <100.0%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Evgenii (Vaiz) and others added 3 commits August 28, 2026 16:06
Rename sink benchmarks to match measured operations
Use shared taxonomy and monotonic validation failure counter
Skip empty enrichment layers before mutating slots
Document manual enrichment entries and default no-op flush
Correct expected-event log defaults and OTel source attributes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Roll back the two changes the crate owner rejected:

- EventProcessor::flush goes back to a required method. A default no-op
  lets a processor that buffers telemetry silently skip flushing it, and
  losing telemetry is worse than the repeated Ok(()).
- EnrichmentEntry returns to #[doc(hidden)] and the manual Enrichment
  implementation example is removed. The type is public only because
  Rust has no way to hide it from the derive expansion; the derive macro
  remains the single supported way to build an enrichment.

Also drop the "composites with zero children" note from
Sink::push_enrichment, which described an internal dispatch detail, and
give EnrichmentTransfer::push_for the same empty-layer early return as
push so a targeted layer with no entries allocates nothing either.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Both callers of `EnrichmentTransfer::push_entries` already return early
when the enrichment layer is empty, so the `entries.is_empty()` half of
its guard can never be true. It decided nothing, which the mutation gate
caught: replacing `||` with `&&` survived on all three platforms.

The empty-layer no-op is unchanged — it is enforced where the layer is
still owned, in `push` and `push_for`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Vaiz
Evgenii (Vaiz) force-pushed the u/vaiz/2026/08/28/observed-api-fixes branch from b963994 to 41920bf Compare August 28, 2026 15:36
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