|
| 1 | +-module(otel_baggage_processor_SUITE). |
| 2 | + |
| 3 | +-compile(export_all). |
| 4 | + |
| 5 | +-include_lib("common_test/include/ct.hrl"). |
| 6 | +-include_lib("stdlib/include/assert.hrl"). |
| 7 | +-include_lib("opentelemetry/include/otel_span.hrl"). |
| 8 | +-include_lib("opentelemetry_api/include/otel_tracer.hrl"). |
| 9 | + |
| 10 | +all() -> [ |
| 11 | + baggage_handling |
| 12 | + ]. |
| 13 | + |
| 14 | +init_per_suite(Config) -> |
| 15 | + ok = application:load(opentelemetry_baggage_processor), |
| 16 | + ok = application:load(opentelemetry), |
| 17 | + application:set_env(opentelemetry, processors, [{otel_baggage_processor, #{}}, {otel_batch_processor, #{scheduled_delay_ms => 1}}]), |
| 18 | + Config. |
| 19 | + |
| 20 | +end_per_suite(_Config) -> |
| 21 | + ok = application:unload(opentelemetry), |
| 22 | + ok. |
| 23 | + |
| 24 | +init_per_testcase(_, Config) -> |
| 25 | + {ok, _} = application:ensure_all_started(opentelemetry_baggage_processor), |
| 26 | + otel_batch_processor:set_exporter(otel_exporter_pid, self()), |
| 27 | + Config. |
| 28 | + |
| 29 | +end_per_testcase(_, Config) -> |
| 30 | + application:stop(opentelemetry), |
| 31 | + Config. |
| 32 | + |
| 33 | +baggage_handling(_Config) -> |
| 34 | + SpanCtx1 = ?start_span(<<"span-1">>), |
| 35 | + ?set_current_span(SpanCtx1), |
| 36 | + Ctx = otel_ctx:get_current(), |
| 37 | + Ctx2 = otel_baggage:set(Ctx, <<"key">>, <<"value">>), |
| 38 | + _Token = otel_ctx:attach(Ctx2), |
| 39 | + SpanCtx2 = ?start_span(<<"span-2">>), |
| 40 | + ?end_span(), |
| 41 | + ?set_current_span(SpanCtx2), |
| 42 | + ?end_span(), |
| 43 | + Attributes = get_span_attributes(<<"span-1">>), |
| 44 | + ?assertEqual(Attributes, #{}), |
| 45 | + Attributes2 = get_span_attributes(<<"span-2">>), |
| 46 | + ?assertEqual(Attributes2, #{<<"key">> => <<"value">>}), |
| 47 | + ok. |
| 48 | + |
| 49 | +get_span_attributes(Name) -> |
| 50 | + receive |
| 51 | + {span, #span{name=Name, attributes=Attributes}} -> |
| 52 | + otel_attributes:map(Attributes) |
| 53 | + after |
| 54 | + 100 -> |
| 55 | + error(timeout) |
| 56 | + end. |
0 commit comments