|
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()],
|
@@ -108,18 +112,22 @@ span_id(#span_ctx{span_id=SpanId}) ->
|
108 | 112 | SpanId.
|
109 | 113 |
|
110 | 114 | %% keys are prefixed with `otel_' because the main use of this function is logger metadata
|
111 |
| --spec hex_span_ctx(opentelemetry:span_ctx() | undefined) -> #{otel_trace_id := unicode:charlist(), |
112 |
| - otel_span_id := unicode:charlist(), |
113 |
| - otel_trace_flags := unicode:charlist()} | #{}. |
| 115 | +-spec hex_span_ctx(opentelemetry:span_ctx() | undefined) -> #{?OTEL_TRACE_ID := unicode:charlist(), |
| 116 | + ?OTEL_SPAN_ID := unicode:charlist(), |
| 117 | + ?OTEL_TRACE_FLAGS := unicode:charlist()} | #{}. |
114 | 118 | hex_span_ctx(#span_ctx{trace_id=TraceId,
|
115 | 119 | span_id=SpanId,
|
116 | 120 | trace_flags=TraceFlags}) ->
|
117 |
| - #{otel_trace_id => io_lib:format("~32.16.0b", [TraceId]), |
118 |
| - otel_span_id => io_lib:format("~16.16.0b", [SpanId]), |
119 |
| - otel_trace_flags => case TraceFlags band 1 of 1 -> "01"; _ -> "00" end}; |
| 121 | + #{?OTEL_TRACE_ID => io_lib:format("~32.16.0b", [TraceId]), |
| 122 | + ?OTEL_SPAN_ID => io_lib:format("~16.16.0b", [SpanId]), |
| 123 | + ?OTEL_TRACE_FLAGS => case TraceFlags band 1 of 1 -> "01"; _ -> "00" end}; |
120 | 124 | hex_span_ctx(_) ->
|
121 | 125 | #{}.
|
122 | 126 |
|
| 127 | +-spec hex_span_ctx_keys() -> [atom()]. |
| 128 | +hex_span_ctx_keys() -> |
| 129 | + [?OTEL_TRACE_ID, ?OTEL_SPAN_ID, ?OTEL_TRACE_FLAGS]. |
| 130 | + |
123 | 131 | -spec hex_trace_id(opentelemetry:span_ctx()) -> opentelemetry:hex_trace_id().
|
124 | 132 | hex_trace_id(#span_ctx{trace_id=TraceId}) ->
|
125 | 133 | case otel_utils:format_binary_string("~32.16.0b", [TraceId]) of
|
|
0 commit comments