Skip to content

Commit 70d8eab

Browse files
committed
metrics should listen to MetricsEnabled not TraceEnabled cc @crunchie84
1 parent 1638c66 commit 70d8eab

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Elasticsearch.Net/Connection/RequestState/TransportRequestState.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Elasticsearch.Net.Connection.RequestState
1313
public class TransportRequestState<T> : IDisposable, ITransportRequestState
1414
{
1515
private readonly bool _traceEnabled;
16+
private readonly bool _metricsEnabled;
17+
1618
private Stopwatch _stopwatch;
1719

1820
private ElasticsearchResponse<T> _result;
@@ -91,8 +93,9 @@ public TransportRequestState(
9193
this.ClientSettings = settings;
9294
this.RequestParameters = requestParameters;
9395
this._traceEnabled = settings.TraceEnabled;
94-
if (this._traceEnabled)
95-
this._stopwatch = Stopwatch.StartNew(); this.Method = method;
96+
this._metricsEnabled = settings.MetricsEnabled;
97+
if (this._metricsEnabled)
98+
this._stopwatch = Stopwatch.StartNew();
9699

97100
this.Method = method;
98101
this.Path = path;
@@ -107,7 +110,7 @@ public TransportRequestState(
107110
public void TickSerialization(byte[] postData)
108111
{
109112
this.PostData = postData;
110-
if (this._traceEnabled)
113+
if (this._metricsEnabled)
111114
this.SerializationTime = this._stopwatch.ElapsedMilliseconds;
112115
}
113116

@@ -139,8 +142,7 @@ public void SetResult(ElasticsearchResponse<T> result)
139142
{
140143
if (result == null)
141144
{
142-
if (!_traceEnabled) return;
143-
this._stopwatch.Stop();
145+
if (this._stopwatch != null) this._stopwatch.Stop();
144146
return;
145147
}
146148
result.NumberOfRetries = this.Retried;
@@ -160,11 +162,12 @@ public void SetResult(ElasticsearchResponse<T> result)
160162

161163
if (this.ClientSettings.ConnectionStatusHandler != null)
162164
this.ClientSettings.ConnectionStatusHandler(result);
165+
166+
if (this._stopwatch != null) this._stopwatch.Stop();
163167

164168
if (!_traceEnabled) return;
165169

166170
this._result = result;
167-
this._stopwatch.Stop();
168171

169172
}
170173

0 commit comments

Comments
 (0)