Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2088497
feat: Trilogy semantic convention stability
hannahramadan Mar 18, 2026
4d62100
Rubocop
hannahramadan Mar 18, 2026
5298416
File format
hannahramadan Mar 18, 2026
3425850
Update tests
hannahramadan Mar 18, 2026
459e99b
Use actual error code and resonse in tests
hannahramadan Mar 18, 2026
f3da94c
Match old tests more directly
hannahramadan Mar 18, 2026
208eaa9
Rescue all errors
hannahramadan Mar 19, 2026
9dab994
Rubocop: Avoid rescuing all errors
hannahramadan Mar 19, 2026
c8e7951
Update span name
hannahramadan Mar 19, 2026
769b3e2
Remove peer.service
hannahramadan Mar 24, 2026
7180d60
fix syntax error
hannahramadan Mar 24, 2026
cfcfbe0
file formatter: Remove extra blank line
hannahramadan Mar 24, 2026
6171b08
Update instrumentation/trilogy/lib/opentelemetry/instrumentation/tril…
hannahramadan Apr 14, 2026
db68124
Update README
hannahramadan Apr 14, 2026
76d80f4
Add config table and doc comment
hannahramadan Apr 14, 2026
73149e5
Revert span names change in dup/stable
hannahramadan Apr 15, 2026
d47c59b
Update tests
hannahramadan Apr 15, 2026
035ec6a
linter cop
hannahramadan Apr 15, 2026
73f5778
Apply suggestions from code review
hannahramadan Apr 21, 2026
3c14c39
Update README.md
hannahramadan Apr 21, 2026
bb0dc48
Update instrumentation/trilogy/lib/opentelemetry/instrumentation/tril…
hannahramadan Apr 21, 2026
a237b0e
Merge branch 'main' into trilogy_semantic_stability
hannahramadan Apr 21, 2026
35d406f
rubocop and coverage
hannahramadan Apr 21, 2026
3517b4c
Merge branch 'main' into trilogy_semantic_stability
hannahramadan Apr 27, 2026
0d0eefc
Remove .simplecov overwrite
hannahramadan Apr 27, 2026
d04a3d2
Merge branch 'main' into trilogy_semantic_stability
hannahramadan May 14, 2026
5d29fbd
Update tests
hannahramadan May 14, 2026
f28c1cf
Add connect and ping test
hannahramadan May 15, 2026
f4bc921
Use real error type
hannahramadan May 15, 2026
aa21f15
Update instrumentation/trilogy/lib/opentelemetry/instrumentation/tril…
hannahramadan May 15, 2026
79c0eee
Merge branch 'main' into trilogy_semantic_stability
kaylareopelle May 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion helpers/mysql/lib/opentelemetry/helpers/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0module OpenTelemetry
# SPDX-License-Identifier: Apache-2.0
Comment thread
kaylareopelle marked this conversation as resolved.
Outdated

require 'opentelemetry-common'

module OpenTelemetry
Expand Down Expand Up @@ -66,6 +67,31 @@ def database_span_name(sql, operation, database_name, config)
end || 'mysql'
end

# Span naming following stable database semantic conventions.
# Per spec: {db.query.summary} -> {db.operation.name} {target} -> {target} -> {db.system.name}
# We don't have db.query.summary, so we use:
# {db.operation.name} {db.namespace} -> {db.namespace} -> mysql
#
# Note: Per spec, db.operation.name SHOULD NOT be extracted from db.query.text.
# The operation should only be used if explicitly provided by the application
# (e.g., via with_attributes).
#
# @param operation [String] The database operation (db.operation.name), if provided by the application.
# @param database_name [String] The name of the database (db.namespace).
# @return [String] The span name.
# @api private
def stable_database_span_name(operation, database_name)
Comment thread
robbkidd marked this conversation as resolved.
Outdated
if operation && database_name
"#{operation} #{database_name}"
elsif database_name
database_name
elsif operation
operation
else
'mysql'
end
end

# @api private
def extract_statement_type(sql)
return unless sql
Expand Down
45 changes: 45 additions & 0 deletions helpers/mysql/test/helpers/mysql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,51 @@
end
end

describe '.stable_database_span_name' do
let(:operation) { 'SELECT' }
let(:database_name) { 'mydb' }
let(:stable_span_name) { OpenTelemetry::Helpers::MySQL.stable_database_span_name(operation, database_name) }

describe 'when operation and database_name are present' do
it 'returns "{operation} {database_name}"' do
assert_equal('SELECT mydb', stable_span_name)
end
end

describe 'when only database_name is present' do
let(:operation) { nil }

it 'returns database_name' do
assert_equal('mydb', stable_span_name)
end
end

describe 'when only operation is present' do
let(:database_name) { nil }

it 'returns operation' do
assert_equal('SELECT', stable_span_name)
end
end

describe 'when both operation and database_name are nil' do
let(:operation) { nil }
let(:database_name) { nil }

it 'returns mysql as fallback' do
assert_equal('mysql', stable_span_name)
end
end

describe 'preserves operation case as provided' do
it 'does not normalize case' do
assert_equal('select mydb', OpenTelemetry::Helpers::MySQL.stable_database_span_name('select', 'mydb'))
assert_equal('SELECT mydb', OpenTelemetry::Helpers::MySQL.stable_database_span_name('SELECT', 'mydb'))
assert_equal('Select mydb', OpenTelemetry::Helpers::MySQL.stable_database_span_name('Select', 'mydb'))
end
end
end

describe '.db_operation_and_name' do
let(:operation) { 'operation' }
let(:database_name) { 'database_name' }
Expand Down
5 changes: 5 additions & 0 deletions instrumentation/trilogy/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
inherit_from: ../../.rubocop.yml

Metrics/ModuleLength:
Exclude:
- "lib/opentelemetry/instrumentation/trilogy/patches/stable/client.rb"
- "lib/opentelemetry/instrumentation/trilogy/patches/dup/client.rb"
19 changes: 14 additions & 5 deletions instrumentation/trilogy/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
#
# SPDX-License-Identifier: Apache-2.0

appraise 'trilogy-2.9' do
gem 'trilogy', '~> 2.9.0'
end
# To facilitate database semantic convention stability migration, we are using
# appraisal to test the different semantic convention modes along with different
# gem versions. For more information on the semantic convention modes, see:
# https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/

semconv_stability = %w[old stable dup]

semconv_stability.each do |mode|
appraise "trilogy-2-#{mode}" do
gem 'trilogy', '~> 2.9'
end

appraise 'trilogy-latest' do
gem 'trilogy'
appraise "trilogy-latest-#{mode}" do
gem 'trilogy'
end
end
16 changes: 16 additions & 0 deletions instrumentation/trilogy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ The `opentelemetry-instrumentation-trilogy` gem source is [on github][repo-githu

The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].

## Database semantic convention stability

In the OpenTelemetry ecosystem, database semantic conventions have now reached a stable state. However, the initial Trilogy instrumentation was introduced before this stability was achieved, which resulted in database attributes being based on an older version of the semantic conventions.

To facilitate the migration to stable semantic conventions, you can use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable. This variable allows you to opt-in to the new stable conventions, ensuring compatibility and future-proofing your instrumentation.

When setting the value for `OTEL_SEMCONV_STABILITY_OPT_IN`, you can specify which conventions you wish to adopt:

- `database` - Emits the stable database and networking conventions and ceases emitting the old conventions previously emitted by the instrumentation.
- `database/dup` - Emits both the old and stable database and networking conventions, enabling a phased rollout of the stable semantic conventions.
- Default behavior (in the absence of either value) is to continue emitting the old database and networking conventions the instrumentation previously emitted.

During the transition from old to stable conventions, Trilogy instrumentation code comes in three patch versions: `dup`, `old`, and `stable`. These versions are identical except for the attributes they send. Any changes to Trilogy instrumentation should consider all three patches.

For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/).

## License

The `opentelemetry-instrumentation-trilogy` gem is distributed under the Apache 2.0 license. See [LICENSE][license-github] for more information.
Expand Down
8 changes: 8 additions & 0 deletions instrumentation/trilogy/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ require 'rubocop/rake_task'

RuboCop::RakeTask.new

# Set OTEL_SEMCONV_STABILITY_OPT_IN based on appraisal name
gemfile = ENV.fetch('BUNDLE_GEMFILE', '')
if gemfile.include?('stable')
ENV['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'database'
elsif gemfile.include?('dup')
ENV['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'database/dup'
end

Rake::TestTask.new :test do |t|
t.libs << 'test'
t.libs << 'lib'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,47 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
option :propagator, default: 'none', validate: %w[none tracecontext vitess]
option :record_exception, default: true, validate: :boolean

attr_reader :propagator
attr_reader :propagator, :semconv

private

def require_dependencies
require_relative 'patches/client'
@semconv = determine_semconv

case @semconv
when :old
require_relative 'patches/old/client'
when :stable
require_relative 'patches/stable/client'
when :dup
require_relative 'patches/dup/client'
end
end

def patch_client
::Trilogy.prepend(Patches::Client)
case @semconv
when :old
::Trilogy.prepend(Patches::Old::Client)
when :stable
::Trilogy.prepend(Patches::Stable::Client)
when :dup
::Trilogy.prepend(Patches::Dup::Client)
end
end

def determine_semconv
opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', nil)
return :old if opt_in.nil?

opt_in_values = opt_in.split(',').map(&:strip)

if opt_in_values.include?('database/dup')
:dup
elsif opt_in_values.include?('database')
:stable
else
:old
end
end

def configure_propagator(config)
Expand Down

This file was deleted.

Loading
Loading