Skip to content

Commit c99f9a1

Browse files
remove redundant instrumentations != null checks (#6091)
Co-authored-by: Rajkumar Rangaraj <[email protected]>
1 parent 36b777b commit c99f9a1

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

src/OpenTelemetry/Logs/LoggerProviderSdk.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,13 @@ protected override void Dispose(bool disposing)
217217
{
218218
if (disposing)
219219
{
220-
if (this.instrumentations != null)
220+
foreach (var item in this.instrumentations)
221221
{
222-
foreach (var item in this.instrumentations)
223-
{
224-
(item as IDisposable)?.Dispose();
225-
}
226-
227-
this.instrumentations.Clear();
222+
(item as IDisposable)?.Dispose();
228223
}
229224

225+
this.instrumentations.Clear();
226+
230227
// Wait for up to 5 seconds grace period
231228
this.Processor?.Shutdown(5000);
232229
this.Processor?.Dispose();

src/OpenTelemetry/Metrics/MeterProviderSdk.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,13 @@ protected override void Dispose(bool disposing)
451451
{
452452
if (disposing)
453453
{
454-
if (this.instrumentations != null)
454+
foreach (var item in this.instrumentations)
455455
{
456-
foreach (var item in this.instrumentations)
457-
{
458-
(item as IDisposable)?.Dispose();
459-
}
460-
461-
this.instrumentations.Clear();
456+
(item as IDisposable)?.Dispose();
462457
}
463458

459+
this.instrumentations.Clear();
460+
464461
// Wait for up to 5 seconds grace period
465462
this.reader?.Shutdown(5000);
466463
this.reader?.Dispose();

src/OpenTelemetry/Trace/TracerProviderSdk.cs

+9-16
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,14 @@ internal bool OnForceFlush(int timeoutMilliseconds)
352352
internal bool OnShutdown(int timeoutMilliseconds)
353353
{
354354
// TO DO Put OnShutdown logic in a task to run within the user provider timeOutMilliseconds
355-
bool? result;
356-
if (this.instrumentations != null)
355+
foreach (var item in this.instrumentations)
357356
{
358-
foreach (var item in this.instrumentations)
359-
{
360-
(item as IDisposable)?.Dispose();
361-
}
362-
363-
this.instrumentations.Clear();
357+
(item as IDisposable)?.Dispose();
364358
}
365359

366-
result = this.processor?.Shutdown(timeoutMilliseconds);
360+
this.instrumentations.Clear();
361+
362+
bool? result = this.processor?.Shutdown(timeoutMilliseconds);
367363
this.listener?.Dispose();
368364
return result ?? true;
369365
}
@@ -374,16 +370,13 @@ protected override void Dispose(bool disposing)
374370
{
375371
if (disposing)
376372
{
377-
if (this.instrumentations != null)
373+
foreach (var item in this.instrumentations)
378374
{
379-
foreach (var item in this.instrumentations)
380-
{
381-
(item as IDisposable)?.Dispose();
382-
}
383-
384-
this.instrumentations.Clear();
375+
(item as IDisposable)?.Dispose();
385376
}
386377

378+
this.instrumentations.Clear();
379+
387380
(this.sampler as IDisposable)?.Dispose();
388381

389382
// Wait for up to 5 seconds grace period

0 commit comments

Comments
 (0)