-
Notifications
You must be signed in to change notification settings - Fork 896
Added correlation id #5289
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: user/sanjuyadav/logging_enhancement
Are you sure you want to change the base?
Added correlation id #5289
Conversation
/azp run |
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
f97c494
to
b99594d
Compare
721cf65
to
1ef9d65
Compare
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
Enhances agent logging with correlation IDs and operation context to improve traceability during job/task execution. The feature is controlled by the AZP_USE_ENHANCED_LOGGING
environment variable and maintains backward compatibility.
- Introduces EnhancedTracing implementation with formatted log messages containing correlation and operation tags
- Adds ambient correlation context using AsyncLocal to track step and task IDs across execution flows
- Implements runtime switching between standard and enhanced tracing through a proxy pattern
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/Test/L0/EnhancedTracingL0.cs | Adds unit tests for enhanced tracing functionality and correlation formatting |
src/Microsoft.VisualStudio.Services.Agent/Tracing.cs | Removes unused _componentName field from base Tracing class |
src/Microsoft.VisualStudio.Services.Agent/TraceManager.cs | Adds whitespace formatting |
src/Microsoft.VisualStudio.Services.Agent/EnhancedTracing.cs | Implements correlation ID formatting and ambient context management |
src/Agent.Worker/TaskManager.cs | Integrates task-level correlation context setting/clearing |
src/Agent.Worker/StepsRunner.cs | Integrates step-level correlation context and fixes boolean comparison |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
353e472
to
9827c3d
Compare
@@ -58,6 +58,7 @@ public TraceManager(HostTraceListener traceListener, TraceSetting traceSetting, | |||
|
|||
public SourceSwitch Switch { get; private set; } | |||
|
|||
|
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.
Small nit-pick here. This extra line can be removed. Just to keep the code clean.
} | ||
|
||
// Ambient correlation context for enhanced logs only | ||
public static class EnhancedCorrelationContext |
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.
instead of static class can we make it part of ExecutionContext and use it from there makes the design more clear.
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.
setting via this method, it can be used anywhere in listener/worker if we want to attach any process/class with a correlationid but with execution context it will be available only in worker
but as jobid/stepid all are on worker side attached with execution context it can be moved to execution context
will check and update accordingly
aac63d5
to
a3f1490
Compare
Context
Enhance agent logging with operation context and safe correlation to improve diagnosability during job/task execution. Enables quickly tracing task lifecycle (download/extract/run) without verbose logs.
Description
Add enhanced tracing pathway that formats log lines with operation and optional correlation tags.
Risk Assessment (Low / Medium / High)
Low: change is behind an environment knob; default behavior unchanged.
Core logging paths touched but continue using existing masking and listeners.
Rollback is trivial by disabling the knob.
Unit Tests Added or Updated (Yes / No)
L0 tests for TraceManager startup/runtime switching and proxy stability.
Additional Testing Performed
Manual smoke with local agent run; Worker logs show enriched tags:
Example: [TASK-…] [DownloadAsync] …, [GetDirectory] … (see Worker_20250811-121852-utc.log excerpt).
[2025-08-11 12:18:53Z INFO TaskManager] [TASK-6d15af64-176c-496d-b583-fd2ae21d4df4] [DownloadAsync] Skip download checkout task. [2025-08-11 12:18:53Z VERB TaskManager] [TASK-ae214784-0f5e-451f-b615-042bce65d833] [DownloadAsync] Entering DownloadAsync
Change Behind Feature Flag (Yes / No)
Enabled by environment knob: AZP_USE_ENHANCED_LOGGING. Default is off.
Tech Design / Approach
Implement EnhancedTracing with formatting and a Tracing proxy to swap implementations at runtime without changing call sites.
Respect component-specific SourceSwitch levels; no change to listener lifecycle.
Safe correlation tags sourced from execution contexts (e.g., task/job identifiers) where available.
Documentation Changes Required (Yes/No)
No
Logging Added/Updated (Yes/No)
Yes
Telemetry Added/Updated (Yes/No)
No
Rollback Scenario and Process (Yes/No)
Disable AZP_USE_ENHANCED_LOGGING to revert to standard formatting.
Full rollback: revert this PR; no data migration required.
Dependency Impact Assessed and Regression Tested (Yes/No)
Yes