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

Remove usage of the transitive dependency Optimal #33

Merged
merged 3 commits into from
Sep 25, 2021
Merged
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
61 changes: 23 additions & 38 deletions lib/spandex_datadog/api_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,36 @@ 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",
http: HTTPoison,
port: 8126,
verbose?: false,
batch_size: 10,
sync_threshold: 20,
api_adapter: SpandexDatadog.ApiServer
]

@doc """
Starts genserver with given options.
Starts the ApiServer with given options.

#{Optimal.Doc.document(@start_link_opts)}
## 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
opts = Optimal.validate!(opts, @start_link_opts)
def start_link(opts \\ []) do
opts = Keyword.merge(@default_opts, opts)

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)
Expand Down Expand Up @@ -150,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, [])

Expand Down