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,17 @@ 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}:\r \n {3}"
118+ , this . _requestId
119+ , _result . RequestMethod
120+ , _result . RequestUrl
121+ , _result
122+ ) ;
123+ }
99124
100125 this . Method = method ;
101126 this . Path = path ;
@@ -179,7 +204,8 @@ public void Dispose()
179204
180205 if ( _result . Success )
181206 {
182- Trace . TraceInformation ( "NEST {0} {1} ({2}):\r \n {3}"
207+ Trace . TraceInformation ( "NEST end:{0} {1} {2} ({3}):\r \n {4}"
208+ , this . _requestId
183209 , _result . RequestMethod
184210 , _result . RequestUrl
185211 , _stopwatch . Elapsed
@@ -189,7 +215,8 @@ public void Dispose()
189215 else
190216 {
191217 Trace . TraceError (
192- "NEST {0} {1} ({2}):\r \n {3}"
218+ "NEST end:{0} {1} {2} ({3}):\r \n {4}"
219+ , this . _requestId
193220 , _result . RequestMethod
194221 , _result . RequestUrl
195222 , _stopwatch . Elapsed
0 commit comments