Skip to content

Conversation

sanjuyadav24
Copy link
Contributor

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

@sanjuyadav24
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@sanjuyadav24 sanjuyadav24 force-pushed the user/sanjuyadav/logging_enhancement branch from f97c494 to b99594d Compare August 20, 2025 18:42
@sanjuyadav24 sanjuyadav24 force-pushed the user/sanjuyadav/logging_enhancement_1 branch from 721cf65 to 1ef9d65 Compare August 20, 2025 18:48
@sanjuyadav24 sanjuyadav24 requested a review from Copilot August 20, 2025 18:49
Copy link

@Copilot Copilot AI left a 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.

@rishabhmalikMS rishabhmalikMS force-pushed the user/sanjuyadav/logging_enhancement branch from 353e472 to 9827c3d Compare August 25, 2025 08:26
@@ -58,6 +58,7 @@ public TraceManager(HostTraceListener traceListener, TraceSetting traceSetting,

public SourceSwitch Switch { get; private set; }


Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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

@sanjuyadav24 sanjuyadav24 force-pushed the user/sanjuyadav/logging_enhancement branch 3 times, most recently from aac63d5 to a3f1490 Compare September 2, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants