Skip to content

Commit 32be62b

Browse files
authored
Port update DiagnosticSource to 5.0.0 (#5140) (#5156)
* Update System.Diagnostics.DiagnosticSource - Update to use the latest 5.0.0 version which supports all targets. * Implement IDisposable * Includes fixes to point in time tests due to different transport namespace.
1 parent 85c0854 commit 32be62b

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/Elastic.Transport/Diagnostics/Diagnostic.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public Diagnostic(string operationName, DiagnosticSource source, TState state)
1818
EndState = state;
1919
}
2020

21-
internal class Diagnostic<TState, TStateEnd> : Activity, IDisposable
21+
internal class Diagnostic<TState, TStateEnd> : Activity
2222
{
2323
public static Diagnostic<TState, TStateEnd> Default { get; } = new Diagnostic<TState, TStateEnd>();
2424

2525
private readonly DiagnosticSource _source;
2626
private TStateEnd _endState;
2727
private readonly bool _default;
28+
private bool _disposed;
2829

2930
private Diagnostic() : base("__NOOP__") => _default = true;
3031

@@ -45,8 +46,19 @@ internal set
4546
}
4647
}
4748

49+
protected override void Dispose(bool disposing)
50+
{
51+
if (_disposed) return;
52+
53+
if (disposing)
54+
{
55+
//_source can be null if Default instance
56+
_source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
57+
}
58+
59+
_disposed = true;
4860

49-
//_source can be null if Default instance
50-
public void Dispose() => _source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
61+
base.Dispose(disposing);
62+
}
5163
}
5264
}

src/Elastic.Transport/Elastic.Transport.csproj

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
<TargetFrameworks>netstandard2.0;netstandard2.1;net461</TargetFrameworks>
1616
</PropertyGroup>
1717
<ItemGroup>
18-
1918
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
20-
<PackageReference Include="System.Buffers" Version="4.5.0" />
21-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
19+
<PackageReference Include="System.Buffers" Version="4.5.1" />
20+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
2221
<PackageReference Include="System.Text.Json" Version="4.7.1" />
23-
2422
</ItemGroup>
2523

2624
</Project>

tests/Tests.ScratchPad/Tests.ScratchPad.csproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
<Optimize>true</Optimize>
66
<DebugSymbols>true</DebugSymbols>
77
</PropertyGroup>
8+
89
<ItemGroup>
9-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
1010
<ProjectReference Include="..\Tests.Core\Tests.Core.csproj" />
11-
<PackageReference Include="BenchMarkDotNet" Version="0.11.5" />
1211
</ItemGroup>
13-
</Project>
12+
13+
<ItemGroup>
14+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
15+
<PackageReference Include="BenchMarkDotNet" Version="0.12.1" />
16+
</ItemGroup>
17+
</Project>

tests/Tests/Search/PointInTime/Close/ClosePointInTimeApiTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System;
66
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7-
using Elasticsearch.Net;
7+
using Elastic.Transport;
88
using FluentAssertions;
99
using Nest;
1010
using Tests.Core.Extensions;

tests/Tests/Search/PointInTime/Open/OpenPointInTimeApiTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System;
66
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7-
using Elasticsearch.Net;
7+
using Elastic.Transport;
88
using FluentAssertions;
99
using Nest;
1010
using Tests.Core.ManagedElasticsearch.Clusters;

0 commit comments

Comments
 (0)