Skip to content

Initial implementation for workflow log tracing#1176

Merged
halspang merged 8 commits into
dapr:masterfrom
RyanLettieri:workflow-log-tracing
Nov 14, 2023
Merged

Initial implementation for workflow log tracing#1176
halspang merged 8 commits into
dapr:masterfrom
RyanLettieri:workflow-log-tracing

Conversation

@RyanLettieri
Copy link
Copy Markdown
Contributor

Description

Added in basic logging for workflow to log the registered activities and registered workflows.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[1170]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@RyanLettieri RyanLettieri requested review from a team as code owners October 25, 2023 20:18
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2332388) 66.42% compared to head (0bff075) 66.42%.

❗ Current head 0bff075 differs from pull request most recent head 71064cf. Consider uploading reports for the commit 71064cf to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1176   +/-   ##
=======================================
  Coverage   66.42%   66.42%           
=======================================
  Files         171      171           
  Lines        5758     5758           
  Branches      626      626           
=======================================
  Hits         3825     3825           
  Misses       1784     1784           
  Partials      149      149           
Flag Coverage Δ
net6 66.42% <ø> (ø)
net7 66.42% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread src/Dapr.Workflow/WorkflowLoggingService.cs Outdated
Comment thread src/Dapr.Workflow/WorkflowLoggingService.cs Outdated
Comment thread src/Dapr.Workflow/WorkflowLoggingService.cs Outdated
Comment thread src/Dapr.Workflow/WorkflowLoggingService.cs Outdated
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Comment thread src/Dapr.Workflow/WorkflowLoggingService.cs Outdated
Comment thread test/Dapr.E2E.Test.App/Program.cs
}
}
}
}, cts.Token);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this CancellationToken is only used if the Task has not yet already started, which it most likely has, so it's possible that the task never ends (in the case of not all expected logs being found).

You could use the async method Stream.ReadLineAsync(CancellationToken) to provide a means of abandoning the search when time expires. That would also allow you to avoid calling Task.WaitAll(), which is a synchronously-blocking method.

}
}, cts.Token);

if (!Task.WaitAll(new Task[] {searchTask}, timeout))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe hold off testing the result until after the log file has been deleted (rather than two deletion paths).

Copy link
Copy Markdown
Contributor

@halspang halspang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give some examples of what logs are output when we run a workflow?

Comment on lines +42 to +52
this.logger.Log(LogLevel.Information, "List of registered workflows");
foreach (string item in registeredWorkflows)
{
this.logger.Log(LogLevel.Information, item);
}

this.logger.Log(LogLevel.Information, "List of registered activities:");
foreach (string item in registeredActivities)
{
this.logger.Log(LogLevel.Information, item);
}
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.

Nit: Indentation is weird here.

/// <summary>
/// Defines runtime options for workflows.
/// </summary>
internal sealed class WorkflowLoggingService : IHostedService
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.

I'm not sure if hosted service is the right way to go here. I was thinking more that this would be injected into the various workflow runtime mechanics, like the context.

using (StreamReader reader = new StreamReader(logFilePath))
{
string line;
while ((line = await reader.ReadLineAsync()) != null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to pass the cancellation token to ReadLineAsync() so it will stop reading after the timeout.

finally
{
File.Delete(logFilePath);
if (!allLogsFound)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allLogsFound test should probably be outside/after the finally block; it doesn't need to be executed in the case of an exception (e.g. timeout) as the exception will bubble up and fail the test.

@halspang halspang merged commit 39a38f6 into dapr:master Nov 14, 2023
divzi-p pushed a commit to divzi-p/dotnet-sdk that referenced this pull request Dec 10, 2024
* Initial setup for workflow log tracing

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Created log sink for E2E tests using serilog

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Formatting

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Addressing feedback on review

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Addressing some review comments

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Addressing more feedbck in the workflow e2e test

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

---------

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Divya Perumal <diperuma@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase Logging Metrics for Workflow

3 participants