Skip to content

Commit

Permalink
Match Erlang strings
Browse files Browse the repository at this point in the history
  • Loading branch information
reachfh committed Dec 27, 2023
1 parent c00f7c1 commit c74d681
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/opentelemetry_xray_logger_filter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,34 @@ trace_id(#{meta := #{otel_trace_id := TraceId} = Meta} = LogEvent, _Extra) when
maps:update(meta, NewMeta, LogEvent);

trace_id(
#{
meta
:=
#{otel_trace_id := <<Time:8/binary, TraceId/binary>> = HexTraceId, otel_span_id := HexSpanId} =
Meta
} = LogEvent,
#{meta := #{otel_trace_id := HexTraceId, otel_span_id := HexSpanId} = Meta} = LogEvent,
_Extra
) ->
)
when is_list(HexTraceId), is_list(HexSpanId) ->
Time = string:slice(HexTraceId, 0, 8),
TraceId = string:slice(HexTraceId, 9),
NewId = otel_utils:assert_to_binary(["1-", Time, "-", TraceId, "@", HexSpanId]),
NewMeta = maps:put(xray_trace_id, NewId, Meta),
maps:update(meta, NewMeta, LogEvent);

trace_id(#{meta := #{otel_trace_id := HexTraceId} = Meta} = LogEvent, _Extra)
when is_list(HexTraceId) ->
Time = string:slice(HexTraceId, 0, 8),
TraceId = string:slice(HexTraceId, 9),
NewId = otel_utils:assert_to_binary(["1-", Time, "-", TraceId]),
NewMeta = maps:put(xray_trace_id, NewId, Meta),
maps:update(meta, NewMeta, LogEvent);

trace_id(
#{meta := #{otel_trace_id := <<Time:8/binary, TraceId/binary>> = HexTraceId} = Meta} = LogEvent,
#{meta := #{otel_trace_id := <<Time:8/binary, TraceId/binary>>, otel_span_id := HexSpanId} = Meta} =
LogEvent,
_Extra
) ->
NewId = otel_utils:assert_to_binary(["1-", Time, "-", TraceId, "@", HexSpanId]),
NewMeta = maps:put(xray_trace_id, NewId, Meta),
maps:update(meta, NewMeta, LogEvent);

trace_id(#{meta := #{otel_trace_id := <<Time:8/binary, TraceId/binary>>} = Meta} = LogEvent, _Extra) ->
NewId = otel_utils:assert_to_binary(["1-", Time, "-", TraceId]),
NewMeta = maps:put(xray_trace_id, NewId, Meta),
maps:update(meta, NewMeta, LogEvent);
Expand Down

0 comments on commit c74d681

Please sign in to comment.