@@ -343,9 +343,11 @@ convert_timestamp(Timestamp, Unit) ->
343
343
Offset = erlang :time_offset (),
344
344
erlang :convert_time_unit (Timestamp + Offset , native , Unit ).
345
345
346
- -spec links ([{TraceId , SpanId , Attributes , TraceState } | span_ctx () | {span_ctx (), Attributes }]) -> [link ()] when
347
- TraceId :: trace_id (),
348
- SpanId :: span_id (),
346
+ % % @doc Creates a list of Span links from the given `List'.
347
+ % %
348
+ % % This is equivalent to calling {@link link/2} or {@link link/4} multiple times.
349
+ -spec links ([TraceIdAndSpanId | span_ctx () | {span_ctx (), Attributes }]) -> [link ()] when
350
+ TraceIdAndSpanId :: {trace_id (), span_id (), Attributes , TraceState },
349
351
Attributes :: attributes_map (),
350
352
TraceState :: otel_tracestate :t () | [{string (), string ()}].
351
353
links (List ) when is_list (List ) ->
@@ -368,18 +370,26 @@ links(List) when is_list(List) ->
368
370
links (_ ) ->
369
371
[].
370
372
373
+
374
+ % % @equiv link(SpanCtx, [])
371
375
-spec link (span_ctx () | undefined ) -> link () | undefined .
372
376
link (SpanCtx ) ->
373
377
link (SpanCtx , []).
374
378
379
+ % % @doc Creates a Span link to the Span represented by the given `SpanCtx'.
380
+ % %
381
+ % % The returned link can be used in the `links' field of a Span.
375
382
-spec link (span_ctx () | undefined , attributes_map ()) -> link () | undefined .
376
- link (# span_ctx {trace_id = TraceId ,
377
- span_id = SpanId ,
378
- tracestate = TraceState }, Attributes ) ->
383
+ link (_SpanCtx = # span_ctx {trace_id = TraceId ,
384
+ span_id = SpanId ,
385
+ tracestate = TraceState }, Attributes ) ->
379
386
? MODULE :link (TraceId , SpanId , otel_attributes :process_attributes (Attributes ), TraceState );
380
387
link (_ , _ ) ->
381
388
undefined .
382
389
390
+ % % @doc Creates a Span link to the Span represented by the given `TraceId' and `SpanId'.
391
+ % %
392
+ % % The returned link can be used in the `links' field of a Span.
383
393
-spec link (TraceId , SpanId , Attributes , TraceState ) -> link () | undefined when
384
394
TraceId :: trace_id (),
385
395
SpanId :: span_id (),
@@ -395,12 +405,18 @@ link(TraceId, SpanId, Attributes, TraceState) when is_integer(TraceId),
395
405
link (_ , _ , _ , _ ) ->
396
406
undefined .
397
407
408
+ % % @equiv event(opentelemetry:timestamp(), Name, Attributes)
398
409
-spec event (Name , Attributes ) -> event () | undefined when
399
410
Name :: event_name (),
400
411
Attributes :: attributes_map ().
401
412
event (Name , Attributes ) ->
402
413
event (opentelemetry :timestamp (), Name , Attributes ).
403
414
415
+ % % @doc Creates a Span event with the given `Name' and `Attributes'.
416
+ % %
417
+ % % The Span event is marked to have happened at `Timestamp'. The returned
418
+ % % event can be used to add an event to a Span through {@link otel_span:add_events/2},
419
+ % % for example.
404
420
-spec event (Timestamp , Name , Attributes ) -> event () | undefined when
405
421
Timestamp :: integer (),
406
422
Name :: event_name (),
@@ -419,7 +435,16 @@ event(Timestamp, Name, Attributes) when is_integer(Timestamp),
419
435
event (_ , _ , _ ) ->
420
436
undefined .
421
437
422
- events (List ) ->
438
+ % % @doc Creates a list of Span events from the given `List'.
439
+ % %
440
+ % % This is a conveneince function to create a list of Span events from a list
441
+ % % of `{Time, Name, Attributes}' or `{Name, Attributes}' tuples. It's equivalent
442
+ % % to calling {@link event/2} or {@link event/3} multiple times. This function
443
+ % % also automatically filters out any invalid tuple.
444
+ -spec events ([Event ]) -> [event ()] when
445
+ Event :: {Timestamp :: integer (), event_name (), attributes_map ()} |
446
+ {event_name (), attributes_map ()}.
447
+ events (Events ) ->
423
448
Now = opentelemetry :timestamp (),
424
449
lists :filtermap (fun ({Time , Name , Attributes }) ->
425
450
case event (Time , Name , Attributes ) of
@@ -437,13 +462,21 @@ events(List) ->
437
462
end ;
438
463
(_ ) ->
439
464
false
440
- end , List ).
465
+ end , Events ).
441
466
467
+ % % @doc Create a Span status from the given `Code'.
468
+ % %
469
+ % % The returned status can be used to set the status of a Span through
470
+ % % {@link otel_span:set_status/2}, for example.
442
471
-spec status (Code ) -> status () | undefined when
443
472
Code :: status_code ().
444
473
status (Code ) ->
445
474
status (Code , <<>>).
446
475
476
+ % % @doc Create a Span status from the given `Code' and with the given `Message'.
477
+ % %
478
+ % % The returned status can be used to set the status of a Span through
479
+ % % {@link otel_span:set_status/2}, for example.
447
480
-spec status (Code , Message ) -> status () | undefined when
448
481
Code :: status_code (),
449
482
Message :: unicode :unicode_binary ().
@@ -458,6 +491,7 @@ status(_, _) ->
458
491
459
492
% % internal functions
460
493
494
+ % % @private
461
495
-spec verify_and_set_term (module () | {module (), term ()}, term (), atom ()) -> boolean ().
462
496
verify_and_set_term (Module , TermKey , Behaviour ) ->
463
497
case verify_module_exists (Module ) of
@@ -471,6 +505,7 @@ verify_and_set_term(Module, TermKey, Behaviour) ->
471
505
false
472
506
end .
473
507
508
+ % % @private
474
509
-spec verify_module_exists (module () | {module (), term ()}) -> boolean ().
475
510
verify_module_exists ({Module , _ }) ->
476
511
verify_module_exists (Module );
@@ -486,6 +521,7 @@ verify_module_exists(Module) ->
486
521
% % for use in a filtermap
487
522
% % return {true, Link} if a link is returned or return false
488
523
% % a list is supported for tracestate for backwards compatibility
524
+ % % @private
489
525
link_or_false (TraceId , SpanId , Attributes , TraceState ) when is_list (TraceState ) ->
490
526
link_or_false (TraceId , SpanId , Attributes , otel_tracestate :new (TraceState ));
491
527
link_or_false (TraceId , SpanId , Attributes , TraceState ) ->
@@ -519,6 +555,7 @@ schema_url_to_binary(_) ->
519
555
520
556
% % Vsn can't be an atom or anything but a list or binary
521
557
% % so return empty binary string if it isn't a list or binary.
558
+ % % @private
522
559
vsn_to_binary (Vsn ) when is_binary (Vsn ) ; is_list (Vsn ) ->
523
560
unicode :characters_to_binary (Vsn );
524
561
vsn_to_binary (_ ) ->
0 commit comments