-
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 #551
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
Changes from all commits
0ece6f4
80b3351
9e2f167
6022cd9
7a7cf8a
950269e
57763f7
c862143
ec40f9f
aa7f0ad
2e02259
dcd6a1c
dd1fe75
bf8d1f3
f66b191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,20 @@ | |
| [Obsolete("Experimental")] | ||
| public IOrchestrationFilter? OrchestrationFilter { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets options for the Durable Task worker logging. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Logging options control how logging categories are assigned to different components of the worker. | ||
| /// Starting from a future version, more specific logging categories will be used for better log filtering. | ||
| /// </para><para> | ||
| /// To maintain backward compatibility, legacy logging categories are emitted by default alongside the new | ||
| /// categories. This can be disabled by setting <see cref="LoggingOptions.UseLegacyCategories" /> to false. | ||
| /// </para> | ||
| /// </remarks> | ||
| public LoggingOptions Logging { get; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether <see cref="DataConverter" /> was explicitly set or not. | ||
| /// </summary> | ||
|
|
@@ -161,7 +175,7 @@ | |
| /// behavior is consistently irrespective of option configuration ordering. | ||
| /// </remarks> | ||
| internal bool DataConverterExplicitlySet { get; private set; } | ||
|
|
||
|
Check warning on line 178 in src/Worker/Core/DurableTaskWorkerOptions.cs
|
||
|
|
||
| /// <summary> | ||
| /// Applies these option values to another. | ||
|
|
@@ -176,7 +190,8 @@ | |
| other.MaximumTimerInterval = this.MaximumTimerInterval; | ||
| other.EnableEntitySupport = this.EnableEntitySupport; | ||
| other.Versioning = this.Versioning; | ||
| other.OrchestrationFilter = this.OrchestrationFilter; | ||
|
Check warning on line 193 in src/Worker/Core/DurableTaskWorkerOptions.cs
|
||
| other.Logging.UseLegacyCategories = this.Logging.UseLegacyCategories; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -229,4 +244,51 @@ | |
| /// </remarks> | ||
| public VersionFailureStrategy FailureStrategy { get; set; } = VersionFailureStrategy.Reject; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Options for the Durable Task worker logging. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// These options control how logging categories are assigned to different components of the worker. | ||
| /// Starting from a future version, more specific logging categories will be used for better log filtering: | ||
| /// <list type="bullet"> | ||
| /// <item><description><c>Microsoft.DurableTask.Worker.Grpc</c> for gRPC worker logs (previously <c>Microsoft.DurableTask</c>)</description></item> | ||
| /// <item><description><c>Microsoft.DurableTask.Worker.*</c> for worker-specific logs</description></item> | ||
| /// </list> | ||
| /// </para><para> | ||
| /// To maintain backward compatibility, legacy logging categories are emitted by default alongside the new | ||
| /// categories until a future major release. This ensures existing log filters continue to work. | ||
| /// </para><para> | ||
| /// <b>Migration Path:</b> | ||
| /// <list type="number"> | ||
| /// <item><description>Update your log filters to use the new, more specific categories</description></item> | ||
| /// <item><description>Test your application to ensure logs are captured correctly</description></item> | ||
| /// <item><description>Once confident, set <see cref="UseLegacyCategories" /> to <c>false</c> to disable legacy category emission</description></item> | ||
| /// </list> | ||
| /// </para> | ||
| /// </remarks> | ||
| public class LoggingOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether to emit logs using legacy logging categories in addition to new categories. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// When <c>true</c> (default), logs are emitted to both the new specific categories (e.g., <c>Microsoft.DurableTask.Worker.Grpc</c>) | ||
| /// and the legacy broad categories (e.g., <c>Microsoft.DurableTask</c>). This ensures backward compatibility with existing | ||
| /// log filters and queries. | ||
| /// </para><para> | ||
| /// When <c>false</c>, logs are only emitted to the new specific categories, which provides better log organization | ||
| /// and filtering capabilities. | ||
| /// </para><para> | ||
| /// <b>Default:</b> <c>true</c> (legacy categories are enabled for backward compatibility) | ||
|
Check warning on line 285 in src/Worker/Core/DurableTaskWorkerOptions.cs
|
||
| /// </para><para> | ||
| /// <b>Breaking Change Warning:</b> Setting this to <c>false</c> is a breaking change if you have existing log filters, | ||
| /// queries, or monitoring rules that depend on the legacy category names. Ensure you update those before disabling | ||
| /// legacy categories. | ||
| /// </para> | ||
| /// </remarks> | ||
| public bool UseLegacyCategories { get; set; } = true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // 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() | ||
| { | ||
| this.first.Dispose(); | ||
| this.second.Dispose(); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.