Skip to content

Commit

Permalink
Remove suppress inc and dec from diagnosticsourcelisteners (#1893)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cijothomas authored Mar 10, 2021
1 parent c51d2cf commit 822ce19
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,11 @@ public void OnNext(KeyValuePair<string, object> 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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 822ce19

Please sign in to comment.