Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard code semconv 0.2 values #780

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/opentelemetry/rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{erl_opts, [debug_info]}.
{deps, [{opentelemetry_api, "~> 1.3.0"},
{opentelemetry_semantic_conventions, "~> 0.2"}]}.
{deps, [{opentelemetry_api, "~> 1.3.0"}]}.

{profiles,
[{docs, [{edoc_opts,
Expand Down
1 change: 1 addition & 0 deletions apps/opentelemetry/src/opentelemetry.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
stdlib,
opentelemetry_api
]},
{exclude_paths, ["rebar.lock"]},
{env, []},
{modules, []},

Expand Down
35 changes: 17 additions & 18 deletions apps/opentelemetry/src/otel_resource_detector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
-type detector() :: module() | {module(), term()}.

-include_lib("kernel/include/logger.hrl").
-include_lib("opentelemetry_semantic_conventions/include/resource.hrl").

-record(data, {resource :: otel_resource:t(),
detectors :: [detector()],
Expand Down Expand Up @@ -175,7 +174,7 @@ spawn_detector(Module, Ref) ->

default_resource_attributes(Resource) ->
ProgName = prog_name(),
ProcessResource = otel_resource:create([{?PROCESS_EXECUTABLE_NAME, ProgName} | process_attributes()]),
ProcessResource = otel_resource:create([{'process.executable.name', ProgName} | process_attributes()]),
Resource1 = otel_resource:merge(ProcessResource, Resource),
Resource2 = add_service_name(Resource1, ProgName),
Resource3 = add_service_instance(Resource2),
Expand All @@ -184,9 +183,9 @@ default_resource_attributes(Resource) ->
process_attributes() ->
OtpVsn = otp_vsn(),
ErtsVsn = erts_vsn(),
[{?PROCESS_RUNTIME_NAME, unicode:characters_to_binary(emulator())},
{?PROCESS_RUNTIME_VERSION, unicode:characters_to_binary(ErtsVsn)},
{?PROCESS_RUNTIME_DESCRIPTION, unicode:characters_to_binary(runtime_description(OtpVsn, ErtsVsn))}].
[{'process.runtime.name', unicode:characters_to_binary(emulator())},
{'process.runtime.version', unicode:characters_to_binary(ErtsVsn)},
{'process.runtime.description', unicode:characters_to_binary(runtime_description(OtpVsn, ErtsVsn))}].

runtime_description(OtpVsn, ErtsVsn) ->
io_lib:format("Erlang/OTP ~s erts-~s", [OtpVsn, ErtsVsn]).
Expand Down Expand Up @@ -240,7 +239,7 @@ release_name() ->
add_service_name(Resource, ProgName) ->
case os:getenv("OTEL_SERVICE_NAME") of
false ->
case otel_resource:is_key(?SERVICE_NAME, Resource) of
case otel_resource:is_key('service.name', Resource) of
false ->
ServiceResource = service_release_name(ProgName),
otel_resource:merge(ServiceResource, Resource);
Expand All @@ -256,7 +255,7 @@ add_service_name(Resource, ProgName) ->
ServiceResource = service_release_name(ProgName),
otel_resource:merge(ServiceResource, Resource);
BinaryString ->
ServiceNameResource = otel_resource:create([{?SERVICE_NAME, BinaryString}]),
ServiceNameResource = otel_resource:create([{'service.name', BinaryString}]),
otel_resource:merge(ServiceNameResource, Resource)
end
end.
Expand All @@ -267,52 +266,52 @@ add_service_name(Resource, ProgName) ->
add_service_instance(Resource) ->
case os:getenv("OTEL_SERVICE_INSTANCE") of
false ->
case otel_resource:is_key(?SERVICE_INSTANCE_ID, Resource) of
case otel_resource:is_key('service.instance.id', Resource) of
false ->
case erlang:node() of
nonode@nohost ->
ServiceInstanceId = otel_id_generator:generate_trace_id(),
ServiceInstanceResource = otel_resource:create([{?SERVICE_INSTANCE_ID, ServiceInstanceId}]),
ServiceInstanceResource = otel_resource:create([{'service.instance.id', ServiceInstanceId}]),
otel_resource:merge(ServiceInstanceResource, Resource);
ServiceInstance ->
ServiceInstance1 = erlang:atom_to_binary(ServiceInstance, utf8),
case binary:match(ServiceInstance1, <<"@localhost">>) of
nomatch ->
ServiceInstanceResource = otel_resource:create([{?SERVICE_INSTANCE_ID, ServiceInstance1}]),
ServiceInstanceResource = otel_resource:create([{'service.instance.id', ServiceInstance1}]),
otel_resource:merge(ServiceInstanceResource, Resource);
_Match ->
ServiceInstanceId = otel_id_generator:generate_trace_id(),
ServiceInstanceResource = otel_resource:create([{?SERVICE_INSTANCE_ID, ServiceInstanceId}]),
ServiceInstanceResource = otel_resource:create([{'service.instance.id', ServiceInstanceId}]),
otel_resource:merge(ServiceInstanceResource, Resource)
end
end;
true ->
Resource
end;
ServiceInstance ->
ServiceInstanceResource = otel_resource:create([{?SERVICE_INSTANCE_ID,
ServiceInstanceResource = otel_resource:create([{'service.instance.id',
otel_utils:assert_to_binary(ServiceInstance)}]),
otel_resource:merge(ServiceInstanceResource, Resource)
end.

service_release_name(ProgName) ->
case find_release() of
{RelName, RelVsn} when RelName =/= false ->
otel_resource:create([{?SERVICE_NAME, RelName} |
otel_resource:create([{'service.name', RelName} |
case RelVsn of
false -> [];
_ -> [{?SERVICE_VERSION, RelVsn}]
_ -> [{'service.version', RelVsn}]
end]);
_ ->
otel_resource:create([{?SERVICE_NAME, <<"unknown_service:", ProgName/binary>>}])
otel_resource:create([{'service.name', <<"unknown_service:", ProgName/binary>>}])
end.

add_telemetry_info(Resource) ->
{ok, LibraryVsn} = application:get_key(opentelemetry, vsn),
LibraryName = <<"opentelemetry">>,
LibraryLanguage = <<"erlang">>,
ResourceAttributes = [{?TELEMETRY_SDK_NAME, LibraryName},
{?TELEMETRY_SDK_LANGUAGE, LibraryLanguage},
{?TELEMETRY_SDK_VERSION, LibraryVsn}],
ResourceAttributes = [{'telemetry.sdk.name', LibraryName},
{'telemetry.sdk.language', LibraryLanguage},
{'telemetry.sdk.version', LibraryVsn}],
TelemetryInfoResource = otel_resource:create(ResourceAttributes),
otel_resource:merge(TelemetryInfoResource, Resource).
55 changes: 27 additions & 28 deletions apps/opentelemetry/test/otel_resource_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
-include_lib("common_test/include/ct.hrl").

-include_lib("opentelemetry_api/include/opentelemetry.hrl").
-include_lib("opentelemetry_semantic_conventions/include/resource.hrl").
-include("otel_span.hrl").
-include("otel_test_utils.hrl").
-include("otel_tracer.hrl").
Expand Down Expand Up @@ -67,8 +66,8 @@ startup(_Config) ->
Resource = otel_tracer_provider:resource(),
_ = application:stop(opentelemetry),

?assertMatch(#{?SERVICE_NAME := <<"cttest">>,
?SERVICE_VERSION := <<"1.1.1">>}, otel_attributes:map(otel_resource:attributes(Resource))),
?assertMatch(#{'service.name' := <<"cttest">>,
'service.version' := <<"1.1.1">>}, otel_attributes:map(otel_resource:attributes(Resource))),
ok
after
os:unsetenv("OTEL_RESOURCE_ATTRIBUTES"),
Expand All @@ -85,8 +84,8 @@ startup_env_service_name(_Config) ->
Resource = otel_tracer_provider:resource(),
_ = application:stop(opentelemetry),

?assertMatch(#{?SERVICE_NAME := <<"env-service-name">>,
?SERVICE_VERSION := <<"1.1.1">>}, otel_attributes:map(otel_resource:attributes(Resource))),
?assertMatch(#{'service.name' := <<"env-service-name">>,
'service.version' := <<"1.1.1">>}, otel_attributes:map(otel_resource:attributes(Resource))),
ok
after
os:unsetenv("OTEL_SERVICE_NAME"),
Expand All @@ -110,8 +109,8 @@ crash_detector(_Config) ->

Resource = otel_resource_detector:get_resource(),

?assertMatch(#{?SERVICE_NAME := <<"cttest">>,
?SERVICE_VERSION := <<"2.1.1">>,
?assertMatch(#{'service.name' := <<"cttest">>,
'service.version' := <<"2.1.1">>,
c := <<"d">>,
sk := <<"sv">>}, otel_attributes:map(otel_resource:attributes(Resource))),

Expand All @@ -134,8 +133,8 @@ timeout_detector(_Config) ->

Resource = otel_resource_detector:get_resource(),

?assertMatch(#{?SERVICE_NAME := <<"cttest">>,
?SERVICE_VERSION := <<"3.1.1">>,
?assertMatch(#{'service.name' := <<"cttest">>,
'service.version' := <<"3.1.1">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

?assertEqual(otel_resource:create([]), otel_resource_detector:get_resource(0)),
Expand Down Expand Up @@ -170,8 +169,8 @@ combining(_Config) ->

Merged = otel_resource:merge(Resource1, Resource2),

Expected = otel_attributes:new([{?SERVICE_NAME, <<"other-name">>},
{?SERVICE_VERSION, <<"1.1.1">>}], 128, 255),
Expected = otel_attributes:new([{'service.name', <<"other-name">>},
{'service.version', <<"1.1.1">>}], 128, 255),
?assertEqual(Expected, otel_resource:attributes(Merged)),
?assertEqual(<<"https://opentelemetry.io/schemas/1.8.0">>, otel_resource:schema_url(Merged)),
ok.
Expand All @@ -184,8 +183,8 @@ combining_conflicting_schemas(_Config) ->

Merged = otel_resource:merge(Resource1, Resource2),

Expected = otel_attributes:new([{?SERVICE_NAME, <<"other-name">>},
{?SERVICE_VERSION, <<"1.1.1">>}], 128, 255),
Expected = otel_attributes:new([{'service.name', <<"other-name">>},
{'service.version', <<"1.1.1">>}], 128, 255),
?assertEqual(Expected, otel_resource:attributes(Merged)),
?assertEqual(undefined, otel_resource:schema_url(Merged)),
ok.
Expand All @@ -203,9 +202,9 @@ unknown_service_name(_Config) ->
resource_detector_timeout => 100}),

Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_NAME := <<"unknown_service:erl">>,
?PROCESS_RUNTIME_NAME := <<"BEAM">>,
?PROCESS_EXECUTABLE_NAME := <<"erl">>,
?assertMatch(#{'service.name' := <<"unknown_service:erl">>,
'process.runtime.name' := <<"BEAM">>,
'process.executable.name' := <<"erl">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

ok
Expand All @@ -226,8 +225,8 @@ release_service_name(_Config) ->
resource_detector_timeout => 100}),

Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_NAME := <<"rel-cttest">>,
?SERVICE_VERSION := <<"0.1.0">>,
?assertMatch(#{'service.name' := <<"rel-cttest">>,
'service.version' := <<"0.1.0">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

ok
Expand All @@ -248,7 +247,7 @@ service_instance_id_env(_Config) ->
resource_detector_timeout => 100}),

Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_INSTANCE_ID := <<"test@instance">>,
?assertMatch(#{'service.instance.id' := <<"test@instance">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

ok
Expand All @@ -268,7 +267,7 @@ service_instance_id_env_attributes(_Config) ->
resource_detector_timeout => 100}),

Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_INSTANCE_ID := <<"test@instance">>,
?assertMatch(#{'service.instance.id' := <<"test@instance">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

ok
Expand All @@ -278,16 +277,16 @@ service_instance_id_env_attributes(_Config) ->

service_instance_id_node_name(_Config) ->
Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_INSTANCE_ID := <<"test@instance">>,
?assertMatch(#{'service.instance.id' := <<"test@instance">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),

ok.

service_instance_id_node_id1(_Config) ->
Resource = otel_resource_detector:get_resource(),
ResourceMap = otel_attributes:map(otel_resource:attributes(Resource)),
?assertNotMatch(#{?SERVICE_INSTANCE_ID := <<"test@localhost">>}, ResourceMap),
?assert(maps:is_key(?SERVICE_INSTANCE_ID, ResourceMap)),
?assertNotMatch(#{'service.instance.id' := <<"test@localhost">>}, ResourceMap),
?assert(maps:is_key('service.instance.id', ResourceMap)),

ok.

Expand All @@ -302,8 +301,8 @@ service_instance_id_node_id2(_Config) ->

Resource = otel_resource_detector:get_resource(),
ResourceMap = otel_attributes:map(otel_resource:attributes(Resource)),
?assertNotMatch(#{?SERVICE_INSTANCE_ID := <<"nonode@nohost">>}, ResourceMap),
?assert(maps:is_key(?SERVICE_INSTANCE_ID, ResourceMap)),
?assertNotMatch(#{'service.instance.id' := <<"nonode@nohost">>}, ResourceMap),
?assert(maps:is_key('service.instance.id', ResourceMap)),
ok.

release_service_name_no_version(_Config) ->
Expand All @@ -318,9 +317,9 @@ release_service_name_no_version(_Config) ->
resource_detector_timeout => 100}),

Resource = otel_resource_detector:get_resource(),
?assertMatch(#{?SERVICE_NAME := <<"rel-cttest">>,
?assertMatch(#{'service.name' := <<"rel-cttest">>,
e := <<"f">>}, otel_attributes:map(otel_resource:attributes(Resource))),
?assertNot(maps:is_key(?SERVICE_VERSION, otel_attributes:map(otel_resource:attributes(Resource)))),
?assertNot(maps:is_key('service.version', otel_attributes:map(otel_resource:attributes(Resource)))),

ok
after
Expand All @@ -346,7 +345,7 @@ validate_keys(_Config) ->

Resource = otel_resource_detector:get_resource(),
?assert(otel_resource:is_key(e, Resource)),
?assert(otel_resource:is_key(?SERVICE_NAME, Resource)),
?assert(otel_resource:is_key('service.name', Resource)),
?assert(otel_resource:is_key(<<"service.alias">>, Resource)),
?assert(otel_resource:is_key("service.alias", Resource)),
?assert(otel_resource:is_key('service.alias', Resource)),
Expand Down
9 changes: 3 additions & 6 deletions apps/opentelemetry_api/lib/open_telemetry/span.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ defmodule OpenTelemetry.Span do
- A Status (`t:OpenTelemetry.status/0`)
"""

require OpenTelemetry.SemanticConventions.Trace

@type start_opts() :: :otel_span.start_opts()
@type start_config() :: :otel_span.start_config()

Expand Down Expand Up @@ -140,10 +138,9 @@ defmodule OpenTelemetry.Span do
exception_type = to_string(exception.__struct__)

exception_attributes = [
{OpenTelemetry.SemanticConventions.Trace.exception_type(), exception_type},
{OpenTelemetry.SemanticConventions.Trace.exception_message(), Exception.message(exception)},
{OpenTelemetry.SemanticConventions.Trace.exception_stacktrace(),
Exception.format_stacktrace(trace)}
{:"exception.type", exception_type},
{:"exception.message", Exception.message(exception)},
{:"exception.stacktrace", Exception.format_stacktrace(trace)}
]

add_event(span_ctx, :exception, exception_attributes ++ attributes)
Expand Down
1 change: 0 additions & 1 deletion apps/opentelemetry_api/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defmodule OpenTelemetry.MixProject do
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: [
{:opentelemetry_semantic_conventions, "~> 0.2"},
{:eqwalizer_support,
git: "https://github.com/whatsapp/eqwalizer.git",
branch: "main",
Expand Down
12 changes: 1 addition & 11 deletions apps/opentelemetry_api/mix.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
%{
"cmark": {:hex, :cmark, "0.10.0", "51217dc90fec459f34a30ea73345e6a7c1d2f3d618cb4a1738a2ebd0697a57a0", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "00abeadc6f3176e3941853122413082de95d57787777dd0400d64e568acf7c32"},
"covertool": {:hex, :covertool, "2.0.6", "4a291b4e3449025b0595d8f44c8d7635d4f48f033be2ce88d22a329f36f94a91", [:rebar3], [], "hexpm", "5db3fcd82180d8ea4ad857d4d1ab21a8d31b5aee0d60d2f6c0f9e25a411d1e21"},
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
"earmark": {:hex, :earmark, "1.4.14", "d04572cef64dd92726a97d92d714e38d6e130b024ea1b3f8a56e7de66ec04e50", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "df338b8b1852ee425180b276c56c6941cb12220e04fe8718fe4acbdd35fd699f"},
"earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"},
"elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"},
"eqwalizer_support": {:git, "https://github.com/whatsapp/eqwalizer.git", "1a787cb604f6083ebe8763e358ea362e4677e500", [branch: "main", sparse: "eqwalizer_support"]},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.28.0", "7eaf526dd8c80ae8c04d52ac8801594426ae322b52a6156cd038f30bafa8226f", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e55cdadf69a5d1f4cfd8477122ebac5e1fadd433a8c1022dafc5025e48db0131"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"},
"opentelemetry_semantic_conventions": {:hex, :opentelemetry_semantic_conventions, "0.2.0", "b67fe459c2938fcab341cb0951c44860c62347c005ace1b50f8402576f241435", [:mix, :rebar3], [], "hexpm", "d61fa1f5639ee8668d74b527e6806e0503efc55a42db7b5f39939d84c07d6895"},
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
}
2 changes: 1 addition & 1 deletion apps/opentelemetry_api/rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{erl_opts, [debug_info]}.
{deps, [{opentelemetry_semantic_conventions, "~> 0.2"}]}.
{deps, []}.

{profiles,
[{docs, [{edoc_opts,
Expand Down
Loading
Loading