1414
1515using Microsoft . Rest ;
1616using Microsoft . WindowsAzure . Commands . Common ;
17+ using Microsoft . WindowsAzure . Commands . Common . Extensions ;
1718using Microsoft . WindowsAzure . Commands . Utilities . Common ;
1819using System ;
1920using System . Collections . Concurrent ;
@@ -24,16 +25,19 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common
2425{
2526 public class ServiceClientTracingInterceptor : IServiceClientTracingInterceptor
2627 {
27- public ServiceClientTracingInterceptor ( ConcurrentQueue < string > queue , IList < Regex > matchers = null )
28+ public ServiceClientTracingInterceptor ( ConcurrentQueue < string > queue , IList < Regex > matchers = null , string clientRequestId = null )
2829 {
2930 MessageQueue = queue ;
3031 Matchers = matchers ;
32+ this . clientRequestId = clientRequestId ;
3133 }
3234
3335 public ConcurrentQueue < string > MessageQueue { get ; private set ; }
3436
3537 private IList < Regex > Matchers { get ; set ; }
3638
39+ private string clientRequestId ;
40+
3741 public void Configuration ( string source , string name , string value )
3842 {
3943 // Ignore
@@ -62,8 +66,13 @@ public void ReceiveResponse(string invocationId, System.Net.Http.HttpResponseMes
6266
6367 public void SendRequest ( string invocationId , System . Net . Http . HttpRequestMessage request )
6468 {
65- string requestAsString = request == null ? string . Empty : GeneralUtilities . GetLog ( request , Matchers ) ;
66- MessageQueue . CheckAndEnqueue ( requestAsString ) ;
69+ // CmdletInfoHandler sets/updates x-ms-client-request-id during SendAsync() no matter if SDK sets x-ms-client-request-id.
70+ // Update request here to ensure its value consistent with real result.
71+ if ( request != null && clientRequestId != null )
72+ {
73+ request . AddClientRequestId ( clientRequestId ) ;
74+ }
75+ MessageQueue . CheckAndEnqueue ( GeneralUtilities . GetLog ( request , Matchers ) ) ;
6776 }
6877
6978 public void TraceError ( string invocationId , Exception exception )
0 commit comments