Skip to content

add tracing configuration - #129380

Merged
rosebyte merged 5 commits into
dotnet:mainfrom
rosebyte:trcing-configuration
Jun 23, 2026
Merged

add tracing configuration#129380
rosebyte merged 5 commits into
dotnet:mainfrom
rosebyte:trcing-configuration

Conversation

@rosebyte

@rosebyterosebyte commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Implements tracing configuration support with a builder-style API, aligned with the approved design in #100317.

Key changes in this PR:

  • Adds AddTracing and tracing builder APIs in Microsoft.Extensions.Diagnostics.
  • Adds tracing rule configuration (EnableTracing / DisableTracing) with source, operation, listener, and scope matching.
  • Adds configuration-based tracing enable/disable support.
  • Introduces ActivitySourceFactory and related ActivitySource / ActivityListener enhancements needed for factory-driven and refreshable listener behaviour.
  • Adds tests covering rule evaluation, configuration loading, listener refresh, and factory caching/disposal scenarios.

Issue

Fixes#100317

API Approval

This implementation follows the API proposal approved in #100317 (api-approved) except two details we're signing off currently, nonetheless, it shouldn't be a blocker for PR review.

Testing

Added/updated unit tests in:

  • System.Diagnostics.DiagnosticSource
  • Microsoft.Extensions.Diagnostics

Note

This PR description was generated with GitHub Copilot assistance.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing
See info in area-owners.md if you want to be subscribed.

CopilotAI 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 expands the tracing stack across System.Diagnostics.DiagnosticSource and Microsoft.Extensions.Diagnostics to support configurable tracing with factory-created ActivitySource instances, including listener refresh semantics and additional concurrency hardening around dispose races.

Changes:

  • Adds new public tracing APIs in System.Diagnostics (ActivitySourceFactory, ActivitySourceOptions.Scope, ActivitySource.Scope, ActivityListener.RefreshSources, and unseals ActivitySource to support derived factory-owned instances).
  • Implements Microsoft.Extensions.Diagnostics tracing services/configuration (AddTracing, rule parsing, listener registration, and a caching DefaultActivitySourceFactory).
  • Adds extensive tests for listener refresh/dispose races and rule/configuration behavior.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 9 comments.

Show a summary per file
FileDescription
src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivitySourceTests.csAdds new RemoteExecutor tests for RefreshSources, dispose races, predicate-throw behavior, and factory creation semantics.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySourceOptions.csAdds Scope option for attaching an opaque scope to ActivitySource.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySourceFactory.csIntroduces ActivitySourceFactory base class that validates/binds scope and creates sources from options.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySource.csUnseals ActivitySource, adds Scope, adds dispose sentinel handling, and implements ResetSourceFilters for refresh semantics + predicate exception aggregation.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityListener.csAdds RefreshSources() and a disposal flag to make refresh/dispose races no-op / self-cleaning.
src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csprojIncludes the new ActivitySourceFactory.cs in the build.
src/libraries/System.Diagnostics.DiagnosticSource/src/Resources/Strings.resxAdds resource strings for invalid scope and refresh predicate failures.
src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.csUpdates ref surface for the new/changed public APIs (ActivitySource unsealed, Scope, Dispose(bool), ActivitySourceFactory, ActivityListener.RefreshSources).
src/libraries/Microsoft.Extensions.Diagnostics/tests/TracingConfigureOptionsTests.csAdds unit tests for configuration-to-rule parsing.
src/libraries/Microsoft.Extensions.Diagnostics/tests/Microsoft.Extensions.Diagnostics.Tests.csprojCompiles tracing configuration implementation into the test project for direct testing.
src/libraries/Microsoft.Extensions.Diagnostics/tests/DefaultActivitySourceFactoryTests.csAdds tests for caching, rule matching, config reload behavior, and factory disposal behavior.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/TracingServiceExtensions.csAdds IServiceCollection.AddTracing() registrations (factory, listener config factory, startup activator).
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/DefaultActivitySourceFactory.csImplements caching ActivitySourceFactory + listener registrations that refresh based on TracingOptions changes.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingConfigureOptions.csParses IConfiguration into TracingRule instances for tracing enablement.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingConfiguration.csWraps an IConfiguration instance for later per-listener merging.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingBuilderConfigurationExtensions.csAdds ITracingBuilder.AddConfiguration(...) to wire options + change tokens.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/DefaultActivityListenerConfigurationFactory.csMerges multiple configuration sources into a per-listener view.
src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/ActivityListenerConfigurationFactory.csNew public abstraction for resolving per-listener configuration views.
src/libraries/Microsoft.Extensions.Diagnostics/ref/Microsoft.Extensions.Diagnostics.csAdds ref entries for TracingServiceExtensions + tracing configuration factory surface.
src/libraries/Microsoft.Extensions.Diagnostics/README.mdDocuments the new tracing extension entry points.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/tests/TracingBuilderExtensionsRulesTests.csAdds tests validating the rule-registration extension methods.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingRule.csIntroduces a public rule type with wildcard validation and scope validation.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingOptions.csIntroduces tracing options holding the rule list.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingBuilderExtensions.Rules.csAdds enable/disable rule extension methods for builder/options.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingBuilderExtensions.Listeners.csAdds listener registration/clearing APIs for ITracingBuilder.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ITracingBuilder.csAdds the tracing builder abstraction (DI surface).
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ActivitySourceScopes.csAdds the Global/Local scope enum for rule matching.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ActivityListenerBuilder.csAdds the listener builder type used by AddListener callbacks.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.csprojAdds needed ref project references for the new tracing types.
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.csAdds ref entries for the new tracing abstractions and extensions.
src/libraries/Common/src/System/ExceptionPolyfills.csAdds a downlevel polyfill for ArgumentException.ThrowIfNullOrEmpty.

@rosebyte
rosebyteforce-pushed the trcing-configuration branch from aecf70c to ff45fb8CompareJune 14, 2026 05:57
@rosebyte

Copy link
Copy Markdown
MemberAuthor

@copilot , there are comments demanding timeout for waiting, add the timeouts as suggested.

CopilotAI review requested due to automatic review settings June 14, 2026 14:46

CopilotAI 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

Copilot reviewed 31 out of 31 changed files in this pull request and generated 5 comments.

CopilotAI review requested due to automatic review settings June 18, 2026 06:26

CopilotAI 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

Copilot reviewed 32 out of 32 changed files in this pull request and generated 5 comments.

@rosebyte
rosebyte merged commit e3ecd30 into dotnet:mainJun 23, 2026
97 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 24, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
## Summary
Implements tracing configuration support with a builder-style API,
aligned with the approved design in #100317.
Key changes in this PR:
- Adds `AddTracing` and tracing builder APIs in
`Microsoft.Extensions.Diagnostics`.
- Adds tracing rule configuration (`EnableTracing` / `DisableTracing`)
with source, operation, listener, and scope matching.
- Adds configuration-based tracing enable/disable support.
- Introduces `ActivitySourceFactory` and related `ActivitySource` /
`ActivityListener` enhancements needed for factory-driven and
refreshable listener behaviour.
- Adds tests covering rule evaluation, configuration loading, listener
refresh, and factory caching/disposal scenarios.
## Issue
Fixes#100317
## API Approval
This implementation follows the API proposal approved in #100317
(`api-approved`) except two details we're signing off currently,
nonetheless, it shouldn't be a blocker for PR review.
## Testing
Added/updated unit tests in:
- `System.Diagnostics.DiagnosticSource`
- `Microsoft.Extensions.Diagnostics`
> [!NOTE]
> This PR description was generated with GitHub Copilot assistance.
---------
Co-authored-by: rosebyte <jaroslav.ruzicka@hotmail.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracing configuration similar to MetricsBuilder

4 participants

@rosebyte@svick@cincuranet