Skip to content

Commit

Permalink
Support service version tagging (#57)
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`.

Co-authored-by: Kamil Kowalski <[email protected]>
  • Loading branch information
gorkunov and kamilkowalski authored Jan 16, 2023
1 parent 65d8f88 commit 811629d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 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 @@ -280,7 +280,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 @@ -289,13 +290,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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule SpandexDatadog.MixProject do
defp deps do
[
{:msgpax, "~> 2.2.1 or ~> 2.3"},
{:spandex, "~> 3.0"},
{:spandex, "~> 3.2"},
{:telemetry, "~> 0.4.2 or ~> 1.0"},
# Dev- and test-only deps
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"optimal": {:hex, :optimal, "0.3.6", "46bbf52fbbbd238cda81e02560caa84f93a53c75620f1fe19e81e4ae7b07d1dd", [:mix], [], "hexpm", "1a06ea6a653120226b35b283a1cd10039550f2c566edcdec22b29316d73640fd"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"},
"plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
"spandex": {:hex, :spandex, "3.1.0", "e43df29af70f6f0c13ddd07a5e68650e13dd2a76c6215977c651e64412e8ebee", [:mix], [{:decorator, "~> 1.2", [hex: :decorator, repo: "hexpm", optional: true]}, {:optimal, "~> 0.3.3", [hex: :optimal, repo: "hexpm", optional: false]}, {:plug, ">= 1.0.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "6b053ab307856e34237f06a5ea931eeadf78bdd6f00a49bbfb4103e004a3d3c7"},
"spandex": {:hex, :spandex, "3.2.0", "f8cd40146ea988c87f3c14054150c9a47ba17e53cd4515c00e1f93c29c45404d", [:mix], [{:decorator, "~> 1.2", [hex: :decorator, repo: "hexpm", optional: true]}, {:optimal, "~> 0.3.3", [hex: :optimal, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d0a7d5aef4c5af9cf5467f2003e8a5d8d2bdae3823a6cc95d776b9a2251d4d03"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
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 811629d

Please sign in to comment.