File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
test/OpenTelemetry.Tests/Trace Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -252,5 +252,30 @@ public void SamplersDoesNotImpactTraceStateWhenUsingNull(SamplingDecision sampli
252252 Assert . Equal ( parentTraceState , activity . TraceStateString ) ;
253253 }
254254 }
255+
256+ [ Fact ]
257+ public void SamplerExceptionBubblesUpTest ( )
258+ {
259+ // Note: This test verifies there is NO try/catch around sampling
260+ // and it will throw. For the discussion behind this see:
261+ // https://github.com/open-telemetry/opentelemetry-dotnet/pull/4072
262+
263+ var activitySourceName = Utils . GetCurrentMethodName ( ) ;
264+ using var activitySource = new ActivitySource ( activitySourceName ) ;
265+ using var tracerProvider = Sdk . CreateTracerProviderBuilder ( )
266+ . AddSource ( activitySourceName )
267+ . SetSampler ( new ThrowingSampler ( ) )
268+ . Build ( ) ;
269+
270+ Assert . Throws < InvalidOperationException > ( ( ) => activitySource . StartActivity ( "ThrowingSampler" ) ) ;
271+ }
272+
273+ private sealed class ThrowingSampler : Sampler
274+ {
275+ public override SamplingResult ShouldSample ( in SamplingParameters samplingParameters )
276+ {
277+ throw new InvalidOperationException ( "ThrowingSampler" ) ;
278+ }
279+ }
255280 }
256281}
You can’t perform that action at this time.
0 commit comments