ex_ray v0.1.4 ExRay View Source
ExRay defines an annotation construct that wraps regular functions and enable them to be traced using a simple affordance @trace to interact with an OpenTracing compliant collector.
OpenTracing defines the concept of spans that track the call stack and record timing information and various call artifacts that can be used for application runtime inspection. This is a really cool piece of technology that compliments your monitoring solution as you now have x-ray vision of your application at runtime once a monitoring metric gets off the chart.
However, in practice, your code gets quickly cluttered by your tracing efforts. ExRay alleviates the clutter by injecting cross-cutting tracing concern into your application code. By using @trace annotation, you can trap the essence of the calls without introducing tracing code mixed-in with your business logic.
ExRay leverages Otter Erlang OpenTracing lib from the fine folks of BlueHouse Technology.
To enable OpenTracing with ExRay
defmodule Traceme do
use ExRay, pre: :pre_fun, post: :post_fun
alias ExRay.Span
@trace kind: :cool_kid
def elvis(a, b), do: a + b
defp pre_fun(ctx) do
ctx.target
|> Span.open("123") # where 123 represent a unique callstack ID
|> :otter.tag(:kind, ctx.meta[:kind])
|> :otter.log("Calling Elvis!")
end
defp post_fun(_ctx, span, _res) do
span
|> :otter.log("Elvis has left the building!")
|> Span.close("123")
end
end
ExRay provisions an ExRay.Context
with function details and metadata
that comes from the annotation. You can leverage this information for
tracing in your pre and post span-hook functions.
Link to this section Summary
Functions
Defines a @trace annotation to enable regular function to be traced. Calling an annotated function f1 will ensure that a new span is created upon invocation and closed when the function exits. This macro will define a new function that will call the original function but decorated with pre and post tracing hooks. Tracing functions are generated at compile time
Generates a new tracing function with before and after hooks that will call the original function. Pre and Post hooks can be defined at the module level or overriden on a per function basis
Flags functions that have been annotated for further processing during the compilation phase
Link to this section Functions
Defines a @trace annotation to enable regular function to be traced. Calling an annotated function f1 will ensure that a new span is created upon invocation and closed when the function exits. This macro will define a new function that will call the original function but decorated with pre and post tracing hooks. Tracing functions are generated at compile time.
Generates a new tracing function with before and after hooks that will call the original function. Pre and Post hooks can be defined at the module level or overriden on a per function basis.
Flags functions that have been annotated for further processing during the compilation phase