44using System . IO ;
55using System . Linq ;
66using System . Text ;
7+ using System . Threading ;
78using Elasticsearch . Net . Connection . Configuration ;
89using Elasticsearch . Net . ConnectionPool ;
910using PurifyNet ;
1011
1112namespace Elasticsearch . Net . Connection . RequestState
1213{
14+ internal static class TransportRequestState
15+ {
16+ private static long _requestId = 0 ;
17+ public static long RequestId {
18+ get
19+ {
20+ var r = Interlocked . Increment ( ref _requestId ) ;
21+ return r ;
22+ }
23+ }
24+ }
25+
1326 public class TransportRequestState < T > : IDisposable , ITransportRequestState
1427 {
1528 private readonly bool _traceEnabled ;
1629 private readonly bool _metricsEnabled ;
30+ private readonly long _requestId ;
1731
1832 private Stopwatch _stopwatch ;
1933
@@ -87,6 +101,7 @@ public TransportRequestState(
87101 string method ,
88102 string path )
89103 {
104+ this . _requestId = TransportRequestState . RequestId ;
90105 this . StartedOn = DateTime . UtcNow ;
91106 this . SeenNodes = new List < Uri > ( ) ;
92107 this . SeenExceptions = new List < Exception > ( ) ;
@@ -95,7 +110,16 @@ public TransportRequestState(
95110 this . _traceEnabled = settings . TraceEnabled ;
96111 this . _metricsEnabled = settings . MetricsEnabled ;
97112 if ( this . _metricsEnabled || this . _traceEnabled )
98- this . _stopwatch = Stopwatch . StartNew ( ) ;
113+ this . _stopwatch = Stopwatch . StartNew ( ) ;
114+
115+ if ( this . _traceEnabled )
116+ {
117+ Trace . TraceInformation ( "NEST start:{0} {1} {2}"
118+ , this . _requestId
119+ , _result . RequestMethod
120+ , _result . RequestUrl
121+ ) ;
122+ }
99123
100124 this . Method = method ;
101125 this . Path = path ;
@@ -179,7 +203,8 @@ public void Dispose()
179203
180204 if ( _result . Success )
181205 {
182- Trace . TraceInformation ( "NEST {0} {1} ({2}):\r \n {3}"
206+ Trace . TraceInformation ( "NEST end:{0} {1} {2} ({3}):\r \n {4}"
207+ , this . _requestId
183208 , _result . RequestMethod
184209 , _result . RequestUrl
185210 , _stopwatch . Elapsed
@@ -189,7 +214,8 @@ public void Dispose()
189214 else
190215 {
191216 Trace . TraceError (
192- "NEST {0} {1} ({2}):\r \n {3}"
217+ "NEST end:{0} {1} {2} ({3}):\r \n {4}"
218+ , this . _requestId
193219 , _result . RequestMethod
194220 , _result . RequestUrl
195221 , _stopwatch . Elapsed
0 commit comments