From 822ce196bd1e5bcc369c1b4fa6ff20adec7c0bb7 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Tue, 9 Mar 2021 19:58:05 -0800 Subject: [PATCH] Remove suppress inc and dec from diagnosticsourcelisteners (#1893) * Remove supress inc and dec from diagnosticsourcelistener as TracerProviderSdk is the sole place controlling with start and stop of activities and feeding to processor pipeline * Remove tests which covered not required scenario * changelog --- src/OpenTelemetry/CHANGELOG.md | 3 +++ .../DiagnosticSourceListener.cs | 10 ++------ .../DiagnosticSourceListenerTest.cs | 23 ------------------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 4fe6af6fab3..140f163f6de 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -9,6 +9,9 @@ please check the latest changes ## Unreleased +* Removed SuppressScope Increment/Decrement from DiagnosticSourceListeners. + ([1893](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1893)) + * Added `TracerProviderBuilder.SetErrorStatusOnException` which automatically sets the activity status to `Error` when exception happened. ([#1858](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1858) diff --git a/src/OpenTelemetry/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs b/src/OpenTelemetry/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs index 2e0f1236fe6..fa3d9425d6f 100644 --- a/src/OpenTelemetry/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs +++ b/src/OpenTelemetry/DiagnosticSourceInstrumentation/DiagnosticSourceListener.cs @@ -53,17 +53,11 @@ public void OnNext(KeyValuePair value) { if (value.Key.EndsWith("Start", StringComparison.Ordinal)) { - if (SuppressInstrumentationScope.IncrementIfTriggered() == 0) - { - this.handler.OnStartActivity(Activity.Current, value.Value); - } + this.handler.OnStartActivity(Activity.Current, value.Value); } else if (value.Key.EndsWith("Stop", StringComparison.Ordinal)) { - if (SuppressInstrumentationScope.DecrementIfTriggered() == 0) - { - this.handler.OnStopActivity(Activity.Current, value.Value); - } + this.handler.OnStopActivity(Activity.Current, value.Value); } else if (value.Key.EndsWith("Exception", StringComparison.Ordinal)) { diff --git a/test/OpenTelemetry.Tests/Instrumentation/DiagnosticSourceListenerTest.cs b/test/OpenTelemetry.Tests/Instrumentation/DiagnosticSourceListenerTest.cs index e2b03393a06..458f284ed4b 100644 --- a/test/OpenTelemetry.Tests/Instrumentation/DiagnosticSourceListenerTest.cs +++ b/test/OpenTelemetry.Tests/Instrumentation/DiagnosticSourceListenerTest.cs @@ -33,28 +33,5 @@ public DiagnosticSourceListenerTest() this.testDiagnosticSourceSubscriber = new DiagnosticSourceSubscriber(this.testListenerHandler, null); this.testDiagnosticSourceSubscriber.Subscribe(); } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void ListenerHandlerIsNotInvokedWhenSuppressInstrumentationTrue(bool suppressInstrumentation) - { - using var scope = SuppressInstrumentationScope.Begin(suppressInstrumentation); - - var activity = new Activity("Main"); - this.diagnosticSource.StartActivity(activity, null); - this.diagnosticSource.StopActivity(activity, null); - - if (suppressInstrumentation) - { - Assert.Equal(0, this.testListenerHandler.OnStartInvokedCount); - Assert.Equal(0, this.testListenerHandler.OnStopInvokedCount); - } - else - { - Assert.Equal(1, this.testListenerHandler.OnStartInvokedCount); - Assert.Equal(1, this.testListenerHandler.OnStopInvokedCount); - } - } } }