Skip to content

Commit

Permalink
remove redundant instrumentations != null checks (open-telemetry#6091)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
  • Loading branch information
SimonCropp and rajkumar-rangaraj authored Feb 6, 2025
1 parent 36b777b commit c99f9a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
11 changes: 4 additions & 7 deletions src/OpenTelemetry/Logs/LoggerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

// Wait for up to 5 seconds grace period
this.Processor?.Shutdown(5000);
this.Processor?.Dispose();
Expand Down
11 changes: 4 additions & 7 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

// Wait for up to 5 seconds grace period
this.reader?.Shutdown(5000);
this.reader?.Dispose();
Expand Down
25 changes: 9 additions & 16 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,14 @@ internal bool OnForceFlush(int timeoutMilliseconds)
internal bool OnShutdown(int timeoutMilliseconds)
{
// TO DO Put OnShutdown logic in a task to run within the user provider timeOutMilliseconds
bool? result;
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

result = this.processor?.Shutdown(timeoutMilliseconds);
this.instrumentations.Clear();

bool? result = this.processor?.Shutdown(timeoutMilliseconds);
this.listener?.Dispose();
return result ?? true;
}
Expand All @@ -374,16 +370,13 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.instrumentations != null)
foreach (var item in this.instrumentations)
{
foreach (var item in this.instrumentations)
{
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();
(item as IDisposable)?.Dispose();
}

this.instrumentations.Clear();

(this.sampler as IDisposable)?.Dispose();

// Wait for up to 5 seconds grace period
Expand Down

0 comments on commit c99f9a1

Please sign in to comment.