Skip to content

feat(observed): add event sampling support - #725

Merged
Evgeny Fedorov (evgenyfedorov2) merged 10 commits into
microsoft:mainfrom
evgenyfedorov2:u/efedorov/observed-sampling-framework
Sep 4, 2026
Merged

feat(observed): add event sampling support#725
Evgeny Fedorov (evgenyfedorov2) merged 10 commits into
microsoft:mainfrom
evgenyfedorov2:u/efedorov/observed-sampling-framework

Conversation

@evgenyfedorov2

Copy link
Copy Markdown
Member

Adds opt-in event sampling to observed.

  • Calls the sampler once for every event a Sink is interested in.
  • Sampling implementations have access to the event description, Sink identity, and timestamp through a read-only context.
  • Supports single, composite, and no-op Sinks while preserving borrowed event emission.

Copilot AI lite review requested due to automatic review settings September 3, 2026 18:32

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.

🟢 Approval recommended

The sampling API and implementation are cohesive, align with the documented contract, and are backed by targeted tests covering key semantics (interest gating, composites, cloning, and dyn events).

Pull request overview

Adds opt-in per-sink event sampling to the observed crate, allowing users to synchronously gate delivery to a sink’s processors based on a read-only event context (description, leaf sink id, and timestamp) while preserving borrowed-event emission behavior.

Changes:

  • Introduces a new observed::sampling module defining EventSampler, EventContext, and EventSamplingDecision.
  • Adds Sink::with_event_sampler(...) and wires sampler decisions into leaf dispatch (single and composite sinks), with noop remaining unaffected.
  • Adds integration tests in observed_testing covering sampling decisions, composite behavior, cloning/ownership semantics, and dynamic-event interop.
File summaries
File Description
crates/observed/src/sink/core.rs Adds sampler storage to leaf sink state and applies sampling decisions during dispatch; exposes Sink::with_event_sampler.
crates/observed/src/sampling/mod.rs Defines the public sampling API (context, decision enum, sampler trait) and documents the contract.
crates/observed/src/lib.rs Exposes the new sampling module publicly.
crates/observed/FEATURES.md Documents the new per-sink sampling capability at a feature level.
crates/observed/DESIGN.md Updates sink/routing design documentation to include the sampling gate in the dispatch contract.
crates/observed_testing/tests/event_sampling.rs Adds end-to-end tests validating sampling behavior across sink types and emission styles.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: aa28f79b-7be9-49b1-9b96-361080fad46c
@evgenyfedorov2
Evgeny Fedorov (evgenyfedorov2) force-pushed the u/efedorov/observed-sampling-framework branch from f2525a2 to ef503c8 Compare September 3, 2026 18:50
Copilot AI review requested due to automatic review settings September 3, 2026 18:50

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.

🟡 Changes recommended

The documented “exactly once” sampling call contract appears stricter than the actual dispatch behavior under the reentrancy guard, so the public docs should be tightened to match reality.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread crates/observed/src/sampling/mod.rs
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (8c5a3c9) to head (1ca8ca0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #725   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files         582      583    +1     
  Lines       62852    62891   +39     
=======================================
+ Hits        62852    62891   +39     
Flag Coverage Δ
linux 68.9% <100.0%> (-31.1%) ⬇️
linux-arm 68.9% <100.0%> (-31.1%) ⬇️
scheduled ?
windows 63.8% <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.

Comment thread crates/observed/src/sink/core.rs
Comment thread crates/observed/src/sampling/mod.rs Outdated
Comment thread crates/observed/src/sampling/mod.rs
Comment thread crates/observed/src/sampling/mod.rs
@psandana

Copy link
Copy Markdown
Contributor

🤖 Pato's Pull Request Agent: The routing flowchart in DESIGN.md (the :::mermaid diagram: emit → Interest pass → Collect dimensions → per-processor Redaction → exporters) wasn't updated for sampling — it has no EventSampler node, though the surrounding prose now describes the gate. Consider inserting a sampler decision node between "Interest pass" and "Collect dimensions" (Drop ⇒ stop the leaf, Continue ⇒ proceed) so the diagram matches the code.

Copilot AI review requested due to automatic review settings September 4, 2026 05:53

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.

🟢 Approval recommended

The sampling API, wiring, documentation updates, and test coverage align with the stated contract and are internally consistent across single/composite/noop sinks.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 06:01
@evgenyfedorov2

Copy link
Copy Markdown
Member Author

🤖 Pato's Pull Request Agent: The routing flowchart in DESIGN.md (the :::mermaid diagram: emit → Interest pass → Collect dimensions → per-processor Redaction → exporters) wasn't updated for sampling — it has no EventSampler node, though the surrounding prose now describes the gate. Consider inserting a sampler decision node between "Interest pass" and "Collect dimensions" (Drop ⇒ stop the leaf, Continue ⇒ proceed) so the diagram matches the code.

Fixed, thank you!

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.

🟢 Approval recommended

The sampling contract is implemented at the leaf-dispatch boundary and is backed by targeted unit/integration tests covering the intended invocation and edge-case behavior.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@martintmk
martintmk self-requested a review September 4, 2026 06:23

@martintmk martintmk 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.

[AI AGENT]: Reviewing as an AI agent, with most attention on the new public sampling contract. I took this PR's green CI as the baseline rather than re-running it, and verified the two substantive findings below locally against c8062d44 with targeted probes.

Public surface reviewed: observed::sampling (EventContext, EventSamplingDecision, EventSampler) and Sink::with_event_sampler. One finding, on EventContext's constructor. The rest of the surface holds up: Arc<dyn EventSampler> matches the crate's existing Sink::new(.., Vec<Arc<dyn EventProcessor>>, ..) family and is what makes one sampler shareable across leaves; EventContext's private fields leave room to add inputs without a break; and an unsealed single-method trait is the right shape for an intended extension point. I did not re-raise the EventContext name or #[non_exhaustive] points already settled in earlier threads.

Correctness - no defects found. I traced every changed dispatch path. Two things worth recording as sound rather than assumed: the sampler runs inside the reentrancy guard taken in emit_impl (sink/core.rs L403), so a sampler that emits telemetry is dropped rather than recursing, which is what makes the "not supported" wording safe rather than merely discouraged; and with_event_sampler clones SingleSinkState, whose Slot is Arc<ThreadLocal<..>>, so leaf identity and the shared enrichment slot genuinely survive attachment exactly as the doc claims.

Tests: one gap, commented inline. Otherwise the suite is behaviour-shaped and covers the semantics I would want pinned - interest gating, composite independence, clone-before/clone-after, replacement, borrowed and DynEvent emission, and the noop/empty/processorless corners.

Performance, telemetry, resilience, dependencies: no findings. The added hot-path cost is one Option check plus one virtual call; the clock read that precedes it is contract, not waste, since EventContext::timestamp exposes it. No new dependencies, no new features, no telemetry emitted.

Verdict: approve with non-blocking comments. Nothing here blocks the merge. The composite test is the one item I would like to see land with the feature, since nothing else in CI can catch that regression.

Comment thread crates/observed/src/sampling/mod.rs Outdated
Comment thread crates/observed_testing/tests/event_sampling.rs
Comment thread crates/observed/src/sink/core.rs Outdated

@sgalkin Sergey Galkin (sgalkin) 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.

🤖 Co-authored with Copilot.

Copilot AI review requested due to automatic review settings September 4, 2026 08:25

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.

🟢 Approval recommended

The sampling API, sink integration, and documentation/tests are consistent with the stated per-leaf sampling contract and do not introduce observable correctness issues in the reviewed changes.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 08:35

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.

🟢 Approval recommended

The sampling API and dispatch integration match the stated contract and are backed by focused unit/integration coverage across key sink configurations.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 09:30

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.

🟢 Approval recommended

Implementation and tests look coherent; only minor documentation wording issues were found (references to a crate-private module path).

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread crates/observed/DESIGN.md Outdated
Comment thread crates/observed/FEATURES.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2026 09:36

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.

🟢 Approval recommended

The sampling API and its integration are consistent with existing sink dispatch semantics and are backed by targeted unit/integration coverage for key behaviors (single/composite/noop, cloning, replacement, and dyn-event interop).

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 09:42

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.

🟢 Approval recommended

The sampling API and sink integration are consistent with existing routing/interest behavior and are backed by targeted unit and integration tests without any evident correctness or design issues in the changed code paths.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 09:50

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.

🟢 Approval recommended

The sampling API and dispatch integration are coherent with existing routing semantics, and the change includes targeted tests and documentation updates for the new behavior.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@evgenyfedorov2
Evgeny Fedorov (evgenyfedorov2) merged commit 40c705c into microsoft:main Sep 4, 2026
51 checks passed
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.

5 participants