-
Notifications
You must be signed in to change notification settings - Fork 775
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
Make suppress instrumentation APIs less prone to introducing bugs #1067
Make suppress instrumentation APIs less prone to introducing bugs #1067
Conversation
/// <summary> | ||
/// Gets a value indicating whether instrumentation is suppressed (disabled). | ||
/// </summary> | ||
public static bool SuppressInstrumentation => SuppressInstrumentationScope.IsSuppressed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's more to the API now, but I think it is simpler to understand by decoupling the disposable object from the boolean check. Should we apply AggresiveInlining
on these APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess AggresiveInlining
is not going to help here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, that's a good improvement to avoid pitfalls.
Need to update the CHANGELOG. |
Codecov Report
@@ Coverage Diff @@
## master #1067 +/- ##
=======================================
Coverage 77.40% 77.40%
=======================================
Files 220 220
Lines 6080 6080
=======================================
Hits 4706 4706
Misses 1374 1374
|
src/OpenTelemetry/Sdk.cs
Outdated
/// } | ||
/// </code> | ||
/// </remarks> | ||
public static SuppressInstrumentationScope BeginSuppressInstrumentationScope(bool value = true) => SuppressInstrumentationScope.Begin(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think return should just be IDisposable
. It's not like you can do anything with the class. More closely matches log scope that way too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Good call.
@@ -70,5 +43,10 @@ public void Dispose() | |||
this.disposed = true; | |||
} | |||
} | |||
|
|||
internal static SuppressInstrumentationScope Begin(bool value = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about leaving this in?
public static IDisposable Begin(bool value = true)
Because I kind of like this way better:
using (var scope = SuppressInstrumentationScope.Begin())
But I'm OK also having the helper too 😁
There's no more danger of using (SuppressInstrumentationScope)
because the static is gone right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel great about this. I actually decided to remove the helper in favor of this idea. Though, happy to revert and put the helper back if others find it useful. I personally like your idea better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Refactoring our SuppressInstrumentation APIs to be less likely to cause problems.
Prior to this PR it was possible to do:
while what was intended was:
The former would have caused the static
SuppressInstrumentationScope
instance to be disposed, and furthermore it would not have actually suppressed instrumentation as intended.Now the usage is:
@reyang @CodeBlanch