From 4d9420c09b441ecddb5be590d91009b06a49868f Mon Sep 17 00:00:00 2001 From: Kamil Kowalski Date: Sat, 6 Feb 2021 17:24:34 +0100 Subject: [PATCH 1/3] Remove usage of the transitive dependency Optimal --- lib/spandex_datadog/api_server.ex | 54 ++++++++++++------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/lib/spandex_datadog/api_server.ex b/lib/spandex_datadog/api_server.ex index 6b5b89f..00da1e8 100644 --- a/lib/spandex_datadog/api_server.ex +++ b/lib/spandex_datadog/api_server.ex @@ -1,6 +1,17 @@ defmodule SpandexDatadog.ApiServer do @moduledoc """ Implements worker for sending spans to datadog as GenServer in order to send traces async. + + ## Options + + The following options can be passed to `SpandexDatadog.ApiServer.start_link/1`: + + * `:http` - The HTTP module to use for sending spans to the agent. Currently only HTTPoison has been tested. Required. + * `:host` - The host the agent can be reached at. Defaults to "localhost". + * `:port` - The port to use when sending traces to the agent. Defaults to 8126. + * `:verbose?` - Only to be used for debugging: All finished traces will be logged. + * `:batch_size` - The number of traces that should be sent in a single batch. Defaults to 10. + * `:sync_threshold` - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to 20. """ use GenServer @@ -35,46 +46,21 @@ defmodule SpandexDatadog.ApiServer do @headers [{"Content-Type", "application/msgpack"}] - @start_link_opts Optimal.schema( - opts: [ - host: :string, - port: [:integer, :string], - verbose?: :boolean, - http: :atom, - batch_size: :integer, - sync_threshold: :integer, - api_adapter: :atom - ], - defaults: [ - host: "localhost", - port: 8126, - verbose?: false, - batch_size: 10, - sync_threshold: 20, - api_adapter: SpandexDatadog.ApiServer - ], - required: [:http], - describe: [ - verbose?: "Only to be used for debugging: All finished traces will be logged", - host: "The host the agent can be reached at", - port: "The port to use when sending traces to the agent", - batch_size: "The number of traces that should be sent in a single batch", - sync_threshold: - "The maximum number of processes that may be sending traces at any one time. This adds backpressure", - http: - "The HTTP module to use for sending spans to the agent. Currently only HTTPoison has been tested", - api_adapter: "Which api adapter to use. Currently only used for testing" - ] - ) + @default_opts [ + host: "localhost", + port: 8126, + verbose?: false, + batch_size: 10, + sync_threshold: 20, + api_adapter: SpandexDatadog.ApiServer + ] @doc """ Starts genserver with given options. - - #{Optimal.Doc.document(@start_link_opts)} """ @spec start_link(opts :: Keyword.t()) :: GenServer.on_start() def start_link(opts) do - opts = Optimal.validate!(opts, @start_link_opts) + opts = Keyword.merge(@default_opts, opts) GenServer.start_link(__MODULE__, opts, name: __MODULE__) end From 1354e285ee884f657ce4813ed57afb8f2df52497 Mon Sep 17 00:00:00 2001 From: Greg Mefford Date: Sat, 25 Sep 2021 10:51:31 -0400 Subject: [PATCH 2/3] Tidy up api_server opts, with sane defaults for all options --- lib/spandex_datadog/api_server.ex | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/spandex_datadog/api_server.ex b/lib/spandex_datadog/api_server.ex index 00da1e8..c68743b 100644 --- a/lib/spandex_datadog/api_server.ex +++ b/lib/spandex_datadog/api_server.ex @@ -6,12 +6,12 @@ defmodule SpandexDatadog.ApiServer do The following options can be passed to `SpandexDatadog.ApiServer.start_link/1`: - * `:http` - The HTTP module to use for sending spans to the agent. Currently only HTTPoison has been tested. Required. - * `:host` - The host the agent can be reached at. Defaults to "localhost". - * `:port` - The port to use when sending traces to the agent. Defaults to 8126. - * `:verbose?` - Only to be used for debugging: All finished traces will be logged. - * `:batch_size` - The number of traces that should be sent in a single batch. Defaults to 10. - * `:sync_threshold` - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to 20. + * `:http` - The HTTP module to use for sending spans to the agent. Defaults to `HTTPoison`. + * `:host` - The host the agent can be reached at. Defaults to `"localhost"`. + * `:port` - The port to use when sending traces to the agent. Defaults to `8126`. + * `:verbose?` - Only to be used for debugging: All finished traces will be logged. Defaults to `false` + * `:batch_size` - The number of traces that should be sent in a single batch. Defaults to `10`. + * `:sync_threshold` - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to `20`. """ use GenServer @@ -48,6 +48,7 @@ defmodule SpandexDatadog.ApiServer do @default_opts [ host: "localhost", + http: HTTPoison, port: 8126, verbose?: false, batch_size: 10, @@ -59,7 +60,7 @@ defmodule SpandexDatadog.ApiServer do Starts genserver with given options. """ @spec start_link(opts :: Keyword.t()) :: GenServer.on_start() - def start_link(opts) do + def start_link(opts \\ []) do opts = Keyword.merge(@default_opts, opts) GenServer.start_link(__MODULE__, opts, name: __MODULE__) From f346d9e22b30ca47c4879ede5ef530e1229be89b Mon Sep 17 00:00:00 2001 From: Greg Mefford Date: Sat, 25 Sep 2021 11:02:43 -0400 Subject: [PATCH 3/3] Move start_link docs back to the function itself --- lib/spandex_datadog/api_server.ex | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/spandex_datadog/api_server.ex b/lib/spandex_datadog/api_server.ex index c68743b..f8b7198 100644 --- a/lib/spandex_datadog/api_server.ex +++ b/lib/spandex_datadog/api_server.ex @@ -1,17 +1,6 @@ defmodule SpandexDatadog.ApiServer do @moduledoc """ Implements worker for sending spans to datadog as GenServer in order to send traces async. - - ## Options - - The following options can be passed to `SpandexDatadog.ApiServer.start_link/1`: - - * `:http` - The HTTP module to use for sending spans to the agent. Defaults to `HTTPoison`. - * `:host` - The host the agent can be reached at. Defaults to `"localhost"`. - * `:port` - The port to use when sending traces to the agent. Defaults to `8126`. - * `:verbose?` - Only to be used for debugging: All finished traces will be logged. Defaults to `false` - * `:batch_size` - The number of traces that should be sent in a single batch. Defaults to `10`. - * `:sync_threshold` - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to `20`. """ use GenServer @@ -57,7 +46,16 @@ defmodule SpandexDatadog.ApiServer do ] @doc """ - Starts genserver with given options. + Starts the ApiServer with given options. + + ## Options + + * `:http` - The HTTP module to use for sending spans to the agent. Defaults to `HTTPoison`. + * `:host` - The host the agent can be reached at. Defaults to `"localhost"`. + * `:port` - The port to use when sending traces to the agent. Defaults to `8126`. + * `:verbose?` - Only to be used for debugging: All finished traces will be logged. Defaults to `false` + * `:batch_size` - The number of traces that should be sent in a single batch. Defaults to `10`. + * `:sync_threshold` - The maximum number of processes that may be sending traces at any one time. This adds backpressure. Defaults to `20`. """ @spec start_link(opts :: Keyword.t()) :: GenServer.on_start() def start_link(opts \\ []) do @@ -66,9 +64,7 @@ defmodule SpandexDatadog.ApiServer do GenServer.start_link(__MODULE__, opts, name: __MODULE__) end - @doc """ - Builds server state. - """ + @doc false @spec init(opts :: Keyword.t()) :: {:ok, State.t()} def init(opts) do {:ok, agent_pid} = Agent.start_link(fn -> 0 end) @@ -137,12 +133,14 @@ defmodule SpandexDatadog.ApiServer do end @deprecated "Please use format/3 instead" + @doc false @spec format(Trace.t()) :: map() def format(%Trace{spans: spans, priority: priority, baggage: baggage}) do Enum.map(spans, fn span -> format(span, priority, baggage) end) end @deprecated "Please use format/3 instead" + @doc false @spec format(Span.t()) :: map() def format(%Span{} = span), do: format(span, 1, [])