Skip to content

Commit

Permalink
add version support
Browse files Browse the repository at this point in the history
Adds support for specifying the service version using the `version` tag,
based on a span's `service_version`.
  • Loading branch information
kamilkowalski authored and gorkunov committed Dec 2, 2022
1 parent ff8ce97 commit ffb27a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config :spandex_datadog, SpandexDatadog.Test.Support.Tracer,
sender: SpandexDatadog.Test.Support.TestApiServer,
env: "test",
resource: "default",
service_version: "v1",
services: [
spandex_test: :db
]
16 changes: 12 additions & 4 deletions lib/spandex_datadog/api_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ defmodule SpandexDatadog.ApiServer do
@spec meta(Span.t()) :: map
defp meta(span) do
%{}
|> add_datadog_meta(span)
|> add_env_data(span)
|> add_version_data(span)
|> add_error_data(span)
|> add_http_data(span)
|> add_sql_data(span)
Expand All @@ -255,13 +256,20 @@ defmodule SpandexDatadog.ApiServer do
|> Enum.into(%{})
end

@spec add_datadog_meta(map, Span.t()) :: map
defp add_datadog_meta(meta, %Span{env: nil}), do: meta
@spec add_env_data(map, Span.t()) :: map
defp add_env_data(meta, %Span{env: nil}), do: meta

defp add_datadog_meta(meta, %Span{env: env}) do
defp add_env_data(meta, %Span{env: env}) do
Map.put(meta, :env, env)
end

@spec add_version_data(map, Span.t()) :: map
defp add_version_data(meta, %Span{service_version: nil}), do: meta

defp add_version_data(meta, %Span{service_version: version}) do
Map.put(meta, :version, version)
end

@spec add_error_data(map, Span.t()) :: map
defp add_error_data(meta, %{error: nil}), do: meta

Expand Down
1 change: 1 addition & 0 deletions test/adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule SpandexDatadog.Test.AdapterTest do
Enum.each(spans, fn span ->
assert span.service == :spandex_test
assert span.meta.env == "test"
assert span.meta.version == "v1"
end)
end

Expand Down
3 changes: 3 additions & 0 deletions test/api_server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule SpandexDatadog.ApiServerTest do
id: 4_743_028_846_331_200_906,
start: 1_527_752_052_216_478_000,
service: :foo,
service_version: "v1",
env: "local",
name: "foo",
trace_id: trace_id,
Expand Down Expand Up @@ -175,6 +176,7 @@ defmodule SpandexDatadog.ApiServerTest do
"buz" => "blitz",
"env" => "local",
"foo" => "123",
"version" => "v1",
"zyx" => "[xyz: {1, 2}]"
},
"metrics" => %{
Expand Down Expand Up @@ -265,6 +267,7 @@ defmodule SpandexDatadog.ApiServerTest do
"buz" => "blitz",
"env" => "local",
"foo" => "123",
"version" => "v1",
"zyx" => "[xyz: {1, 2}]"
},
"metrics" => %{
Expand Down

0 comments on commit ffb27a0

Please sign in to comment.