Version:

Modules reference / tracing / Module opentracing
Modules reference / tracing / Module opentracing

Module opentracing

Module opentracing

OpenTracing API module entrypoint

Functions

set_global_tracer (tracer)

Set global tracer

Parameters:

get_global_tracer ()

Get global tracer

Returns:

(table) tracer

start_span (name, opts)

Start root span

Parameters:

  • name: (string)
  • opts: table specifying modifications to make to the newly created span. The following parameters are supported: trace_id , references , a list of referenced spans; start_time , the time to mark when the span begins (in microseconds since epoch); tags , a table of tags to add to the created span.
    • trace_id: (optional string)
    • child_of: (optional table)
    • references: (optional table)
    • tags: (optional table)

Returns:

(table) span

start_span_from_context (context, name)

Start new child span from context

Parameters:

Returns:

(table) span

trace_with_context (name, ctx, fun, …)

Trace function with context by global tracer This function starts span from global tracer and finishes it after execution

Parameters:

  • name: (string) span name
  • ctx: (table) context
  • fun: (function) wrapped function
  • …: (vararg) function’s arguments

Returns:

(vararg) result

Or

(nil) nil (string) err error message

Usage:

-- Process HTTP request
local ctx = opentracing.extractors.http(req.headers)
local result, err = opentracing.trace_with_context('process_data', ctx, process_data, req.body)
-- Wrap functions. In example we create root span that generates two child spans
local span = opentracing.start_span()
local result, err = opentracing.trace_with_context('format_string', span:context(), format, str)
if not result ~= nil then
    print('Error: ', err)
end
opentracing.trace_with_context('print_string', span:context(), print, result)
span:finish()

trace (name, fun, …)

Trace function by global tracer This function starts span from global tracer and finishes it after execution

Parameters:

  • name: (string) span name
  • fun: (function) wrapped function
  • …: (vararg) function’s arguments

Returns:

(vararg) result

Or

(nil) nil (string) err error message

Usage:

local result, err = opentracing.trace_with_context('process_data', process_data, req.body)