Skip to content

opencensus-beam/opencensus_plug

Repository files navigation

Opencensus.Plug

CircleCI CodeCov Inline docs Hex version badge

Plug integration for OpenCensus. It provides tracer and metrics integration.

Installation

The package can be installed by adding opencensus_plug to your list of dependencies in mix.exs:

def deps do
  [
    {:opencensus_plug, "~> 0.3"}
  ]
end

The docs can be found at https://hexdocs.pm/opencensus_plug.

Usage

Tracing

Create tracing module:

defmodule MyApp.TracePlug do
  use Opencensus.Plug.Trace
end

And then add it on the beginning of your pipeline (the sooner the better):

plug MyApp.TracePlug

This will extract parent trace from the headers accordingly to Tracing Context proposal and it will create new span. By default span name will match request path, you can configure that by defining span_name/2 method that will receive Plug.Conn.t as a first argument and plug options as a second.

Metrics

Create metrics module:

defmodule MyApp.MetricsPlug do
  use Opencensus.Plug.Metrics
end

And then add it on the beginning of your pipeline (the sooner the better):

plug MyApp.MetricsPlug

You also need to define metrics that will be measured, fortunately there is helper method for you, just call MyApp.MetricsPlug.setup_metrics() before running pipeline.

Available metrics:

  • "plug/requests/duration" - request duration in microseconds
  • "plug/requests/count" - requests count

WARNING! This defines only metrics, not views. You need to define views on your own to be able to see them in the exporters.

License

See LICENSE file.