Skip to content

Commit

Permalink
Add semconv stability opt-in fun
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannaegele committed Jul 23, 2024
1 parent f349463 commit 548da52
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
15 changes: 15 additions & 0 deletions apps/opentelemetry_semantic_conventions/lib/sem_conv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,19 @@ defmodule OpenTelemetry.SemConv do
attributes of both stability levels will have two modules in this case.
"""

@typedoc """
Stability opt-in value
"""
@type stability_option() :: String.t()

@doc """
List 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()]
defdelegate stability_opt_in(), to: :opentelemetry_sem_conv
end
1 change: 0 additions & 1 deletion apps/opentelemetry_semantic_conventions/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,5 @@ defmodule OpenTelemetry.SemanticConventions.MixProject do
"guides/attributes-registry/signalr.md"
] ++ Path.wildcard("guides/dotnet/*") ++ Path.wildcard("guides/mobile/*"))
end)
|> IO.inspect()
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-module(opentelemetry_sem_conv).

-export([stability_opt_in/0]).

-export_type([stability_option/0]).

-type stability_option() :: binary().

-spec stability_opt_in() -> [stability_option()].
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_stability(OptIns) ->
Dup = lists:member("http/dup", OptIns),
Http = lists:member("http", OptIns),
case {Dup, Http} of
{true, _} ->
<<"http/dup">>;
{_, true} ->
<<"http">>;
_ ->
undefined
end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule OpenTelemetry.SemConvTest do
use ExUnit.Case, async: false

alias OpenTelemetry.SemConv

describe "stability_opt_in" do
test "http" do
assert SemConv.stability_opt_in() == []

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "")
assert SemConv.stability_opt_in() == []

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "unsupported")
assert SemConv.stability_opt_in() == []

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "http")
assert SemConv.stability_opt_in() == ["http"]

System.put_env("OTEL_SEMCONV_STABILITY_OPT_IN", "http/dup,http")
assert SemConv.stability_opt_in() == ["http/dup"]

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

System.delete_env("OTEL_SEMCONV_STABILITY_OPT_IN")
end
end
end

0 comments on commit 548da52

Please sign in to comment.