Skip to content

Commit

Permalink
Improve usability of stability opt in lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannaegele committed Jul 23, 2024
1 parent 548da52 commit 0f3ad39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
13 changes: 9 additions & 4 deletions apps/opentelemetry_semantic_conventions/lib/sem_conv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,22 @@ defmodule OpenTelemetry.SemConv do
"""

@typedoc """
Stability opt-in value
HTTP stability opt-in
"""
@type stability_option() :: String.t()
@type http_stability() :: :http | :http_dup | :unset

@typedoc """
Map of stability opt-ins
"""
@type stability_opt_ins() :: %{http: http_stability()}

@doc """
List of stability opt-ins defined by the `OTEL_SEMCONV_STABILITY_OPT_IN` env var.
Map of stability opt-ins defined by the `OTEL_SEMCONV_STABILITY_OPT_IN` env var.
Current valid options:
* [http](migration-guide.md)
"""
@spec stability_opt_in() :: [stability_option()]
@spec stability_opt_in() :: stability_opt_ins()
defdelegate stability_opt_in(), to: :opentelemetry_sem_conv
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@

-export([stability_opt_in/0]).

-export_type([stability_option/0]).
-export_type([
http_stability/0,
stability_opt_ins/0]).

-type stability_option() :: binary().
-type http_stability() :: http | http_dup | unset.
-type stability_opt_ins() :: #{http => http_stability()}.

-spec stability_opt_in() -> [stability_option()].

-spec stability_opt_in() -> stability_opt_ins().
stability_opt_in() ->
OptInsList = string:split(os:getenv("OTEL_SEMCONV_STABILITY_OPT_IN", ""), ","),
HttpStability = http_stability(OptInsList),
OptIns = [HttpStability],
lists:filter(fun(Opt) -> (Opt =/= undefined) end, OptIns).
#{http => HttpStability}.

http_stability(OptIns) ->
Dup = lists:member("http/dup", OptIns),
Http = lists:member("http", OptIns),
case {Dup, Http} of
{true, _} ->
<<"http/dup">>;
http_dup;
{_, true} ->
<<"http">>;
http;
_ ->
undefined
unset
end.
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ defmodule OpenTelemetry.SemConvTest do

describe "stability_opt_in" do
test "http" do
assert SemConv.stability_opt_in() == []
assert SemConv.stability_opt_in() == %{http: :unset}

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "")
assert SemConv.stability_opt_in() == []
assert SemConv.stability_opt_in() == %{http: :unset}

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "unsupported")
assert SemConv.stability_opt_in() == []
assert SemConv.stability_opt_in() == %{http: :unset}

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "http")
assert SemConv.stability_opt_in() == ["http"]
assert SemConv.stability_opt_in() == %{http: :http}

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "http/dup,http")
assert SemConv.stability_opt_in() == ["http/dup"]
assert SemConv.stability_opt_in() == %{http: :http_dup}

# dup takes precedence
System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "http,http/dup")
assert SemConv.stability_opt_in() == ["http/dup"]
assert SemConv.stability_opt_in() == %{http: :http_dup}

System.delete_env("OTEL_SEMCONV_STABILITY_OPT_IN")
end
Expand Down

0 comments on commit 0f3ad39

Please sign in to comment.