OpenTelemetry Trilogy Instrumentation

The OpenTelemetry Trilogy Ruby gem provides instrumentation for Trilogy and was COPY+PASTE+MODIFIED from the [OpenTelemetry MySQL][opentelemetry-mysql].

Some key differences in this instrumentation are:

  • Trilogy does not expose MySql#query_options, therefore there is limited support for database semantic conventions.
  • SQL Obfuscation is enabled by default to mitigate restricted data leaks.

How do I get started?

Install the gem using:

gem install opentelemetry-instrumentation-trilogy

Or, if you use bundler, include opentelemetry-instrumentation-trilogy in your Gemfile.

Usage

To use the instrumentation, call use with the name of the instrumentation:

OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::Trilogy', {
    # The obfuscation of SQL in the db.statement attribute is disabled by default.
    # To enable, set db_statement to :obfuscate.
    db_statement: :obfuscate,
  }
end

Alternatively, you can also call use_all to install all the available instrumentation.

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

The trilogy instrumentation allows the user to supply additional attributes via the with_attributes method. This makes it possible to supply additional attributes on trilogy spans. Attributes supplied in with_attributes supersede those automatically generated within trilogy's automatic instrumentation. If you supply a db.statement attribute in with_attributes, this library's :db_statement configuration will not be applied.

require 'opentelemetry-instrumentation-trilogy'

client = Trilogy.new(:host => 'localhost', :username => 'root')
OpenTelemetry::Instrumentation::Trilogy.with_attributes('pizzatoppings' => 'mushrooms') do
  client.query('SELECT 1')
end

Semantic Conventions

This instrumentation generally uses Database semantic conventions.

Attribute Name Type Notes
db.instance.id String The name of the DB host executing the query e.g. SELECT @@hostname
db.name String The name of the database from connection_options
db.statement String SQL statement being executed
db.user String The username from connection_options
db.system String mysql
net.peer.name String The name of the remote host from connection_options

How can I get involved?

The opentelemetry-instrumentation-trilogy gem source is on github, along with related gems including opentelemetry-api and opentelemetry-sdk.

The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in GitHub Discussions or attending our weekly meeting. See the meeting calendar for dates and times. For more information on this and other language SIGs, see the OpenTelemetry community page.

License

The opentelemetry-instrumentation-trilogy gem is distributed under the Apache 2.0 license. See LICENSE for more information.