add tracing configuration#129380
Open
rosebyte wants to merge 3 commits into
Open
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing |
Contributor
There was a problem hiding this comment.
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 unsealsActivitySourceto support derived factory-owned instances). - Implements
Microsoft.Extensions.Diagnosticstracing services/configuration (AddTracing, rule parsing, listener registration, and a cachingDefaultActivitySourceFactory). - 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
| File | Description |
|---|---|
| src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivitySourceTests.cs | Adds new RemoteExecutor tests for RefreshSources, dispose races, predicate-throw behavior, and factory creation semantics. |
| src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySourceOptions.cs | Adds Scope option for attaching an opaque scope to ActivitySource. |
| src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySourceFactory.cs | Introduces ActivitySourceFactory base class that validates/binds scope and creates sources from options. |
| src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivitySource.cs | Unseals 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.cs | Adds RefreshSources() and a disposal flag to make refresh/dispose races no-op / self-cleaning. |
| src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj | Includes the new ActivitySourceFactory.cs in the build. |
| src/libraries/System.Diagnostics.DiagnosticSource/src/Resources/Strings.resx | Adds resource strings for invalid scope and refresh predicate failures. |
| src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs | Updates ref surface for the new/changed public APIs (ActivitySource unsealed, Scope, Dispose(bool), ActivitySourceFactory, ActivityListener.RefreshSources). |
| src/libraries/Microsoft.Extensions.Diagnostics/tests/TracingConfigureOptionsTests.cs | Adds unit tests for configuration-to-rule parsing. |
| src/libraries/Microsoft.Extensions.Diagnostics/tests/Microsoft.Extensions.Diagnostics.Tests.csproj | Compiles tracing configuration implementation into the test project for direct testing. |
| src/libraries/Microsoft.Extensions.Diagnostics/tests/DefaultActivitySourceFactoryTests.cs | Adds tests for caching, rule matching, config reload behavior, and factory disposal behavior. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/TracingServiceExtensions.cs | Adds IServiceCollection.AddTracing() registrations (factory, listener config factory, startup activator). |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/DefaultActivitySourceFactory.cs | Implements caching ActivitySourceFactory + listener registrations that refresh based on TracingOptions changes. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingConfigureOptions.cs | Parses IConfiguration into TracingRule instances for tracing enablement. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingConfiguration.cs | Wraps an IConfiguration instance for later per-listener merging. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/TracingBuilderConfigurationExtensions.cs | Adds ITracingBuilder.AddConfiguration(...) to wire options + change tokens. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/DefaultActivityListenerConfigurationFactory.cs | Merges multiple configuration sources into a per-listener view. |
| src/libraries/Microsoft.Extensions.Diagnostics/src/Tracing/Configuration/ActivityListenerConfigurationFactory.cs | New public abstraction for resolving per-listener configuration views. |
| src/libraries/Microsoft.Extensions.Diagnostics/ref/Microsoft.Extensions.Diagnostics.cs | Adds ref entries for TracingServiceExtensions + tracing configuration factory surface. |
| src/libraries/Microsoft.Extensions.Diagnostics/README.md | Documents the new tracing extension entry points. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/tests/TracingBuilderExtensionsRulesTests.cs | Adds tests validating the rule-registration extension methods. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingRule.cs | Introduces a public rule type with wildcard validation and scope validation. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingOptions.cs | Introduces tracing options holding the rule list. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingBuilderExtensions.Rules.cs | Adds enable/disable rule extension methods for builder/options. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/TracingBuilderExtensions.Listeners.cs | Adds listener registration/clearing APIs for ITracingBuilder. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ITracingBuilder.cs | Adds the tracing builder abstraction (DI surface). |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ActivitySourceScopes.cs | Adds the Global/Local scope enum for rule matching. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Tracing/ActivityListenerBuilder.cs | Adds the listener builder type used by AddListener callbacks. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.csproj | Adds needed ref project references for the new tracing types. |
| src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.cs | Adds ref entries for the new tracing abstractions and extensions. |
| src/libraries/Common/src/System/ExceptionPolyfills.cs | Adds a downlevel polyfill for ArgumentException.ThrowIfNullOrEmpty. |
aecf70c to
ff45fb8
Compare
Member
Author
|
@copilot , there are comments demanding timeout for waiting, add the timeouts as suggested. |
This was referenced Jun 14, 2026
Open
| /// </summary> | ||
| /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> | ||
| /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
| public static IServiceCollection AddTracing(this IServiceCollection services) |
| /// <param name="version">The version of the <see cref="ActivitySource"/>.</param> | ||
| /// <param name="tags">The tags to associate with the <see cref="ActivitySource"/>.</param> | ||
| /// <returns>An <see cref="ActivitySource"/> with the specified <paramref name="name"/>, <paramref name="version"/>, and <paramref name="tags"/>.</returns> | ||
| public ActivitySource Create(string name, string? version = "", IEnumerable<KeyValuePair<string, object?>>? tags = null) |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements tracing configuration support with a builder-style API, aligned with the approved design in #100317.
Key changes in this PR:
AddTracingand tracing builder APIs inMicrosoft.Extensions.Diagnostics.EnableTracing/DisableTracing) with source, operation, listener, and scope matching.ActivitySourceFactoryand relatedActivitySource/ActivityListenerenhancements needed for factory-driven and refreshable listener behaviour.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.DiagnosticSourceMicrosoft.Extensions.DiagnosticsNote
This PR description was generated with GitHub Copilot assistance.