@@ -21,8 +21,9 @@ all() ->
21
21
all_testcases () ->
22
22
[disable_auto_registration , registered_tracers , with_span , macros , child_spans ,
23
23
update_span_data , tracer_instrumentation_library , tracer_previous_ctx , stop_temporary_app ,
24
- reset_after , attach_ctx , default_sampler , non_recording_ets_table , record_but_not_sample ,
25
- record_exception_works , record_exception_with_message_works ].
24
+ reset_after , attach_ctx , default_sampler , non_recording_ets_table ,
25
+ root_span_sampling_always_on , root_span_sampling_always_off ,
26
+ record_but_not_sample , record_exception_works , record_exception_with_message_works ].
26
27
27
28
groups () ->
28
29
[{w3c , [], [propagation ]},
@@ -471,6 +472,38 @@ non_recording_ets_table(_Config) ->
471
472
? assertMatch ([# span {name = <<" span-1" >>}], ets :tab2list (? SPAN_TAB )),
472
473
ok .
473
474
475
+ root_span_sampling_always_off (_Config ) ->
476
+ Tracer = opentelemetry :get_tracer (),
477
+
478
+ Sampler = otel_sampler :new (always_off ),
479
+
480
+ SpanCtx1 = otel_tracer :start_span (Tracer , <<" span-1" >>, #{sampler => Sampler }),
481
+ ? assertMatch (false , SpanCtx1 # span_ctx .is_recording ),
482
+ ? assertMatch (0 , SpanCtx1 # span_ctx .trace_flags ),
483
+
484
+ otel_tracer :set_current_span (SpanCtx1 ),
485
+ SpanCtx2 = otel_tracer :start_span (Tracer , <<" span-2" >>, #{}),
486
+ ? assertMatch (false , SpanCtx2 # span_ctx .is_recording ),
487
+ ? assertMatch (0 , SpanCtx2 # span_ctx .trace_flags ),
488
+
489
+ ok .
490
+
491
+ root_span_sampling_always_on (_Config ) ->
492
+ Tracer = opentelemetry :get_tracer (),
493
+
494
+ Sampler = otel_sampler :new (always_on ),
495
+
496
+ SpanCtx1 = otel_tracer :start_span (Tracer , <<" span-1" >>, #{sampler => Sampler }),
497
+ ? assertMatch (true , SpanCtx1 # span_ctx .is_recording ),
498
+ ? assertMatch (1 , SpanCtx1 # span_ctx .trace_flags ),
499
+
500
+ otel_tracer :set_current_span (SpanCtx1 ),
501
+ SpanCtx2 = otel_tracer :start_span (Tracer , <<" span-2" >>, #{}),
502
+ ? assertMatch (true , SpanCtx2 # span_ctx .is_recording ),
503
+ ? assertMatch (1 , SpanCtx1 # span_ctx .trace_flags ),
504
+
505
+ ok .
506
+
474
507
record_but_not_sample (Config ) ->
475
508
ct :comment (" Test that a Span that the sampler returns RECORD_ONLY for gets created"
476
509
" as a valid recorded span but is not sent to the exporter." ),
0 commit comments