otterx v0.1.0 Otterx

Otterx is open tracing library for Elixir. It provides a wrapper around the otters Erlang library.

All functions allow to pass nil or :undefined in the parts refering to other traces, parents, or the span to update. This will rendere the function a noop and allows for a fast bypassing of tracing without much additional load

Summary

Functions

Ends a span and prepares queues it to be dispatched to the trace server. This is also where filtering happens, it’s the most expensive part of tracing

Retrives the Trace ID and the Span ID from a span. This can be used for start_child/2

Adds a log to a span

Adds a log to a span with a given service

Starts a new span with a given name and a generated trace id

Starts a new span with a given Trace ID. If the trace_id is :undefined or nil the span is not started and nil is returned in it’s pace

Starts a new span with a given Trace ID and Parent ID. If the trace_id is :undefined or nil the span is not started and nil returned in it’s pace. The parent_id can either be a number, nil or :undefined

Starts a new span as a child of a existing span, using the parents Trace ID or a {trace_id, parent_id} tuple and setting the childs parent to the parents Span ID

Adds a tag to a span, possibly overwriting the existing value

Adds a tag to a span with a given service, possibly overwriting the existing value

Functions

finish(span)

Ends a span and prepares queues it to be dispatched to the trace server. This is also where filtering happens, it’s the most expensive part of tracing.

## Examples

iex> Otterx.finish(nil)
:ok
iex> Otterx.finish(:undefined)
:ok
iex> span = Otterx.start("span")
iex> Otterx.finish(span)
:ok
ids(span)

Retrives the Trace ID and the Span ID from a span. This can be used for start_child/2

## Examples

iex> Otterx.ids(nil)
nil
iex> Otterx.ids(:undefined)
nil
iex> span = Otterx.start("span")
iex> {trace_id, span_id} = Otterx.ids(span)
iex> is_integer(trace_id) and is_integer(span_id)
true
log(span, log)

Adds a log to a span.

## Examples

iex> Otterx.log(nil, "my log")
nil
iex> Otterx.log(:undefined, "your log")
nil
iex> span = Otterx.start("span")
iex> span = Otterx.log(span, "our log")
iex> is_tuple(span)
true
log(span, log, service)

Adds a log to a span with a given service.

## Examples

iex> Otterx.log(nil, "my log", "service")
nil
iex> Otterx.log(:undefined, "your log", "service")
nil
iex> span = Otterx.start("span")
iex> span = Otterx.log(span, "our log", "service")
iex> is_tuple(span)
true
start(name)

Starts a new span with a given name and a generated trace id.

Examples

iex> span = Otterx.start("aspan")
iex> is_tuple(span)
true
start(name, trace_id)

Starts a new span with a given Trace ID. If the trace_id is :undefined or nil the span is not started and nil is returned in it’s pace.

Examples

iex> Otterx.start("aspan", nil)
nil
iex> Otterx.start("aspan", :undefined)
nil
iex> span = Otterx.start("aspan", 42)
iex> is_tuple(span)
true
start(name, trace_id, parent_id)

Starts a new span with a given Trace ID and Parent ID. If the trace_id is :undefined or nil the span is not started and nil returned in it’s pace. The parent_id can either be a number, nil or :undefined

Examples

iex> Otterx.start("aspan", nil, nil)
nil
iex> Otterx.start("aspan", :undefined, nil)
nil
iex> span = Otterx.start("aspan", 42, nil)
iex> is_tuple(span)
true
iex> span = Otterx.start("aspan", 42, 100)
iex> is_tuple(span)
true
start_child(name, parent)

Starts a new span as a child of a existing span, using the parents Trace ID or a {trace_id, parent_id} tuple and setting the childs parent to the parents Span ID.

If the parent or trace_id is :undefined or nil the span is not started and nil is returned in it’s pace.

## Examples

iex> Otterx.start_child("child", nil)
nil
iex> Otterx.start_child("child", :undefined)
nil
iex> parent = Otterx.start("parent")
iex> span = Otterx.start_child("child", parent)
iex> is_tuple(span)
true
iex> trace_ids = {42, nil}
iex> span = Otterx.start_child("child", trace_ids)
iex> is_tuple(span)
true
iex> trace_ids = {42, 100}
iex> span = Otterx.start_child("child", trace_ids)
iex> is_tuple(span)
true
tag(span, key, value)

Adds a tag to a span, possibly overwriting the existing value.

## Examples

iex> Otterx.tag(nil, "key", "value")
nil
iex> Otterx.tag(:undefined, "key", "value")
nil
iex> span = Otterx.start("span")
iex> span = Otterx.tag(span, "key", "value")
iex> is_tuple(span)
true
tag(span, key, value, service)

Adds a tag to a span with a given service, possibly overwriting the existing value.

## Examples

iex> Otterx.tag(nil, "key", "value", "service")
nil
iex> Otterx.tag(:undefined, "key", "value", "service")
nil
iex> span = Otterx.start("span")
iex> span = Otterx.tag(span, "key", "value", "service")
iex> is_tuple(span)
true