Fix double shutdown (#1017)

* fix double shutdown

* add consistency

* nit
This commit is contained in:
Reiley Yang 2020-08-07 10:36:27 -07:00 committed by GitHub
parent 1b01f3c98e
commit e43356abd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 31 additions and 43 deletions

View File

@ -11,7 +11,7 @@
Please sort alphabetically.
Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax.
-->
<OpenTelemetryPkgVer>[0.4.0-beta.2,1.0)</OpenTelemetryPkgVer>
<OpenTelemetryExporterConsolePkgVer>[0.4.0-beta.2,1.0)</OpenTelemetryExporterConsolePkgVer>
<OpenTelemetryPkgVer>[0.4.0-beta.2,1.0)</OpenTelemetryPkgVer>
</PropertyGroup>
</Project>

View File

@ -16,7 +16,6 @@
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
public class Program
{

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using System;
using OpenTelemetry.Trace;
internal static class TracerProviderExtensions

View File

@ -38,6 +38,7 @@ public class Program
{
activity?.SetTag("foo", 1);
activity?.SetTag("bar", "Hello, World!");
activity?.SetTag("baz", new int[] { 1, 2, 3 });
}
}
}

View File

@ -30,9 +30,8 @@ public class Program
new string[]
{
"MyCompany.MyProduct.MyLibrary",
});
tracerProvider.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())));
})
.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())));
using (var activity = MyActivitySource.StartActivity("SayHello"))
{

View File

@ -15,7 +15,6 @@
// </copyright>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

View File

@ -20,7 +20,6 @@ using System.Diagnostics;
using System.Linq;
using Google.Protobuf;
using Opentelemetry.Proto.Common.V1;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using OtlpCommon = Opentelemetry.Proto.Common.V1;

View File

@ -17,7 +17,6 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.ZPages.Implementation;
#if NET452
using OpenTelemetry.Internal;

View File

@ -15,7 +15,6 @@
// </copyright>
using System;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Http;
namespace OpenTelemetry.Instrumentation.Http.Implementation

View File

@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using System.Threading;
using OpenTelemetry.Metrics.Export;

View File

@ -18,9 +18,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using OpenTelemetry.Context;
using OpenTelemetry.Metrics;
using OpenTelemetry.Metrics.Export;
using OpenTelemetry.Resources;

View File

@ -27,6 +27,8 @@ namespace OpenTelemetry.Trace
/// </summary>
public abstract class ActivityProcessor : IDisposable
{
private bool disposed;
/// <summary>
/// Activity start hook.
/// </summary>
@ -80,14 +82,24 @@ namespace OpenTelemetry.Trace
protected virtual void Dispose(bool disposing)
{
try
if (this.disposed)
{
this.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult();
return;
}
catch (Exception ex)
if (disposing)
{
OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Dispose), ex);
try
{
this.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult();
}
catch (Exception ex)
{
OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Dispose), ex);
}
}
this.disposed = true;
}
}
}

View File

@ -17,7 +17,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Internal;
@ -55,6 +54,11 @@ namespace OpenTelemetry.Trace
public CompositeActivityProcessor AddProcessor(ActivityProcessor processor)
{
if (processor == null)
{
throw new ArgumentNullException(nameof(processor));
}
var node = new DoublyLinkedListNode<ActivityProcessor>(processor)
{
Previous = this.tail,
@ -132,22 +136,22 @@ namespace OpenTelemetry.Trace
{
cur.Value?.Dispose();
}
catch (Exception e)
catch (Exception ex)
{
OpenTelemetrySdkEventSource.Log.SpanProcessorException("Dispose", e);
OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.Dispose), ex);
}
cur = cur.Next;
}
}
base.Dispose(disposing);
this.disposed = true;
}
private class DoublyLinkedListNode<T>
{
public readonly T Value;
public DoublyLinkedListNode(T value)
{
this.Value = value;
@ -156,8 +160,6 @@ namespace OpenTelemetry.Trace
public DoublyLinkedListNode<T> Previous { get; set; }
public DoublyLinkedListNode<T> Next { get; set; }
public T Value { get; set; }
}
}
}

View File

@ -14,10 +14,6 @@
// limitations under the License.
// </copyright>
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace OpenTelemetry.Trace.Internal
{
internal sealed class NoopActivityProcessor : ActivityProcessor

View File

@ -15,9 +15,6 @@
// </copyright>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using OpenTelemetry.Resources;
namespace OpenTelemetry.Trace
{

View File

@ -43,18 +43,12 @@ namespace OpenTelemetry.Trace
{
foreach (var item in this.Instrumentations)
{
if (item is IDisposable disposable)
{
disposable.Dispose();
}
(item as IDisposable)?.Dispose();
}
this.Instrumentations.Clear();
if (this.ActivityProcessor is IDisposable disposableProcessor)
{
disposableProcessor.Dispose();
}
this.ActivityProcessor?.Dispose();
// Shutdown the listener last so that anything created while instrumentation cleans up will still be processed.
// Redis instrumentation, for example, flushes during dispose which creates Activity objects for any profiling

View File

@ -15,10 +15,7 @@
// </copyright>
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Testing.Export;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Internal;

View File

@ -15,7 +15,6 @@
// </copyright>
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
using Xunit;