-
Notifications
You must be signed in to change notification settings - Fork 53
Add durable instance-id logging scopes for orchestrations and activities #598
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses issue #250 by adding automatic instance-id logging scopes to orchestration and activity executions in Durable Task. Previously, users had to manually create logging scopes containing the instance ID in each orchestrator and activity to correlate logs in Application Insights.
Key changes:
- Logging scopes wrapping orchestrator execution with
InstanceIdinTaskOrchestrationShim.Execute - Logging scopes wrapping activity execution with
InstanceIdinTaskActivityShim.RunAsync - Unit tests validating that instance-id scopes are properly applied
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Worker/Core/Shims/TaskOrchestrationShim.cs | Wraps orchestration execution in a logger scope containing the InstanceId, ensuring all logs during orchestration have the instance context |
| src/Worker/Core/Shims/TaskActivityShim.cs | Wraps activity execution in a logger scope containing the InstanceId, ensuring all logs during activity have the instance context |
| test/Worker/Core.Tests/Shims/TaskShimLoggingScopeTests.cs | Adds comprehensive unit tests verifying that both orchestration and activity shims properly create logging scopes with the correct InstanceId |
| } | ||
| } | ||
|
|
||
| class TestOrchestrationContext : OrchestrationContext |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, all private classes that do not serve as base classes should be sealed. The TestOrchestrationContext class should be declared as sealed since it's a private helper class and doesn't serve as a base class.
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Converters; | ||
| using Microsoft.DurableTask.Worker; | ||
| using Microsoft.DurableTask.Worker.Shims; |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate namespace declaration. The namespace is already declared on line 7 (using Microsoft.DurableTask.Worker.Shims). This duplicate declaration should be removed as it's redundant and could cause confusion.
| using Microsoft.DurableTask.Worker.Shims; |
| scopeState!.Should().ContainKey("InstanceId").WhoseValue.Should().Be(instanceId); | ||
| } | ||
|
|
||
| class TestActivity : TaskActivity<string, string> |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, all private classes that do not serve as base classes should be sealed. The TestActivity class should be declared as sealed since it's a private helper class and doesn't serve as a base class.
| } | ||
| } | ||
|
|
||
| class TestOrchestrator : TaskOrchestrator<string, string> |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, all private classes that do not serve as base classes should be sealed. The TestOrchestrator class should be declared as sealed since it's a private helper class and doesn't serve as a base class.
Durable Functions logs lacked automatic instance-id scoping, making correlation across orchestrators and activities cumbersome.
Logging scopes
InstanceId.Tests
InstanceIdfor orchestrations and activities.Example scope usage now applied automatically:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.