View Source OpenTelemetryXandra (opentelemetry_xandra v0.1.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
@type query_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.
Thet type for a function that returns the statement to be used in the span.
See attach/1
for more information.
Functions
@spec attach(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.attach()
Supervisor.start_link(children, strategy: :one_for_one)
end
Options
:query_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 likeINSERT INTO users (id, name) VALUES (1, 'Alice')
, the operation parser could returnINSERT
. The default operation parser just takes the first word of the (whitespace-trimmed) query.:statement
- it can be a boolean, wheretrue
means that thedb.statement
span attribute gets filled with the query statement. Iffalse
, the attribute doesn't get set. It can also be a function of typestatement_fun/0
: if it returns{:ok, statement}
thendb.statement
gets set tostatement
, while if it returns:error
thendb.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.