-
Notifications
You must be signed in to change notification settings - Fork 361
Adds workflow replay-safe logger #1434
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
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4404175
Removed obsolete type
WhitWaldo 662b620
Added missing using
WhitWaldo cf876c0
Adding interface for IWorkflowContext for replayability concerns
WhitWaldo be5340a
Removed unused IConfiguration
WhitWaldo fcdeadf
Added ReplaySafeLogger type
WhitWaldo bcea844
Building out functionality to expose ReplayLogger in workflow context
WhitWaldo 0a871f5
Added license information to file
WhitWaldo 2a77908
Removed unnecessary file
WhitWaldo 1d11d40
Updated copyright header for different project, made some tweaks for …
WhitWaldo ed19f04
Added virtual methods that use the already-available ILoggerFactory t…
WhitWaldo 04a77a2
Removed unnecessary registration
WhitWaldo 283e98d
Updated example to demonstrate using ReplaySafeLogger in the orchestr…
WhitWaldo 182d58e
Tweaks on visibility and abstraction so that the methods are availabl…
WhitWaldo 5f4a41b
Merge branch 'workflow-replay-logger' into workflow-logger
WhitWaldo 3d6641e
Removed obsolete type registrations
WhitWaldo 78ad0da
Simplified argument null check
WhitWaldo 1d3f06f
Removed since-removed code leftover from merge
WhitWaldo 4f32540
Added documentation demonstrating how to access the replay-safe logger
WhitWaldo 53da1d8
Removed unnecessary and separate ReplaySafeLogger in favor of method …
WhitWaldo 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
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,21 @@ | ||
| namespace Dapr.Workflow; | ||
|
|
||
| /// <summary> | ||
| /// Provides functionality available to orchestration code. | ||
| /// </summary> | ||
| public interface IWorkflowContext | ||
| { | ||
| /// <summary> | ||
| /// Gets a value indicating whether the orchestration or operation is currently replaying itself. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This property is useful when there is logic that needs to run only when *not* replaying. For example, | ||
| /// certain types of application logging may become too noisy when duplicated as part of replay. The | ||
| /// application code could check to see whether the function is being replayed and then issue | ||
| /// the log statements when this value is <c>false</c>. | ||
| /// </remarks> | ||
| /// <value> | ||
| /// <c>true</c> if the orchestration or operation is currently being replayed; otherwise <c>false</c>. | ||
| /// </value> | ||
| bool IsReplaying { get; } | ||
| } |
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,50 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // Copyright 2024 The Dapr Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License at | ||
| // https://github.com/microsoft/durabletask-dotnet/blob/main/LICENSE | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Dapr.Workflow; | ||
|
|
||
| internal class ReplaySafeLogger : ILogger | ||
| { | ||
| private readonly IWorkflowContext context; | ||
| private readonly ILogger logger; | ||
|
|
||
| public ReplaySafeLogger(IWorkflowContext context, ILogger logger) | ||
| { | ||
| this.context = context ?? throw new ArgumentNullException(nameof(context)); | ||
| this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| } | ||
|
|
||
| IDisposable ILogger.BeginScope<TState>(TState state) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(state, nameof(state)); | ||
| return this.logger.BeginScope<TState>(state)!; | ||
| } | ||
|
|
||
| public bool IsEnabled(LogLevel logLevel) => this.logger.IsEnabled(logLevel); | ||
|
|
||
| public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, | ||
| Func<TState, Exception?, string> formatter) | ||
| { | ||
| if (!this.context.IsReplaying) | ||
| { | ||
| this.logger.Log(logLevel, eventId, state, exception, formatter); | ||
| } | ||
| } | ||
| } |
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 was deleted.
Oops, something went wrong.
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.