@@ -14,7 +14,7 @@ all() ->
14
14
{group , grpc }, {group , grpc_gzip }].
15
15
16
16
groups () ->
17
- [{functional , [], [configuration , span_round_trip , ets_instrumentation_info , to_attributes ]},
17
+ [{functional , [], [configuration , span_round_trip , span_flags , ets_instrumentation_info , to_attributes ]},
18
18
{grpc , [], [verify_export ]},
19
19
{grpc_gzip , [], [verify_export ]},
20
20
{http_protobuf , [], [verify_export , user_agent ]},
@@ -322,6 +322,7 @@ span_round_trip(_Config) ->
322
322
], 128 , 128 ),
323
323
status = # status {code = ? OTEL_STATUS_OK ,
324
324
message = <<" " >>},
325
+ parent_span_is_remote = undefined ,
325
326
instrumentation_scope = # instrumentation_scope {name = <<" tracer-1" >>,
326
327
version = <<" 0.0.1" >>}},
327
328
@@ -335,6 +336,79 @@ span_round_trip(_Config) ->
335
336
336
337
ok .
337
338
339
+ span_flags (_Config ) ->
340
+ % % Test build_span_flags function
341
+ ? assertEqual (16#100 , otel_otlp_traces :build_span_flags (false , 0 )), % % 0x100 - local parent
342
+ ? assertEqual (16#300 , otel_otlp_traces :build_span_flags (true , 0 )), % % 0x300 - remote parent
343
+ ? assertEqual (16#100 , otel_otlp_traces :build_span_flags (undefined , 0 )), % % 0x100 - no parent
344
+ ? assertEqual (16#101 , otel_otlp_traces :build_span_flags (false , 1 )), % % 0x101 - local parent with sampled flag
345
+ ? assertEqual (16#301 , otel_otlp_traces :build_span_flags (true , 1 )), % % 0x301 - remote parent with sampled flag
346
+
347
+ % % Test span with local parent
348
+ TraceId = otel_id_generator :generate_trace_id (),
349
+ SpanId = otel_id_generator :generate_span_id (),
350
+ ParentSpanId = otel_id_generator :generate_span_id (),
351
+ StartTime = opentelemetry :timestamp (),
352
+ EndTime = opentelemetry :timestamp (),
353
+
354
+ LocalParentSpan = # span {name = <<" span-with-local-parent" >>,
355
+ trace_id = TraceId ,
356
+ span_id = SpanId ,
357
+ parent_span_id = ParentSpanId ,
358
+ parent_span_is_remote = false ,
359
+ kind = ? SPAN_KIND_CLIENT ,
360
+ start_time = StartTime ,
361
+ end_time = EndTime ,
362
+ trace_flags = 1 ,
363
+ is_recording = true ,
364
+ attributes = otel_attributes :new ([], 128 , 128 ),
365
+ events = otel_events :new (128 , 128 , 128 ),
366
+ links = otel_links :new ([], 128 , 128 , 128 ),
367
+ tracestate = otel_tracestate :new ([])},
368
+
369
+ PbSpanLocal = otel_otlp_traces :to_proto (LocalParentSpan ),
370
+ ? assertEqual (16#101 , maps :get (flags , PbSpanLocal )), % % 0x101 - local parent with sampled flag
371
+
372
+ % % Test span with remote parent
373
+ RemoteParentSpan = # span {name = <<" span-with-remote-parent" >>,
374
+ trace_id = TraceId ,
375
+ span_id = SpanId ,
376
+ parent_span_id = ParentSpanId ,
377
+ parent_span_is_remote = true ,
378
+ kind = ? SPAN_KIND_CLIENT ,
379
+ start_time = StartTime ,
380
+ end_time = EndTime ,
381
+ trace_flags = 1 ,
382
+ is_recording = true ,
383
+ attributes = otel_attributes :new ([], 128 , 128 ),
384
+ events = otel_events :new (128 , 128 , 128 ),
385
+ links = otel_links :new ([], 128 , 128 , 128 ),
386
+ tracestate = otel_tracestate :new ([])},
387
+
388
+ PbSpanRemote = otel_otlp_traces :to_proto (RemoteParentSpan ),
389
+ ? assertEqual (16#301 , maps :get (flags , PbSpanRemote )), % % 0x301 - remote parent with sampled flag
390
+
391
+ % % Test span with no parent
392
+ NoParentSpan = # span {name = <<" span-with-no-parent" >>,
393
+ trace_id = TraceId ,
394
+ span_id = SpanId ,
395
+ parent_span_id = undefined ,
396
+ parent_span_is_remote = undefined ,
397
+ kind = ? SPAN_KIND_CLIENT ,
398
+ start_time = StartTime ,
399
+ end_time = EndTime ,
400
+ trace_flags = 1 ,
401
+ is_recording = true ,
402
+ attributes = otel_attributes :new ([], 128 , 128 ),
403
+ events = otel_events :new (128 , 128 , 128 ),
404
+ links = otel_links :new ([], 128 , 128 , 128 ),
405
+ tracestate = otel_tracestate :new ([])},
406
+
407
+ PbSpanNoParent = otel_otlp_traces :to_proto (NoParentSpan ),
408
+ ? assertEqual (16#101 , maps :get (flags , PbSpanNoParent )), % % 0x101 - no parent with sampled flag
409
+
410
+ ok .
411
+
338
412
% % test conversion of attributes to the map representation of the OTLP protobuf
339
413
to_attributes (_Config ) ->
340
414
% % this tests the removal of support for iolists as values in attributes
0 commit comments