Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Elasticsearch.Net/Diagnostics/Diagnostic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public Diagnostic(string operationName, DiagnosticSource source, TState state)
EndState = state;
}

internal class Diagnostic<TState, TStateEnd> : Activity, IDisposable
internal class Diagnostic<TState, TStateEnd> : Activity
{
public static Diagnostic<TState, TStateEnd> Default { get; } = new Diagnostic<TState, TStateEnd>();
public static Diagnostic<TState, TStateEnd> Default { get; } = new();

private readonly DiagnosticSource _source;
private TStateEnd _endState;
private readonly bool _default;
private bool _disposed;

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

Expand All @@ -44,9 +45,20 @@ internal set
_endState = value;
}
}

protected override void Dispose(bool disposing)
{
if (_disposed) return;

if (disposing)
{
//_source can be null if Default instance
_source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
}

//_source can be null if Default instance
public void Dispose() => _source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
_disposed = true;

base.Dispose(disposing);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Elasticsearch.Net/Elasticsearch.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />

<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
Expand Down
8 changes: 6 additions & 2 deletions tests/Tests.ScratchPad/Tests.ScratchPad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<Optimize>true</Optimize>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
<ProjectReference Include="..\Tests.Core\Tests.Core.csproj" />
<PackageReference Include="BenchMarkDotNet" Version="0.11.5" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
<PackageReference Include="BenchMarkDotNet" Version="0.12.1" />
</ItemGroup>
</Project>