opencensus_plug v0.3.0 Opencensus.Plug.Trace behaviour
Template method for creating Plug
to trace your Plug
requests.
Usage
- Create your own
Plug
module:
defmodule MyApp.TracingPlug do
use Opencensus.Plug.Trace
end
- Add it to your pipeline, ex. for Phoenix:
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
plug MyApp.TracingPlug
end
Configuration
This module creates 2 callback modules, which allows you to configure your span and also provides a way to add custom attributes assigned to span.
c:span_name/1
- defaults to request pathc:span_status/1
- defaults to mapping of reponse code to OpenCensus span value, see:opencensus.http_status_to_trace_status/1
.
And also you can use attributes
argument in use
which must be either list
of attributes which are names of 1-argument functions in current module that
must return string value of the attribute, or map/keyword list of one of:
atom
- which is name of the called function{module, function}
- which will callapply(module, function, [conn])
{module, function, args}
- which will prependconn
to the given arguments and callapply(module, function, [conn | args])
Example:
defmodule MyAppWeb.TraceWithCustomAttribute do
use Opencensus.Plug.Trace, attributes: [:method]
def method(conn), do: conn.method
end
Link to this section Summary
Callbacks
Return name for current span. By defaut returns "plug"
Return tuple containing span status and message. By default return value status assigned by default mapping and empty message
Link to this section Callbacks
span_name(arg0, options)
span_name(Plug.Conn.t(), options :: term()) :: String.t()
span_name(Plug.Conn.t(), options :: term()) :: String.t()
Return name for current span. By defaut returns "plug"
span_status(arg0, options)
span_status(Plug.Conn.t(), options :: term()) :: {integer(), String.t()}
span_status(Plug.Conn.t(), options :: term()) :: {integer(), String.t()}
Return tuple containing span status and message. By default return value status assigned by default mapping and empty message.