-
Notifications
You must be signed in to change notification settings - Fork 792
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
Support for SamplerDetectors and EnvVarSamplerDetector #3635
Conversation
be986a8
to
973f289
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3635 +/- ##
==========================================
- Coverage 87.35% 86.94% -0.42%
==========================================
Files 282 285 +3
Lines 10132 10179 +47
==========================================
- Hits 8851 8850 -1
- Misses 1281 1329 +48
|
@@ -30,7 +30,7 @@ public static void Main() | |||
{ | |||
using var tracerProvider = Sdk.CreateTracerProviderBuilder() | |||
.AddSource("MyCompany.MyProduct.MyLibrary") | |||
.SetSampler(new AlwaysOnSampler()) | |||
.ConfigureSampler(x => x.SetDefaultSampler(new AlwaysOnSampler())) |
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 it should be
.ConfigureSampler(x => x.Clear().SetDefaultSampler(new AlwaysOnSampler()))
Can you elaborate on why you suggest using the "builder API" instead of SetSampler
if the user would like to always use one explicit sampler?
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.
Fixed in fb11564.
New API provide broader functionalities so it should be used in all examples in the repository.
|
||
double ratio = defaultRatio; | ||
|
||
if (hasValue && double.TryParse(envVarValue, out double parsedRatio) && parsedRatio >= 0.0 && parsedRatio <= 1.0) |
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.
We should throw a FormatException
if the ratio is bad. Example in other place:
opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs
Line 78 in 9c3d1b1
throw new FormatException($"{ProtocolEnvVarName} environment variable has an invalid value: '{protocolEnvVar}'"); |
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 have tried to avoid throwing exceptions.
I think that both solutions should be fine.
@open-telemetry/dotnet-approvers, any preferences/comments what is the better option?
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.
Take notice that EnvironmentVariableHelper
is throwing FormatException
when it fails to parse the value.
test/OpenTelemetry.Tests/Trace/Sampling/OTelEnvSamplerDetectorTests.cs
Outdated
Show resolved
Hide resolved
@@ -335,6 +335,22 @@ Custom resource detectors can be implemented: | |||
|
|||
A demo ResourceDetector is shown [here](./MyResourceDetector.cs). | |||
|
|||
## Sampler Detector | |||
|
|||
OpenTelemetry .NET SDK provides a sampler detector for detecting sampler |
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.
mm.. I am not sure of the need of such a new api. Can we simply modify SDK to automatically pick Sampler from Env Variables?
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 see some benefits for having builder with detectors:
- possibility to programmatically disable env. vars.
- easily add more samplers supported by the env. vars. You can just implement externally support for other samplers without taking care about parsing values for common samplers. Please consider something like
XRayOTelEnvVarSamplerDetector
. With current design it could be chained with current CommonEnvVar Detector.
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 are issues with the existing environment variable stuff. Primarily, it doesn't work with IConfiguration/IOptions. This is something I am looking at, hoping to find a new pattern that smooths all of this out. Probably first to drive #3583. I would vote to wait on this sorry @Kielek I know that is probably frustrating!
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.
If we speaking about timeframe, it will be great to include it at least based env. var. support for 1.4.0 release. We would like to give AutoInstrumentation users some flexibility here.
I know that we will need more thing configurable in the future so I will observe issue you have mentioned.
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.
in current state: LGTM
Mainly, because it is consistent with existing API/design.
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Fixes #3601.
Changes
Please provide a brief description of the changes here.
SamplerDetector
s functionality (based on what was implemented forResources
)OTEL_TRACES_SAMPLER
andOTEL_TRACES_SAMPLER_ARG
env vars foralways_on
,always_off
,traceidratio
,parentbased_always_on
,parentbased_always_off
,parentbased_traceidratio
.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes