|
21 | 21 | -export([trace_id/1,
|
22 | 22 | span_id/1,
|
23 | 23 | hex_span_ctx/1,
|
| 24 | + hex_span_ctx_keys/0, |
24 | 25 | hex_trace_id/1,
|
25 | 26 | hex_span_id/1,
|
26 | 27 | tracestate/1,
|
|
44 | 45 | -include_lib("opentelemetry_semantic_conventions/include/trace.hrl").
|
45 | 46 |
|
46 | 47 | -define(is_recording(SpanCtx), SpanCtx =/= undefined andalso SpanCtx#span_ctx.is_recording =:= true).
|
| 48 | +-define(OTEL_TRACE_ID, otel_trace_id). |
| 49 | +-define(OTEL_SPAN_ID, otel_span_id). |
| 50 | +-define(OTEL_TRACE_FLAGS, otel_trace_flags). |
47 | 51 |
|
48 | 52 | -type start_opts() :: #{attributes := opentelemetry:attributes_map(),
|
49 | 53 | links := [opentelemetry:link()],
|
@@ -100,18 +104,22 @@ span_id(#span_ctx{span_id=SpanId}) ->
|
100 | 104 | SpanId.
|
101 | 105 |
|
102 | 106 | %% keys are prefixed with `otel_' because the main use of this function is logger metadata
|
103 |
| --spec hex_span_ctx(opentelemetry:span_ctx() | undefined) -> #{otel_trace_id := unicode:charlist(), |
104 |
| - otel_span_id := unicode:charlist(), |
105 |
| - otel_trace_flags := unicode:charlist()} | #{}. |
| 107 | +-spec hex_span_ctx(opentelemetry:span_ctx() | undefined) -> #{?OTEL_TRACE_ID := unicode:charlist(), |
| 108 | + ?OTEL_SPAN_ID := unicode:charlist(), |
| 109 | + ?OTEL_TRACE_FLAGS := unicode:charlist()} | #{}. |
106 | 110 | hex_span_ctx(#span_ctx{trace_id=TraceId,
|
107 | 111 | span_id=SpanId,
|
108 | 112 | trace_flags=TraceFlags}) ->
|
109 |
| - #{otel_trace_id => io_lib:format("~32.16.0b", [TraceId]), |
110 |
| - otel_span_id => io_lib:format("~16.16.0b", [SpanId]), |
111 |
| - otel_trace_flags => case TraceFlags band 1 of 1 -> "01"; _ -> "00" end}; |
| 113 | + #{?OTEL_TRACE_ID => io_lib:format("~32.16.0b", [TraceId]), |
| 114 | + ?OTEL_SPAN_ID => io_lib:format("~16.16.0b", [SpanId]), |
| 115 | + ?OTEL_TRACE_FLAGS => case TraceFlags band 1 of 1 -> "01"; _ -> "00" end}; |
112 | 116 | hex_span_ctx(_) ->
|
113 | 117 | #{}.
|
114 | 118 |
|
| 119 | +-spec hex_span_ctx_keys() -> [atom()]. |
| 120 | +hex_span_ctx_keys() -> |
| 121 | + [?OTEL_TRACE_ID, ?OTEL_SPAN_ID, ?OTEL_TRACE_FLAGS]. |
| 122 | + |
115 | 123 | -spec hex_trace_id(opentelemetry:span_ctx()) -> opentelemetry:hex_trace_id().
|
116 | 124 | hex_trace_id(#span_ctx{trace_id=TraceId}) ->
|
117 | 125 | case otel_utils:format_binary_string("~32.16.0b", [TraceId]) of
|
|
0 commit comments