Current section

30 Versions

Jump to

Compare versions

18 files changed
+175 additions
-69 deletions
  @@ -2,30 +2,31 @@
2 2 [{<<"GitHub">>,<<"https://github.com/open-telemetry/opentelemetry-erlang">>},
3 3 {<<"OpenTelemetry.io">>,<<"https://opentelemetry.io">>}]}.
4 4 {<<"name">>,<<"opentelemetry_api">>}.
5 - {<<"version">>,<<"1.3.0">>}.
5 + {<<"version">>,<<"1.3.1">>}.
6 6 {<<"description">>,<<"OpenTelemetry API">>}.
7 7 {<<"elixir">>,<<"~> 1.8">>}.
8 8 {<<"app">>,<<"opentelemetry_api">>}.
9 9 {<<"build_tools">>,[<<"rebar3">>,<<"mix">>]}.
10 10 {<<"files">>,
11 - [<<"lib">>,<<"lib/open_telemetry">>,<<"lib/open_telemetry/baggage.ex">>,
12 - <<"lib/open_telemetry/ctx.ex">>,<<"lib/open_telemetry/tracer.ex">>,
13 - <<"lib/open_telemetry/span.ex">>,<<"lib/open_telemetry.ex">>,<<"mix.exs">>,
14 - <<"README.md">>,<<"LICENSE">>,<<"rebar.config">>,<<"include">>,
15 - <<"include/gradualizer.hrl">>,<<"include/otel_tracer.hrl">>,
16 - <<"include/opentelemetry.hrl">>,<<"include/otel_ctx.hrl">>,<<"src">>,
17 - <<"src/opentelemetry_api.app.src">>,<<"src/otel_propagator_b3.erl">>,
18 - <<"src/otel_propagator_baggage.erl">>,
19 - <<"src/otel_propagator_text_map_composite.erl">>,
20 - <<"src/otel_propagator_text_map_noop.erl">>,
11 + [<<"lib">>,<<"lib/open_telemetry.ex">>,<<"lib/open_telemetry">>,
12 + <<"lib/open_telemetry/baggage.ex">>,<<"lib/open_telemetry/ctx.ex">>,
13 + <<"lib/open_telemetry/tracer.ex">>,<<"lib/open_telemetry/span.ex">>,
14 + <<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,<<"rebar.config">>,
15 + <<"include">>,<<"include/gradualizer.hrl">>,<<"include/otel_ctx.hrl">>,
16 + <<"include/otel_tracer.hrl">>,<<"include/opentelemetry.hrl">>,<<"src">>,
17 + <<"src/otel_baggage.erl">>,<<"src/otel_ctx.erl">>,
18 + <<"src/otel_tracer_provider.erl">>,<<"src/otel_tracestate.erl">>,
19 + <<"src/otel_propagator.erl">>,<<"src/otel_propagator_b3.erl">>,
21 20 <<"src/otel_propagator_b3multi.erl">>,
22 - <<"src/otel_propagator_b3single.erl">>,<<"src/otel_utils.erl">>,
23 - <<"src/otel_tracer_provider.erl">>,<<"src/otel_propagator.erl">>,
24 - <<"src/otel_propagator_text_map.erl">>,<<"src/otel_tracer.erl">>,
25 - <<"src/otel_propagator_trace_context.erl">>,<<"src/otel_tracer_noop.erl">>,
26 - <<"src/otel_tracestate.erl">>,<<"src/opentelemetry.erl">>,
27 - <<"src/otel_attributes.erl">>,<<"src/otel_baggage.erl">>,
28 - <<"src/otel_ctx.erl">>,<<"src/otel_span.erl">>]}.
21 + <<"src/otel_propagator_b3single.erl">>,
22 + <<"src/otel_propagator_baggage.erl">>,
23 + <<"src/otel_propagator_text_map.erl">>,
24 + <<"src/otel_propagator_text_map_noop.erl">>,
25 + <<"src/otel_propagator_trace_context.erl">>,<<"src/otel_span.erl">>,
26 + <<"src/otel_tracer_noop.erl">>,<<"src/otel_utils.erl">>,
27 + <<"src/opentelemetry.erl">>,
28 + <<"src/otel_propagator_text_map_composite.erl">>,<<"src/otel_tracer.erl">>,
29 + <<"src/otel_attributes.erl">>,<<"src/opentelemetry_api.app.src">>]}.
29 30 {<<"licenses">>,[<<"Apache-2.0">>]}.
30 31 {<<"requirements">>,
31 32 [[{<<"name">>,<<"opentelemetry_semantic_conventions">>},
  @@ -13,7 +13,7 @@
13 13 %% limitations under the License.
14 14 %%%------------------------------------------------------------------------
15 15
16 - %% convert 2 strings (one meant to be like a namspace and the other a unique name)
16 + %% convert 2 strings (one meant to be like a namespace and the other a unique name)
17 17 %% to an atom for use registering a process
18 18 -define(REG_NAME(Name), list_to_atom(lists:concat([?MODULE, "_", Name]))).
19 19 -define(GLOBAL_TRACER_PROVIDER_NAME, global).
  @@ -32,6 +32,7 @@ defmodule OpenTelemetry.Span do
32 32 require OpenTelemetry.SemanticConventions.Trace
33 33
34 34 @type start_opts() :: :otel_span.start_opts()
35 + @type start_config() :: :otel_span.start_config()
35 36
36 37 @doc """
37 38 Get the SpanId of a Span.
  @@ -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 convenience 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(_) ->
  @@ -1,6 +1,6 @@
1 1 {application, opentelemetry_api,
2 2 [{description, "OpenTelemetry API"},
3 - {vsn, "1.3.0"},
3 + {vsn, "1.3.1"},
4 4 {registered, []},
5 5 {applications,
6 6 [kernel,
Loading more files…