View Source OpentelemetryXandra (opentelemetry_xandra v0.2.0)

A module to trace Xandra queries with OpenTelemetry.

This library uses Telemetry to create OpenTelemetry Spans for Xandra queries.

Usage

See attach/1.

Resources

This library follows the OpenTelemetry Semantic Conventions for naming, according to:

Summary

Types

The type for a function that parses a query and returns the operation, database, and table.

Thet type for a function that returns the statement to be used in the span.

Functions

Attaches a Telemetry handler that records OTel spans for Xandra queries.

Types

Link to this type

operation_parser_fun()

View Source
@type operation_parser_fun() ::
  (String.t() ->
     {operation :: String.t(), database :: String.t(), table :: String.t()})

The type for a function that parses a query and returns the operation, database, and table.

See attach/1 for more information.

@type statement_fun() :: (String.t() -> {:ok, String.t()} | :error)

Thet type for a function that returns the statement to be used in the span.

See attach/1 for more information.

Functions

@spec setup(keyword()) :: :ok | {:error, :already_exists}

Attaches a Telemetry handler that records OTel spans for Xandra queries.

Usage

Call this function in your application's Application.start/2 callback:

def start(_type, _args) do
  children = [
    # ...
  ]

  OpentelemetryXandra.setup()

  Supervisor.start_link(children, strategy: :one_for_one)
end

Options

  • :operation_parser - a function that takes a query (as a string) and should return a DB operation string that will be used in the span name. For example, for a query like INSERT INTO users (id, name) VALUES (1, 'Alice'), the operation parser could return INSERT. The default operation parser just takes the first word of the (whitespace-trimmed) query.

  • :statement - it can be a boolean, where true means that the db.statement span attribute gets filled with the query statement. If false, the attribute doesn't get set. It can also be a function of type statement_fun/0: if it returns {:ok, statement} then db.statement gets set to statement, while if it returns :error then db.statement doesn't get set.

Sensitive Information

Xandra does not sanitize the query that this library captures. Whatever string you pass to Xandra.execute/4 and other functions gets used for the :statement option.