BuildkiteTestCollector.Tracing (buildkite_test_collector v0.2.0)

Helpers for doing simple tracing in your tests.

Link to this section Summary

Types

Valid trace types.

ExUnit test tags (specifically the module and test tags).

Functions

Measure the execution time of a function and add a trace to the test analytics.

Link to this section Types

@type section() :: :http | :sql | :sleep | :annotation

Valid trace types.

See the documentation for more information.

@type tags() :: %{:module => module(), :test => atom(), optional(atom()) => any()}

ExUnit test tags (specifically the module and test tags).

These are used to uniquely identify the test being executed.

Link to this section Functions

Link to this function

measure(tags, section, detail \\ nil, callable)

@spec measure(tags(), section(), nil | String.t(), (() -> result)) :: result
when result: any()

Measure the execution time of a function and add a trace to the test analytics.

example

Example

alias BuildkiteTestCollector.Tracing

test "it can measure an HTTP request", tags do
  assert {:ok, _} =
           Tracing.measure(tags, :http, "The koan of Github", fn ->
             Tesla.get("https://api.github.com/zen", headers: [{"user-agent", "Tesla"}])
           end)
end


test "it can measure a SQL query", tags do
  import Ecto.Query

  query =
    from(tt in "time_travellers",
      where: tt.born >= 1968 and tt.born <= 1970,
      select: tt.name,
      order_by: tt.name
    )

  assert {:ok, ["Marty McFly", "Theodore Logan, III", "William Stanley Preston, Esq."]} =
           Tracing.measure(tags, :sql, inspect(query), fn ->
             MyApp.all(query)
           end)
end