Skip to content

Add early log sampling hook - #7773

Open
amadeuszl wants to merge 2 commits into
dotnet:mainfrom
amadeuszl:users/alechniak/early-sampling
Open

amadeuszl wants to merge 2 commits into
dotnet:mainfrom
amadeuszl:users/alechniak/early-sampling

Conversation

@amadeuszl

@amadeuszl amadeuszl commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Enables wiring up early sampling, so it skips log record creation early

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 23, 2026 11:15
@amadeuszl
amadeuszl requested a review from a team as a code owner September 23, 2026 11:15

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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and the change includes test coverage.

Review effort: Lite
Findings: None

What changed in this PR

Adds an early logging-sampling hook to reject records before enrichment, redaction, or formatting.

Changes:

  • Adds category/level sampling support.
  • Applies early sampling during logging and enablement checks.
  • Adds tests and updates the public API baseline.
File Description
test/​Libraries/​Microsoft.Extensions.Telemetry.Tests/​Logging/​ExtendedLoggerTests.cs Tests early rejection behavior.
src/​Libraries/​Microsoft.Extensions.Telemetry/​Logging/​ExtendedLoggerFactory.cs Passes category names to loggers.
src/​Libraries/​Microsoft.Extensions.Telemetry/​Logging/​ExtendedLogger.cs Performs early sampling.
src/​Libraries/​Microsoft.Extensions.Telemetry.Abstractions/​Sampling/​LoggingSampler.cs Defines the sampling hook.
src/​Libraries/​Microsoft.Extensions.Telemetry.Abstractions/​Microsoft.Extensions.Telemetry.Abstractions.json Records the public API addition.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

/// only the supplied values and ambient state. It may be called more than once for the same log record,
/// so implementations should return a stable decision. The default implementation enables the log record.
/// </remarks>
public virtual bool ShouldSample(string categoryName, LogLevel logLevel) => true;

@amadeuszl amadeuszl Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

instead of that we could bring new class eg. EarlyLoggingSampler

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants