66-include_lib (" opentelemetry/include/otel_span.hrl" ).
77-include_lib (" opentelemetry_api/include/otel_tracer.hrl" ).
88
9- all () -> [
10- baggage_handling
11- ].
9+ all () ->
10+ [baggage_handling , add_prefix_to_attributes , filter_baggage_attributes ].
1211
1312init_per_suite (Config ) ->
1413 ok = application :load (opentelemetry_baggage_processor ),
1514 ok = application :load (opentelemetry ),
16- application :set_env (opentelemetry , processors , [{otel_baggage_processor , #{}}, {otel_batch_processor , #{scheduled_delay_ms => 1 }}]),
15+ application :set_env (opentelemetry ,
16+ processors ,
17+ [{otel_baggage_processor , #{}},
18+ {otel_batch_processor , #{scheduled_delay_ms => 1 }}]),
1719 Config .
1820
1921end_per_suite (_Config ) ->
@@ -22,20 +24,22 @@ end_per_suite(_Config) ->
2224
2325init_per_testcase (_ , Config ) ->
2426 {ok , _ } = application :ensure_all_started (opentelemetry_baggage_processor ),
25- otel_batch_processor :set_exporter (otel_exporter_pid , self ()),
2627 Config .
2728
2829end_per_testcase (_ , Config ) ->
2930 application :stop (opentelemetry ),
3031 Config .
3132
3233baggage_handling (_Config ) ->
34+ {ok , _ } = application :ensure_all_started (opentelemetry ),
35+ otel_batch_processor :set_exporter (otel_exporter_pid , self ()),
3336 SpanCtx1 = ? start_span (<<" span-1" >>),
3437 ? set_current_span (SpanCtx1 ),
3538 Ctx = otel_ctx :get_current (),
3639 Ctx2 = otel_baggage :set (Ctx , <<" key" >>, <<" value" >>),
3740 _Token = otel_ctx :attach (Ctx2 ),
38- SpanCtx2 = ? start_span (<<" span-2" >>, #{attributes => #{<<" existing-attribute" >> => true }}),
41+ SpanCtx2 =
42+ ? start_span (<<" span-2" >>, #{attributes => #{<<" existing-attribute" >> => true }}),
3943 ? end_span (),
4044 ? set_current_span (SpanCtx2 ),
4145 ? end_span (),
@@ -45,11 +49,47 @@ baggage_handling(_Config) ->
4549 ? assertEqual (Attributes2 , #{<<" key" >> => <<" value" >>, <<" existing-attribute" >> => true }),
4650 ok .
4751
52+ add_prefix_to_attributes (_Config ) ->
53+ application :set_env (opentelemetry ,
54+ processors ,
55+ [{otel_baggage_processor , #{prefix => <<" app." >>}},
56+ {otel_batch_processor , #{scheduled_delay_ms => 1 }}]),
57+ {ok , _ } = application :ensure_all_started (opentelemetry ),
58+ otel_batch_processor :set_exporter (otel_exporter_pid , self ()),
59+ Ctx = otel_ctx :get_current (),
60+ Ctx2 = otel_baggage :set (Ctx , <<" key" >>, <<" value" >>),
61+ Ctx3 = otel_baggage :set (Ctx2 , atom_key , <<" value" >>),
62+ _Token = otel_ctx :attach (Ctx3 ),
63+ SpanCtx1 = ? start_span (<<" span-1" >>),
64+ ? set_current_span (SpanCtx1 ),
65+ ? end_span (),
66+ Attributes = get_span_attributes (<<" span-1" >>),
67+ ? assertEqual (#{<<" app.key" >> => <<" value" >>, <<" app.atom_key" >> => <<" value" >>},
68+ Attributes ),
69+ ok .
70+
71+ filter_baggage_attributes (_Config ) ->
72+ application :set_env (opentelemetry ,
73+ processors ,
74+ [{otel_baggage_processor , #{filter => <<" trace_field" >>}},
75+ {otel_batch_processor , #{scheduled_delay_ms => 1 }}]),
76+ {ok , _ } = application :ensure_all_started (opentelemetry ),
77+ otel_batch_processor :set_exporter (otel_exporter_pid , self ()),
78+ Ctx = otel_ctx :get_current (),
79+ Ctx2 = otel_baggage :set (Ctx , <<" key" >>, <<" value" >>),
80+ Ctx3 = otel_baggage :set (Ctx2 , atom_key , <<" value" >>, [<<" trace_field" >>]),
81+ _Token = otel_ctx :attach (Ctx3 ),
82+ SpanCtx1 = ? start_span (<<" span-1" >>),
83+ ? set_current_span (SpanCtx1 ),
84+ ? end_span (),
85+ Attributes = get_span_attributes (<<" span-1" >>),
86+ ? assertEqual (#{<<" atom_key" >> => <<" value" >>}, Attributes ),
87+ ok .
88+
4889get_span_attributes (Name ) ->
4990 receive
50- {span , # span {name = Name , attributes = Attributes }} ->
91+ {span , # span {name = Name , attributes = Attributes }} ->
5192 otel_attributes :map (Attributes )
52- after
53- 100 ->
54- error (timeout )
93+ after 100 ->
94+ error (timeout )
5595 end .
0 commit comments