From abf36321e6d34e5433a7f81d5fd780d83680afad Mon Sep 17 00:00:00 2001 From: Kamil Kowalski Date: Sun, 29 Nov 2020 16:39:34 +0100 Subject: [PATCH] Remove opts validation and Optimal as a dependency --- lib/plug/add_context.ex | 52 ++++------ lib/plug/end_trace.ex | 28 ++---- lib/plug/start_trace.ex | 46 ++++----- lib/span.ex | 213 +++++++++++++++++----------------------- lib/spandex.ex | 43 ++------ lib/tracer.ex | 104 +++++++------------- mix.exs | 4 +- mix.lock | 1 - test/spandex_test.exs | 83 ---------------- 9 files changed, 183 insertions(+), 391 deletions(-) diff --git a/lib/plug/add_context.ex b/lib/plug/add_context.ex index 43a2788..d9a5c7a 100644 --- a/lib/plug/add_context.ex +++ b/lib/plug/add_context.ex @@ -1,51 +1,39 @@ defmodule Spandex.Plug.AddContext do @moduledoc """ Adds request context to the top span of the trace, setting - the resource, method, url, service, type and env + the resource, method, url, service, type and env. + + ## Options + + This plug accepts the following options: + + * `:tracer` - The tracing module to be used to start the trace. Required. + * `:allowed_route_replacements` - A list of route parts that may be replaced with their actual value. + If not set or set to nil, then all will be allowed, unless they are disallowed. + * `:disallowed_route_replacements` - A list of route parts that may *not* be replaced with their actual value. + * `:query_params` - A list of query params who's value will be included in the resource name. + * `:tracer_opts` - Any opts to be passed to the tracer when starting or continuing the trace. """ @behaviour Plug alias Spandex.Plug.Utils - @init_opts Optimal.schema( - opts: [ - allowed_route_replacements: [{:list, :atom}, nil], - disallowed_route_replacements: {:list, :atom}, - query_params: {:list, :atom}, - tracer: :atom, - tracer_opts: :keyword - ], - defaults: [ - allowed_route_replacements: nil, - disallowed_route_replacements: [], - query_params: [], - tracer_opts: [] - ], - required: [:tracer], - describe: [ - tracer: "The tracing module to be used to start the trace.", - tracer_opts: "Any opts to be passed to the tracer when starting or continuing the trace.", - allowed_route_replacements: - "A list of route parts that may be replaced with their actual value. " <> - "If not set or set to nil, then all will be allowed, unless they are disallowed.", - disallowed_route_replacements: - "A list of route parts that may *not* be replaced with their actual value.", - query_params: "A list of query params who's value will be included in the resource name." - ] - ) + @default_opts [ + allowed_route_replacements: nil, + disallowed_route_replacements: [], + query_params: [], + tracer_opts: [] + ] @doc """ Starts a trace, considering the filters/parameters in the provided options. - #{Optimal.Doc.document(@init_opts)} - You would generally not use `allowed_route_replacements` and `disallowed_route_replacements` together. """ @spec init(opts :: Keyword.t()) :: Keyword.t() def init(opts) do - opts = Optimal.validate!(opts, @init_opts) - - opts + @default_opts + |> Keyword.merge(opts || []) |> Keyword.update!(:allowed_route_replacements, fn config -> if config do Enum.map(config, &Atom.to_string/1) diff --git a/lib/plug/end_trace.ex b/lib/plug/end_trace.ex index 939310c..245679e 100644 --- a/lib/plug/end_trace.ex +++ b/lib/plug/end_trace.ex @@ -1,34 +1,26 @@ defmodule Spandex.Plug.EndTrace do @moduledoc """ Finishes a trace, setting status and error based on the HTTP status. + + ## Options + + This plug accepts the following options: + + * `:tracer` - The tracing module to be used to start the trace. Required. + * `:tracer_opts` - Any opts to be passed to the tracer when starting or continuing the trace. """ @behaviour Plug alias Spandex.Plug.Utils - @init_opts Optimal.schema( - opts: [ - tracer: :atom, - tracer_opts: :keyword - ], - defaults: [ - tracer_opts: [] - ], - required: [:tracer], - describe: [ - tracer: "The tracing module to be used to start the trace.", - tracer_opts: "Any opts to be passed to the tracer when starting or continuing the trace." - ] - ) + @default_opts [tracer_opts: []] @doc """ - Accepts and validates opts for the plug, and underlying tracer. - - #{Optimal.Doc.document(@init_opts)} + Accepts opts for the plug, and underlying tracer. """ @spec init(opts :: Keyword.t()) :: Keyword.t() def init(opts) do - Optimal.validate!(opts, @init_opts) + Keyword.merge(@default_opts, opts) end @spec call(conn :: Plug.Conn.t(), _opts :: Keyword.t()) :: Plug.Conn.t() diff --git a/lib/plug/start_trace.ex b/lib/plug/start_trace.ex index 3cad71e..8b627a4 100644 --- a/lib/plug/start_trace.ex +++ b/lib/plug/start_trace.ex @@ -2,44 +2,34 @@ defmodule Spandex.Plug.StartTrace do @moduledoc """ Starts a trace, skipping ignored routes or methods. Store info in Conn assigns if we actually trace the request. + + ## Options + + This plug accepts the following options: + + * `:tracer` - The tracing module to be used to start the trace. Required. + * `:ignored_methods` - A list of strings representing methods to ignore. A good example would be `["OPTIONS"]`. + * `:ignored_routes` - A list of strings or regexes. If it is a string, it must match exactly. + * `:tracer_opts` - Any opts to be passed to the tracer when starting or continuing the trace. + * `:span_name` - The name to be used for the top level span. """ @behaviour Plug alias Spandex.Plug.Utils alias Spandex.SpanContext - @init_opts Optimal.schema( - opts: [ - ignored_methods: {:list, :string}, - ignored_routes: {:list, [:regex, :string]}, - tracer: :atom, - tracer_opts: :keyword, - span_name: :string - ], - defaults: [ - ignored_methods: [], - ignored_routes: [], - tracer_opts: [], - span_name: "request" - ], - required: [:tracer], - describe: [ - ignored_methods: - "A list of strings representing methods to ignore. A good example would be `[\"OPTIONS\"]`", - ignored_routes: "A list of strings or regexes. If it is a string, it must match exactly.", - tracer: "The tracing module to be used to start the trace.", - tracer_opts: "Any opts to be passed to the tracer when starting or continuing the trace.", - span_name: "The name to be used for the top level span." - ] - ) + @default_opts [ + ignored_methods: [], + ignored_routes: [], + tracer_opts: [], + span_name: "request" + ] @doc """ - Accepts and validates opts for the plug, and underlying tracer. - - #{Optimal.Doc.document(@init_opts)} + Accepts opts for the plug, and underlying tracer. """ @spec init(opts :: Keyword.t()) :: Keyword.t() - def init(opts), do: Optimal.validate!(opts, @init_opts) + def init(opts), do: Keyword.merge(@default_opts, opts) @spec call(conn :: Plug.Conn.t(), opts :: Keyword.t()) :: Plug.Conn.t() def call(conn, opts) do diff --git a/lib/span.ex b/lib/span.ex index 95acdee..ab6eb8c 100644 --- a/lib/span.ex +++ b/lib/span.ex @@ -1,28 +1,65 @@ defmodule Spandex.Span do @moduledoc """ A container for all span data and metadata. + + ## Special metadata + + Apart from regular trace options, `Spandex.Span` allows specifying special + metadata often used in web transaction tracing. These are: + + * `http` - metadata relating to the HTTP request, + * `error` - information about the error raised during processing of the span, + * `sql_query` - information about the SQL query this span represents. + + ### Example + + ```elixir + [ + http: [ + url: "my_website.com?foo=bar", + status_code: "400", + method: "GET", + query_string: "foo=bar", + user_agent: "Mozilla/5.0...", + request_id: "special_id" + ], + error: [ + exception: ArgumentError.exception("foo"), + stacktrace: __STACKTRACE__, + error?: true # Used for specifying that a span is an error when there is no exception or stacktrace. + ], + sql_query: [ + rows: 100, + db: "my_database", + query: "SELECT * FROM users;" + ], + # Private has the same structure as the outer meta structure, but private metadata does not + # transfer from parent span to child span. + private: [ + ... + ] + ] + ``` """ alias Spandex.Span - defstruct [ - :completion_time, - :env, - :error, - :http, - :id, - :name, - :parent_id, - :private, - :resource, - :service, - :services, - :sql_query, - :start, - :tags, - :trace_id, - :type - ] + defstruct completion_time: nil, + env: nil, + error: nil, + http: nil, + id: nil, + name: nil, + parent_id: nil, + private: [], + resource: nil, + service: nil, + services: [], + sql_query: nil, + start: nil, + tags: [], + trace_id: nil, + type: nil @nested_opts [:error, :http, :sql_query] @@ -45,99 +82,45 @@ defmodule Spandex.Span do type: atom() } - @span_opts Optimal.schema( - opts: [ - completion_time: :integer, - env: :string, - error: :keyword, - http: :keyword, - id: :any, - name: :string, - parent_id: :any, - private: :keyword, - resource: [:atom, :string], - service: :atom, - services: :keyword, - sql_query: :keyword, - start: :integer, - tags: :keyword, - trace_id: :any, - type: :atom - ], - defaults: [ - private: [], - services: [], - tags: [] - ], - required: [ - :id, - :name, - :service, - :start, - :trace_id - ], - extra_keys?: true - ) - - def span_opts(), do: @span_opts + @type option :: + {:completion_time, integer()} + | {:env, String.t()} + | {:error, Keyword.t()} + | {:http, Keyword.t()} + | {:id, Spandex.id()} + | {:name, String.t()} + | {:parent_id, Spandex.id()} + | {:private, Keyword.t()} + | {:resource, atom() | String.t()} + | {:service, atom()} + | {:services, Keyword.t()} + | {:sql_query, Keyword.t()} + | {:start, Spandex.timestamp()} + | {:tags, Keyword.t()} + | {:trace_id, term()} + | {:type, atom()} + + @type opts :: [option()] @doc """ - Create a new span. - - #{Optimal.Doc.document(@span_opts)} + Creates a new span. """ - @spec new(Keyword.t()) :: - {:ok, Span.t()} - | {:error, [Optimal.error()]} + @spec new(Span.opts()) :: {:ok, Span.t()} def new(opts) do - update(nil, opts, @span_opts) + update(nil, opts) end @doc """ - Update an existing span. - - #{Optimal.Doc.document(Map.put(@span_opts, :required, []))} - - ## Special Meta - - ```elixir - [ - http: [ - url: "my_website.com?foo=bar", - status_code: "400", - method: "GET", - query_string: "foo=bar", - user_agent: "Mozilla/5.0...", - request_id: "special_id" - ], - error: [ - exception: ArgumentError.exception("foo"), - stacktrace: __STACKTRACE__, - error?: true # Used for specifying that a span is an error when there is no exception or stacktrace. - ], - sql_query: [ - rows: 100, - db: "my_database", - query: "SELECT * FROM users;" - ], - # Private has the same structure as the outer meta structure, but private metadata does not - # transfer from parent span to child span. - private: [ - ... - ] - ] - ``` + Updates an existing span. """ - @spec update(Span.t() | nil, Keyword.t(), Optimal.Schema.t()) :: - {:ok, Span.t()} - | {:error, [Optimal.error()]} - def update(span, opts, schema \\ Map.put(@span_opts, :required, [])) do + @spec update(Span.t() | nil, Span.opts()) :: {:ok, Span.t()} + def update(span, opts) do opts_without_nils = Enum.reject(opts, fn {_key, value} -> is_nil(value) end) starting_opts = span - |> Kernel.||(%{}) - |> Map.take(schema.opts) + |> Kernel.||(%Span{}) + |> Map.from_struct() |> Enum.reject(fn {_key, value} -> is_nil(value) end) |> merge_retaining_nested(opts_without_nils) @@ -150,7 +133,14 @@ defmodule Spandex.Span do starting_opts end - validate_and_merge(span, with_type, schema) + new_span = + if span do + struct(span, with_type) + else + struct(Span, with_type) + end + + {:ok, new_span} end @spec merge_retaining_nested(Keyword.t(), Keyword.t()) :: Keyword.t() @@ -195,29 +185,8 @@ defmodule Spandex.Span do end) end - @spec validate_and_merge(Span.t() | nil, Keyword.t(), Optimal.schema()) :: - {:ok, Span.t()} - | {:error, [Optimal.error()]} - defp validate_and_merge(span, opts, schema) do - case Optimal.validate(opts, schema) do - {:ok, opts} -> - new_span = - if span do - struct(span, opts) - else - struct(Span, opts) - end - - {:ok, new_span} - - {:error, errors} -> - {:error, errors} - end - end - - @spec child_of(Span.t(), String.t(), Spandex.id(), Spandex.timestamp(), Keyword.t()) :: + @spec child_of(Span.t(), String.t(), Spandex.id(), Spandex.timestamp(), Span.opts()) :: {:ok, Span.t()} - | {:error, [Optimal.error()]} def child_of(parent_span, name, id, start, opts) do child = %Span{parent_span | id: id, name: name, start: start, parent_id: parent_span.id} update(child, opts) diff --git a/lib/spandex.ex b/lib/spandex.ex index c4de405..8c47985 100644 --- a/lib/spandex.ex +++ b/lib/spandex.ex @@ -22,15 +22,12 @@ defmodule Spandex do @doc """ Starts a new trace. - Span updates for the first span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a second call to `update_span/2` and check the return value. + Span updates for the first span may be passed in. """ @spec start_trace(binary(), Tracer.opts()) :: {:ok, Trace.t()} | {:error, :disabled} | {:error, :trace_running} - | {:error, [Optimal.error()]} def start_trace(_, :disabled), do: {:error, :disabled} def start_trace(name, opts) do @@ -47,9 +44,7 @@ defmodule Spandex do @doc """ Start a new span. - Span updates for that span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a second call to `update_span/2` and check the return value. + Span updates for that span may be passed in. """ @spec start_span(String.t(), Tracer.opts()) :: {:ok, Span.t()} @@ -74,15 +69,12 @@ defmodule Spandex do @doc """ Updates the current span. - - In the case of an invalid update, validation errors are returned. """ @spec update_span(Tracer.opts(), boolean()) :: {:ok, Span.t()} | {:error, :disabled} | {:error, :no_trace_context} | {:error, :no_span_context} - | {:error, [Optimal.error()]} def update_span(opts, top? \\ false) def update_span(:disabled, _), do: {:error, :disabled} @@ -110,28 +102,22 @@ defmodule Spandex do Any spans that have already been started will not inherit any of the updates from that span. For instance, if you change `service`, it will not be reflected in already-started spans. - - In the case of an invalid update, validation errors are returned. """ @spec update_top_span(Tracer.opts()) :: {:ok, Span.t()} | {:error, :disabled} | {:error, :no_trace_context} - | {:error, [Optimal.error()]} def update_top_span(:disabled), do: {:error, :disabled} def update_top_span(opts), do: update_span(opts, true) @doc """ Updates all spans, whether complete or in-progress. - - In the case of an invalid update for any span, validation errors are returned. """ @spec update_all_spans(Tracer.opts()) :: {:ok, Trace.t()} | {:error, :disabled} | {:error, :no_trace_context} - | {:error, [Optimal.error()]} def update_all_spans(:disabled), do: {:error, :disabled} def update_all_spans(opts) do @@ -147,10 +133,7 @@ defmodule Spandex do @doc """ Finishes the current trace. - Span updates for the top span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a call to `update_span/2` and check the return value before - finishing the trace. + Span updates for the top span may be passed in. """ @spec finish_trace(Tracer.opts()) :: {:ok, Trace.t()} @@ -186,10 +169,7 @@ defmodule Spandex do @doc """ Finishes the current span. - Span updates for that span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a call to `update_span/2` and check the return value before - finishing the span. + Span updates for that span may be passed in. """ @spec finish_span(Tracer.opts()) :: {:ok, Span.t()} @@ -231,15 +211,12 @@ defmodule Spandex do @doc """ Updates the current span with error details. - - In the case of an invalid value, validation errors are returned. """ @spec span_error(Exception.t(), Enum.t(), Tracer.opts()) :: {:ok, Span.t()} | {:error, :disabled} | {:error, :no_trace_context} | {:error, :no_span_context} - | {:error, [Optimal.error()]} def span_error(_error, _stacktrace, :disabled), do: {:error, :disabled} def span_error(exception, stacktrace, opts) do @@ -337,9 +314,7 @@ defmodule Spandex do @doc """ Given a `%SpanContext{}`, resumes a trace from a different process or service. - Span updates for the top span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a second call to `update_span/2` and check the return value. + Span updates for the top span may be passed in. """ @spec continue_trace(String.t(), SpanContext.t(), Keyword.t()) :: {:ok, Trace.t()} @@ -361,9 +336,7 @@ defmodule Spandex do @doc """ Given a trace_id and span_id, resumes a trace from a different process or service. - Span updates for the top span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a second call to `update_span/2` and check the return value. + Span updates for the top span may be passed in. """ @spec continue_trace(String.t(), Spandex.id(), Spandex.id(), Keyword.t()) :: {:ok, Trace.t()} @@ -379,9 +352,7 @@ defmodule Spandex do @doc """ Given a span struct, resumes a trace from a different process or service. - Span updates for the top span may be passed in. They are skipped if they are - invalid updates. As such, if you aren't sure if your updates are valid, it is - safer to perform a second call to `update_span/2` and check the return value. + Span updates for the top span may be passed in. """ @spec continue_trace_from_span(String.t(), Span.t(), Tracer.opts()) :: {:ok, Trace.t()} diff --git a/lib/tracer.ex b/lib/tracer.ex index a6242b7..37b28b3 100644 --- a/lib/tracer.ex +++ b/lib/tracer.ex @@ -9,6 +9,20 @@ defmodule Spandex.Tracer do use Spandex.Tracer, otp_app: :my_app end ``` + + ## Options + + All tracer functions accept the following tracer options: + + * `:adapter` - The third party adapter to use. Required. + * `:service` - The default service name to use for spans declared without a service. Required. + * `:disabled?` - Allows for wholesale disabling a tracer. + * `:env` - A name used to identify the environment name, e.g `prod` or `development`. + * `:services` - A mapping of service name to the default span types. + * `:strategy` - The storage and tracing strategy. Currently only supports local process dictionary. + * `:sender` - Once a trace is complete, it is sent using this module. Defaults to the `default_sender/0` of the selected adapter. + + Additionally, you can pass any `Spandex.Span.option()` and it will be merged into the span. """ alias Spandex.{ @@ -19,7 +33,17 @@ defmodule Spandex.Tracer do @type tagged_tuple(arg) :: {:ok, arg} | {:error, term()} @type span_name() :: String.t() - @type opts :: Keyword.t() | :disabled + @type option :: + {:adapter, atom()} + | {:service, atom()} + | {:disabled?, boolean()} + | {:env, String.t()} + | {:services, keyword(atom())} + | {:strategy, atom()} + | {:sender, atom()} + | {:trace_key, atom()} + | Span.option() + @type opts :: [option()] | :disabled @callback configure(opts) :: :ok @callback start_trace(span_name, opts) :: tagged_tuple(Trace.t()) @@ -39,61 +63,11 @@ defmodule Spandex.Tracer do | {:error, :disabled} | {:error, :no_span_context} | {:error, :no_trace_context} - | {:error, [Optimal.error()]} @callback distributed_context(Plug.Conn.t(), opts) :: tagged_tuple(map) @callback inject_context(Spandex.headers(), opts) :: Spandex.headers() @macrocallback span(span_name, opts, do: Macro.t()) :: Macro.t() @macrocallback trace(span_name, opts, do: Macro.t()) :: Macro.t() - @tracer_opts Optimal.schema( - opts: [ - adapter: :atom, - service: :atom, - disabled?: :boolean, - env: :string, - services: {:keyword, :atom}, - strategy: :atom, - sender: :atom, - trace_key: :atom - ], - required: [:adapter, :service], - defaults: [ - disabled?: false, - services: [], - strategy: Spandex.Strategy.Pdict - ], - describe: [ - adapter: "The third party adapter to use", - trace_key: "Don't set manually. This option is passed automatically.", - sender: - "Once a trace is complete, it is sent using this module. Defaults to the `default_sender/0` of the selected adapter", - service: "The default service name to use for spans declared without a service", - disabled?: "Allows for wholesale disabling a tracer", - env: "A name used to identify the environment name, e.g `prod` or `development`", - services: "A mapping of service name to the default span types.", - strategy: "The storage and tracing strategy. Currently only supports local process dictionary." - ] - ) - - @all_tracer_opts @tracer_opts - |> Optimal.merge( - Span.span_opts(), - annotate: "Span Creation", - add_required?: false - ) - |> Map.put(:extra_keys?, false) - - @doc """ - A schema for the opts that a tracer accepts. - - #{Optimal.Doc.document(@all_tracer_opts)} - - All tracer functions that take opts use this schema. - This also accepts defaults for any value that can - be given to a span. - """ - def tracer_opts(), do: @all_tracer_opts - defmacro __using__(opts) do # credo:disable-for-next-line Credo.Check.Refactor.LongQuoteBlocks quote do @@ -101,7 +75,7 @@ defmodule Spandex.Tracer do @behaviour Spandex.Tracer - @opts Spandex.Tracer.tracer_opts() + @default_opts [disabled?: false, services: [], strategy: Spandex.Strategy.Pdict] @doc """ Use to create and configure a tracer. @@ -171,25 +145,25 @@ defmodule Spandex.Tracer do @impl Spandex.Tracer def update_span(opts) do - Spandex.update_span(validate_update_config(opts, @otp_app)) + Spandex.update_span(update_config(opts, @otp_app)) end @impl Spandex.Tracer def update_top_span(opts) do - Spandex.update_top_span(validate_update_config(opts, @otp_app)) + Spandex.update_top_span(update_config(opts, @otp_app)) end @impl Spandex.Tracer def finish_trace(opts \\ []) do opts - |> validate_update_config(@otp_app) + |> update_config(@otp_app) |> Spandex.finish_trace() end @impl Spandex.Tracer def finish_span(opts \\ []) do opts - |> validate_update_config(@otp_app) + |> update_config(@otp_app) |> Spandex.finish_span() end @@ -259,11 +233,11 @@ defmodule Spandex.Tracer do end defp merge_config(opts, otp_app) do - otp_app - |> Application.get_env(__MODULE__) - |> Kernel.||([]) + env = Application.get_env(otp_app, __MODULE__) + + @default_opts + |> Keyword.merge(env || []) |> Keyword.merge(opts || []) - |> Optimal.validate!(@opts) |> Keyword.put(:trace_key, __MODULE__) end @@ -277,19 +251,13 @@ defmodule Spandex.Tracer do end end - defp validate_update_config(opts, otp_app) do - env = Application.get_env(otp_app, __MODULE__) + defp update_config(opts, otp_app) do + env = Application.get_env(otp_app, __MODULE__, []) if env[:disabled?] do :disabled else - schema = %{@opts | defaults: [], required: []} - - # TODO: We may want to have some concept of "the quintessential tracer configs" - # So that we can take those here, instead of embedding that knowledge here. - opts - |> Optimal.validate!(schema) |> Keyword.put(:trace_key, __MODULE__) |> Keyword.put(:strategy, env[:strategy] || Spandex.Strategy.Pdict) |> Keyword.put(:adapter, env[:adapter]) diff --git a/mix.exs b/mix.exs index 2ced634..06f8d2f 100644 --- a/mix.exs +++ b/mix.exs @@ -58,6 +58,7 @@ defmodule Spandex.Mixfile do [ {:benchee, "~> 0.13.2", only: [:dev, :test]}, {:credo, "~> 0.9.2", only: [:dev, :test], runtime: false}, + {:decorator, "~> 1.2", optional: true}, {:dialyxir, "~> 0.5", only: [:dev], runtime: false}, {:ex_doc, ">= 0.19.0", only: :dev, runtime: false}, {:excoveralls, "~> 0.10", only: :test}, @@ -66,9 +67,6 @@ defmodule Spandex.Mixfile do {:makeup, "~> 1.0.1", only: :dev}, {:makeup_elixir, "~> 0.14.0", only: :dev}, {:nimble_parsec, "~> 0.5.3", only: :dev}, - - {:decorator, "~> 1.2", optional: true}, - {:optimal, "~> 0.3.3"}, {:plug, ">= 1.0.0"} ] end diff --git a/mix.lock b/mix.lock index 27cb226..34ff48a 100644 --- a/mix.lock +++ b/mix.lock @@ -21,7 +21,6 @@ "mime": {:hex, :mime, "1.4.0", "5066f14944b470286146047d2f73518cf5cca82f8e4815cf35d196b58cf07c47", [:mix], [], "hexpm", "75fa42c4228ea9a23f70f123c74ba7cece6a03b1fd474fe13f6a7a85c6ea4ff6"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm", "589b5af56f4afca65217a1f3eb3fee7e79b09c40c742fddc1c312b3ac0b3399f"}, - "optimal": {:hex, :optimal, "0.3.6", "46bbf52fbbbd238cda81e02560caa84f93a53c75620f1fe19e81e4ae7b07d1dd", [:mix], [], "hexpm", "1a06ea6a653120226b35b283a1cd10039550f2c566edcdec22b29316d73640fd"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, "plug": {:hex, :plug, "1.10.4", "41eba7d1a2d671faaf531fa867645bd5a3dce0957d8e2a3f398ccff7d2ef017f", [:mix], [{:mime, "~> 1.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", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad1e233fe73d2eec56616568d260777b67f53148a999dc2d048f4eb9778fe4a0"}, "plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"}, diff --git a/test/spandex_test.exs b/test/spandex_test.exs index 2466546..55edd40 100644 --- a/test/spandex_test.exs +++ b/test/spandex_test.exs @@ -54,11 +54,6 @@ defmodule Spandex.Test.SpandexTest do assert {:error, :disabled} = Spandex.start_trace("root_span", :disabled) end - test "returns an error if invalid options are specified" do - assert {:error, validation_errors} = Spandex.start_trace("root_span", @base_opts) - assert {:service, "is required"} in validation_errors - end - test "adds span_id, trace_id to log metadata" do opts = @base_opts ++ @span_opts @@ -98,15 +93,6 @@ defmodule Spandex.Test.SpandexTest do assert %Span{name: "span_name", service: :test_service, resource: "test_resource"} = span end - test "returns an error if invalid options are specified" do - opts = @base_opts ++ @span_opts - assert {:ok, %Trace{id: _trace_id}} = Spandex.start_trace("root_span", opts) - - assert {:error, validation_errors} = Spandex.start_span("span_name", @base_opts ++ [type: "not an atom"]) - - assert {:type, "must be of type :atom"} in validation_errors - end - test "adds span_id, trace_id to log metadata" do opts = @base_opts ++ @span_opts @@ -154,15 +140,6 @@ defmodule Spandex.Test.SpandexTest do test "returns an error if tracing is disabled" do assert {:error, :disabled} = Spandex.update_span(:disabled) end - - test "returns an error if invalid options are specified" do - opts = @base_opts ++ @span_opts - assert {:ok, %Trace{id: _trace_id}} = Spandex.start_trace("root_span", opts) - - assert {:error, validation_errors} = Spandex.update_span(@base_opts ++ [type: "not an atom"]) - - assert {:type, "must be of type :atom"} in validation_errors - end end describe "Spandex.update_span/2" do @@ -222,15 +199,6 @@ defmodule Spandex.Test.SpandexTest do test "returns an error if tracing is disabled" do assert {:error, :disabled} = Spandex.update_top_span(:disabled) end - - test "returns an error if invalid options are specified" do - opts = @base_opts ++ @span_opts - assert {:ok, %Trace{id: _trace_id}} = Spandex.start_trace("root_span", opts) - - assert {:error, validation_errors} = Spandex.update_top_span(@base_opts ++ [type: "not an atom"]) - - assert {:type, "must be of type :atom"} in validation_errors - end end describe "Spandex.update_all_spans/1" do @@ -257,15 +225,6 @@ defmodule Spandex.Test.SpandexTest do test "returns an error if tracing is disabled" do assert {:error, :disabled} = Spandex.update_all_spans(:disabled) end - - test "returns an error if invalid options are specified" do - opts = @base_opts ++ @span_opts - assert {:ok, %Trace{id: _trace_id}} = Spandex.start_trace("root_span", opts) - - assert {:error, validation_errors} = Spandex.update_all_spans(@base_opts ++ [type: "not an atom"]) - - assert {:type, "must be of type :atom"} in validation_errors - end end describe "Spandex.finish_trace/1" do @@ -437,20 +396,6 @@ defmodule Spandex.Test.SpandexTest do test "returns an error if tracing is disabled" do assert {:error, :disabled} = Spandex.span_error(@runtime_error, @fake_stacktrace, :disabled) end - - test "returns an error if invalid options are specified" do - opts = @base_opts ++ @span_opts - assert {:ok, %Trace{id: _trace_id}} = Spandex.start_trace("root_span", opts) - - assert {:error, validation_errors} = - Spandex.span_error( - @runtime_error, - @fake_stacktrace, - @base_opts ++ [type: "not an atom"] - ) - - assert {:type, "must be of type :atom"} in validation_errors - end end describe "Spandex.current_trace_id/1" do @@ -567,14 +512,6 @@ defmodule Spandex.Test.SpandexTest do assert {:error, :disabled} == Spandex.continue_trace("span_name", span_context, :disabled) end - test "returns an error if invalid options are specified" do - opts = @base_opts ++ [type: "not an atom"] - span_context = %SpanContext{trace_id: 123, parent_id: 456} - assert {:error, validation_errors} = Spandex.continue_trace("span_name", span_context, opts) - - assert {:type, "must be of type :atom"} in validation_errors - end - test "adds span_id, trace_id to log metadata" do opts = @base_opts ++ @span_opts span_context = %SpanContext{trace_id: 123, parent_id: 456} @@ -613,13 +550,6 @@ defmodule Spandex.Test.SpandexTest do assert {:error, :disabled} == Spandex.continue_trace("span_name", 123, 456, :disabled) end - test "returns an error if invalid options are specified" do - assert {:error, validation_errors} = - Spandex.continue_trace("span_name", 123, 456, @base_opts ++ [type: "not an atom"]) - - assert {:type, "must be of type :atom"} in validation_errors - end - test "adds span_id, trace_id to log metadata" do opts = @base_opts ++ @span_opts @@ -663,19 +593,6 @@ defmodule Spandex.Test.SpandexTest do assert {:error, :disabled} == Spandex.continue_trace_from_span("root_span", existing_span, :disabled) end - - test "returns an error if invalid options are specified" do - existing_span = %Span{id: 456, trace_id: 123, name: "existing"} - - assert {:error, validation_errors} = - Spandex.continue_trace_from_span( - "span_name", - existing_span, - @base_opts ++ [type: "not an atom"] - ) - - assert {:type, "must be of type :atom"} in validation_errors - end end describe "Spandex.distributed_context/2 with Plug.Conn" do