BuildkiteTestCollector.Formatter (buildkite_test_collector v0.3.1)

Documentation for BuildkiteTestCollectorFormatter.

See instructions https://github.com/elixir-lang/elixir/blob/main/lib/ex_unit/lib/ex_unit/formatter.ex

Inspiration https://github.com/elixir-lang/elixir/blob/main/lib/ex_unit/lib/ex_unit/cli_formatter.ex

Summary

Types

A trace with a known duration.

A trace with known start and end time.

The ExUnit tags, (specifically module and test tags)

Unique identifier for tests.

Functions

Manually add a trace span to the currently running test.

Returns a specification to start this module under a supervisor.

Types

span_with_duration()

@type span_with_duration() :: %{
  :section => :http | :sql | :sleep | :annotation,
  :duration => BuildkiteTestCollector.Duration.t(),
  optional(:detail) => String.t()
}

A trace with a known duration.

span_with_start_and_end_at()

@type span_with_start_and_end_at() :: %{
  :section => :http | :sql | :sleep | :annotation,
  :start_at => BuildkiteTestCollector.Instant.t(),
  :end_at => BuildkiteTestCollector.Instant.t(),
  optional(:duration) => BuildkiteTestCollector.Duration.t(),
  optional(:detail) => String.t()
}

A trace with known start and end time.

tags()

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

The ExUnit tags, (specifically module and test tags)

test_id()

@type test_id() :: {module(), atom()}

Unique identifier for tests.

Contains the module that the test is defined in, and the name of the test as an atom.

Functions

add_span(tags, span)

@spec add_span(
  tags() | test_id(),
  span_with_start_and_end_at() | span_with_duration()
) :: :ok

Manually add a trace span to the currently running test.

You can add timing information about sql queries, http requests, etc to your test analytics.

It's probably better to use the helpers in the Tracing module.

Example

alias BuildkiteTestCollector.{Formatter, Instant}

test "example of instrumenting a query", tags do
  start_at = Instant.now()

  MyApp.Repo.all(my_complicated_query)

  end_at = Instant.now()

  Formatter.add_span(tags, %{
    start_at: start_at,
    end_at: end_at,
    section: :sql,
    detail: inspect(my_complicated_query)
  })
end

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.