Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove suppress inc and dec from diagnosticsourcelisteners #1893

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}