Skip to content

Commit a9fb88a

Browse files
authored
Merge pull request #233 from tsloughter/baggage-encoding
url encode baggage keys and values
2 parents 3463415 + 84615da commit a9fb88a

File tree

8 files changed

+365
-26
lines changed

8 files changed

+365
-26
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ OpenTelemetry stats collection and distributed tracing framework for Erlang.
99

1010
Requires OTP 21.3 or above.
1111

12+
## Contacting Us
13+
14+
We hold regular meetings. See details at [community page](https://github.com/open-telemetry/community#special-interest-groups).
15+
16+
We use [GitHub Discussions](https://github.com/open-telemetry/opentelemetry-erlang/discussions) for support or general questions. Feel free to drop us a line.
17+
18+
We are also present in the #otel-erlang-elixir channel in the [CNCF slack](https://slack.cncf.io/). Please join us for more informal discussions.
19+
1220
## Design
1321

1422
The [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification) defines a language library as having 2 components, the API and the SDK. The API must not only define the interfaces of any implementation in that language but also be able to function as a noop implementation of the tracer. The SDK is the default implementation of the API that must be optional.

apps/opentelemetry/test/opentelemetry_SUITE.erl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,28 @@ propagation(Config) ->
214214
?assertMatch(#span_ctx{trace_flags=1}, ?current_span_ctx),
215215
?assertMatch(#span_ctx{is_recording=true}, ?current_span_ctx),
216216

217-
otel_baggage:set("key-1", "value-1"),
218-
otel_baggage:set("key-2", "value-2"),
217+
218+
otel_baggage:set("key-1", <<"value=1">>, []),
219+
%% TODO: should the whole baggage entry be dropped if metadata is bad?
220+
%% drop bad metadata (the `1').
221+
otel_baggage:set(<<"key-2">>, <<"value-2">>, [<<"metadata">>, 1, {<<"md-k-1">>, <<"md-v-1">>}]),
222+
%% drop baggage with bad value
223+
otel_baggage:set(<<"key-3">>, value3),
224+
219225
Headers = otel_propagator:text_map_inject([{<<"existing-header">>, <<"I exist">>}]),
220226

221227
EncodedTraceId = io_lib:format("~32.16.0b", [TraceId]),
222228
EncodedSpanId = io_lib:format("~16.16.0b", [SpanId]),
223229

224-
?assertListsEqual([{<<"baggage">>, "key-2=value-2,key-1=value-1"},
230+
?assertListsEqual([{<<"baggage">>, <<"key-2=value-2;metadata;md-k-1=md-v-1,key-1=value%3D1">>},
225231
{<<"existing-header">>, <<"I exist">>} |
226232
trace_context(Propagator, EncodedTraceId, EncodedSpanId)], Headers),
227233

228234
?end_span(SpanCtx),
229235

230-
?assertEqual(#{"key-1" => "value-1",
231-
"key-2" => "value-2"}, otel_baggage:get_all()),
236+
?assertEqual(#{<<"key-1">> => {<<"value=1">>, []},
237+
<<"key-2">> => {<<"value-2">>, [<<"metadata">>, {<<"md-k-1">>, <<"md-v-1">>}]}},
238+
otel_baggage:get_all()),
232239

233240
%% ?end_span doesn't remove the span from the context
234241
?assertEqual(SpanCtx, ?current_span_ctx),
@@ -243,8 +250,9 @@ propagation(Config) ->
243250
BinaryHeaders = [{string:uppercase(Key), iolist_to_binary(Value)} || {Key, Value} <- Headers],
244251
otel_propagator:text_map_extract(BinaryHeaders),
245252

246-
?assertEqual(#{"key-1" => "value-1",
247-
"key-2" => "value-2"}, otel_baggage:get_all()),
253+
?assertEqual(#{<<"key-1">> => {<<"value=1">>, []},
254+
<<"key-2">> => {<<"value-2">>, [<<"metadata">>, {<<"md-k-1">>, <<"md-v-1">>}]}},
255+
otel_baggage:get_all()),
248256

249257
%% extracted remote spans are set to the active span
250258
%% but with `is_recording' false

apps/opentelemetry_api/lib/open_telemetry/baggage.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ defmodule OpenTelemetry.Baggage do
66
"""
77

88
defdelegate set(keyvalues), to: :otel_baggage
9-
defdelegate set(key, values), to: :otel_baggage
9+
defdelegate set(ctx_or_key, keyvalues), to: :otel_baggage
10+
defdelegate set(ctx, key, value), to: :otel_baggage
11+
defdelegate set(ctx, key, values, metadata), to: :otel_baggage
1012
defdelegate get_all(), to: :otel_baggage
13+
defdelegate get_all(ctx), to: :otel_baggage
1114
defdelegate clear(), to: :otel_baggage
15+
defdelegate clear(ctx), to: :otel_baggage
1216
defdelegate get_text_map_propagators(), to: :otel_baggage
1317
end

0 commit comments

Comments
 (0)