Skip to content

Commit e4497f7

Browse files
author
Gustavo Aguiar
committed
add baggage as span attributes
1 parent 3f45fdf commit e4497f7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

processors/opentelemetry_baggage_processor/src/otel_baggage_processor.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
-behaviour(otel_span_processor).
44

5+
-include_lib("opentelemetry/include/otel_span.hrl").
56
-include_lib("opentelemetry_api/include/opentelemetry.hrl").
67

78
-export([
@@ -12,8 +13,10 @@
1213
-type processor_config() :: term().
1314

1415
-spec on_start(otel_ctx:t(), opentelemetry:span(), processor_config()) -> opentelemetry:span().
15-
on_start(_Ctx, Span, _Config) ->
16-
Span.
16+
on_start(Ctx, Span, _Config) ->
17+
Baggage = otel_baggage:get_all(Ctx),
18+
Attributes = maps:map(fun(_K, {Value, _Metadata}) -> Value end, Baggage),
19+
add_attributes(Span, Attributes).
1720

1821
-spec on_end(opentelemetry:span(), processor_config()) ->
1922
true | dropped | {error, invalid_span} | {error, no_export_buffer}.
@@ -23,3 +26,7 @@ on_end(_Span, _Config) ->
2326
-spec force_flush(processor_config()) -> ok | {error, term()}.
2427
force_flush(_Config) ->
2528
ok.
29+
30+
-spec add_attributes(opentelemetry:span(), opentelemetry:attributes_map()) -> opentelemetry:span().
31+
add_attributes(Span = #span{attributes=SpanAttributes}, AttributesMap) ->
32+
Span#span{attributes=otel_attributes:set(AttributesMap, SpanAttributes)}.

0 commit comments

Comments
 (0)