-
Notifications
You must be signed in to change notification settings - Fork 847
Add support for OTEL_SDK_DISABLED environment variable #6568
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
base: main
Are you sure you want to change the base?
Add support for OTEL_SDK_DISABLED environment variable #6568
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6568 +/- ##
==========================================
- Coverage 86.75% 86.72% -0.04%
==========================================
Files 258 258
Lines 11910 11958 +48
==========================================
+ Hits 10332 10370 +38
- Misses 1578 1588 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…ahhaering/opentelemetry-dotnet into support-sdk-disabled-envVar
test/OpenTelemetry.Tests/Logs/LoggerProviderBuilderBaseTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Martin Costello <[email protected]>
public LoggerProviderBuilderBaseTests() | ||
{ | ||
Environment.SetEnvironmentVariable(SdkConfigDefinitions.SdkDisableEnvVarName, null); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Environment.SetEnvironmentVariable(SdkConfigDefinitions.SdkDisableEnvVarName, null); | ||
GC.SuppressFinalize(this); | ||
} |
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.
A better way to do this, IMHO, would be to:
- Not set the value in the constructor
- Let the test set the value it's interested in
- Set it back to the original value when being disposed
You could use a similar pattern to this to implement it in a cross-cutting way, then the usage would be something like:
using (new EnvironmentVariableScope("OTEL_SDK_DISABLED", value))
{
var builder = new LoggerProviderBuilderBase();
using var provider = builder.Build();
Assert.IsType(expected, provider);
}
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.
Thanks for the suggestion, I've done that.
Is there any way I can retry the workflow without a commit? Sometimes the build fails even though I have no errors (like right now).
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.
Not without write access to the repo, no.
test/OpenTelemetry.Tests/Logs/LoggerProviderBuilderBaseTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Martin Costello <[email protected]>
@CodeBlanch Would you mind taking a look at this please? |
if (bool.TryParse(envVarValue, out bool result) && result) | ||
{ | ||
serviceProvider.Dispose(); | ||
return new NoopLoggerProvider(); |
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.
2 comments:
-
Would probably be good to add a log here. Don't want support tickets raised for missing telemetry when users have shot themselves in the foot 😄
-
This won't work for hosting scenarios. See line 80. This code is only invoked for manual/detached bootstrap. Something else will need to be done for hosting style. Ideally we would have a single solution for both but I haven't looked at where that might go.
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.
Thanks for the hint. Now it should work for both scenarios. Could you please check again?
Fixes #4155
Changes
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes