-
Notifications
You must be signed in to change notification settings - Fork 53
Add specific logging categories for Worker.Grpc and orchestration logs with backward-compatible opt-in #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+455
−4
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b5631c
Initial plan
Copilot 4f48371
Investigate and understand test failure caused by dual-category logging
Copilot c2f2f66
Fix test failure: update GetLogs() to use specific category to avoid …
Copilot 2429a1f
Simplify comment in GetLogs method
Copilot b2b04ee
Improve exception handling in CompositeDisposable.Dispose
Copilot dadaee9
Improve integration tests to verify actual worker logger type via ref…
Copilot 498c904
Extract reflection helper methods to reduce code duplication in tests
Copilot 9cc7afd
Consolidate LoggingOptions docs and remove useless test
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DurableTask.Worker.Grpc; | ||
|
|
||
| /// <summary> | ||
| /// A logger wrapper that emits logs to both a primary (new) category and an optional legacy category. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This logger is used to maintain backward compatibility while transitioning to more specific logging categories. | ||
| /// When legacy categories are enabled, log messages are written to both the new specific category | ||
| /// (e.g., "Microsoft.DurableTask.Worker.Grpc") and the legacy broad category (e.g., "Microsoft.DurableTask"). | ||
| /// </remarks> | ||
| sealed class DualCategoryLogger : ILogger | ||
| { | ||
| readonly ILogger primaryLogger; | ||
| readonly ILogger? legacyLogger; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="DualCategoryLogger"/> class. | ||
| /// </summary> | ||
| /// <param name="primaryLogger">The primary logger with the new category.</param> | ||
| /// <param name="legacyLogger">The optional legacy logger with the old category.</param> | ||
| public DualCategoryLogger(ILogger primaryLogger, ILogger? legacyLogger) | ||
| { | ||
| this.primaryLogger = Check.NotNull(primaryLogger); | ||
| this.legacyLogger = legacyLogger; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public IDisposable? BeginScope<TState>(TState state) | ||
| where TState : notnull | ||
| { | ||
| IDisposable? primaryScope = this.primaryLogger.BeginScope(state); | ||
| IDisposable? legacyScope = this.legacyLogger?.BeginScope(state); | ||
|
|
||
| if (primaryScope is not null && legacyScope is not null) | ||
| { | ||
| return new CompositeDisposable(primaryScope, legacyScope); | ||
| } | ||
|
|
||
| return primaryScope ?? legacyScope; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool IsEnabled(LogLevel logLevel) | ||
| { | ||
| // Return true if either logger is enabled at this level | ||
| return this.primaryLogger.IsEnabled(logLevel) || | ||
| (this.legacyLogger?.IsEnabled(logLevel) ?? false); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Log<TState>( | ||
| LogLevel logLevel, | ||
| EventId eventId, | ||
| TState state, | ||
| Exception? exception, | ||
| Func<TState, Exception?, string> formatter) | ||
| { | ||
| // Log to primary logger | ||
| if (this.primaryLogger.IsEnabled(logLevel)) | ||
| { | ||
| this.primaryLogger.Log(logLevel, eventId, state, exception, formatter); | ||
| } | ||
|
|
||
| // Log to legacy logger if enabled | ||
| if (this.legacyLogger?.IsEnabled(logLevel) ?? false) | ||
| { | ||
| this.legacyLogger.Log(logLevel, eventId, state, exception, formatter); | ||
| } | ||
| } | ||
|
|
||
| sealed class CompositeDisposable : IDisposable | ||
| { | ||
| readonly IDisposable first; | ||
| readonly IDisposable second; | ||
|
|
||
| public CompositeDisposable(IDisposable first, IDisposable second) | ||
| { | ||
| this.first = first; | ||
| this.second = second; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Exception? firstException = null; | ||
|
|
||
| try | ||
| { | ||
| this.first.Dispose(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| firstException = ex; | ||
| } | ||
|
Comment on lines
+95
to
+98
|
||
|
|
||
| try | ||
| { | ||
| this.second.Dispose(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| if (firstException is null) | ||
| { | ||
| throw; | ||
| } | ||
|
|
||
| throw new AggregateException(firstException, ex); | ||
| } | ||
|
|
||
| if (firstException is not null) | ||
| { | ||
| throw firstException; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.