BuildkiteTestCollector.Formatter (buildkite_test_collector v0.3.0)

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

Link to this section 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.

Link to this section Types

Link to this type

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.

Link to this type

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.

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

The ExUnit tags, (specifically module and test tags)

@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.

Link to this section Functions

Link to this function

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

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
Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.