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.
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.
I guess AggresiveInlining is not going to help here :)
reyang
left a comment
There was a problem hiding this comment.
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.
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.
| } | ||
| } | ||
|
|
||
| internal static SuppressInstrumentationScope Begin(bool value = true) |
There was a problem hiding this comment.
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.
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.
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
SuppressInstrumentationScopeinstance to be disposed, and furthermore it would not have actually suppressed instrumentation as intended.Now the usage is:
@reyang @CodeBlanch