Skip to content

Commit

Permalink
abstracting away most behavior from adapters, enabling storage strate…
Browse files Browse the repository at this point in the history
…gies (#53)
  • Loading branch information
zachdaniel authored Jun 4, 2018
1 parent 443a287 commit b1db34a
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 505 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ contained as keys for that struct. They illustrate the keys that are known to ei
keys or to have UI sugar with certain clients. Its hard to find any kind of list of these published
anywhere, so let me know if you know of more! Examples
```
```elixir
Spandex.update_span(type: :db, http: [url: "/posts", status_code: 400], sql_query: [query: "SELECT * FROM posts", rows: 10])
```
Expand All @@ -151,6 +151,10 @@ Spandex used to ship with function decorators, but those decorators had a habit
The current trace_id and span_id can be retrieved with `Tracer.current_trace_id()` and `Tracer.current_span_id()`. This can then be used as `Tracer.continue_trace("new_trace", trace_id, span_id)`. New spans can then be logged from there and will be sent in a separate batch.
## Strategies
There is (currently and temporarily) only one storage strategy, which can be changed via the `strategy` option. See tracer opt documentation for an example of setting it. To implement your own (ETS adapter should be on its way) simply implement the `Spandex.Strategy` behaviour. Keep in mind that the strategy is not an atomic pattern. It represents retrieving and wholesale replacing a trace, meaning that it is *not* safe to use across processes or concurrently. Each process should have its own store for its own generated spans. This should be fine because you can send multiple batches of spans for the same trace separately.
## Datadog Api Sender Performance
Originally, the library had an api server and spans were sent via `GenServer.cast`, but we've seen the need to introduce backpressure, and limit the overall amount of requests made. As such, the datadog api sender accepts `batch_size` and `sync_threshold` options.
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ config :logger, :console,
config :spandex, Spandex.Test.Support.Tracer,
service: :spandex_test,
adapter: Spandex.Adapters.Datadog,
env: "test",
sender: Spandex.Test.DatadogTestApiServer,
env: "test",
resource: "default",
services: [
spandex_test: :db
Expand Down
22 changes: 6 additions & 16 deletions lib/adapters/adapter.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
defmodule Spandex.Adapters.Adapter do
@moduledoc """
Describes the callback for a tracing adapter. Can be used to provide different
implementations of reporting/aggregating spans while still using the spandex
internal implementation.
The callbacks required to implement an adapter.
"""
@callback start_trace(String.t(), Keyword.t()) :: {:ok, term} | {:error, term}
@callback start_span(String.t(), Keyword.t()) :: {:ok, term} | {:error, term}
@callback update_span(Keyword.t()) :: :ok | {:error, term}
@callback finish_span(Keyword.t()) :: :ok | {:error, term}
@callback finish_trace(Keyword.t()) :: :ok | {:error, term}
@callback span_error(Exception.t(), Keyword.t()) :: :ok | {:error, term}
@callback current_trace_id(Keyword.t()) :: term | nil | {:error, term}
@callback current_span_id(Keyword.t()) :: term | nil | {:error, term}
@callback current_span(Keyword.t()) :: term | nil
@callback continue_trace(String.t(), term, term, Keyword.t()) :: {:ok, term} | {:error, term}
@callback continue_trace_from_span(String.t(), map, Keyword.t()) :: {:ok, term} | {:error, term}
@callback update_top_span(Keyword.t()) :: :ok | {:error, term}
@callback update_all_spans(Keyword.t()) :: :ok | {}

@callback distributed_context(Plug.Conn.t(), Keyword.t()) :: {:ok, term} | {:error, term}
@callback trace_id() :: term
@callback span_id() :: term
@callback now() :: term
@callback default_sender() :: module
end
Loading

0 comments on commit b1db34a

Please sign in to comment.