Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion instrumentation/trilogy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ This gem requires Trilogy 2.11 or higher and will not work with a future Trilogy
| `obfuscation_limit` | `2000` | Maximum length of the obfuscated SQL statement. Statements exceeding this limit are truncated. |
| `peer_service` | `nil` | Deprecated with no replacement. Sets the `peer.service` attribute on spans (old semantic conventions only). |
| `propagator` | `'none'` | Propagator for injecting trace context into SQL comments. `'none'` disables propagation, `'tracecontext'` uses W3C Trace Context, `'vitess'` uses Vitess-style propagation (requires `opentelemetry-propagator-vitess` gem). |
| `record_exception` | `true` | Records exceptions as span events when an error occurs. |
| `record_exception` | `true` when using old semconv, otherwise `false` | Records exceptions as span events when an error occurs. |
| `span_name` | `:statement_type` | Controls span naming (old semantic conventions only). `:statement_type` uses the SQL operation (e.g., `SELECT`), `:db_name` uses the database name, `:db_operation_and_name` combines both. |

## Semantic Conventions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Trilogy
#
# ### `:record_exception`
#
# Records exceptions as span events when an error occurs. Default is `true`.
# Records exceptions as span events when an error occurs. Default is `true` for old semconv, otherwise `false`.
#
# ### `:span_name`
#
Expand Down Expand Up @@ -91,7 +91,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name]
option :obfuscation_limit, default: 2000, validate: :integer
option :propagator, default: 'none', validate: %w[none tracecontext vitess]
option :record_exception, default: true, validate: :boolean
option :record_exception, default: nil, validate: :boolean

attr_reader :propagator, :semconv

Expand All @@ -100,6 +100,8 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
def require_dependencies
@semconv = determine_semconv

@config[:record_exception] = (@semconv == :old) if @config[:record_exception].nil?

case @semconv
when :old
require_relative 'patches/old/client'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
end

describe 'when queries fail' do
let(:config) { { record_exception: true } }
it 'sets span status to error' do
expect do
client.query('SELECT INVALID')
Expand Down Expand Up @@ -392,6 +393,18 @@
_(exporter.finished_spans.last.attributes['error.type']).must_equal 'Trilogy::ConnectionClosed'
end

describe 'when record_exception is default' do
let(:config) { {} }

it 'does not record exception when record_exception is default' do
expect do
client.query('SELECT INVALID')
end.must_raise Trilogy::Error

_(span.events).must_be_nil
end
end

describe 'when record_exception is false' do
let(:config) { { record_exception: false } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@
end

describe 'when queries fail' do
let(:config) { { record_exception: true } }

it 'sets span status to error' do
expect do
client.query('SELECT INVALID')
Expand Down Expand Up @@ -291,6 +293,17 @@
_(exporter.finished_spans.last.attributes['error.type']).must_equal 'Trilogy::ConnectionClosed'
end

describe 'when record_exception is default' do
let(:config) { {} }
it 'does not record exception when record_exception is default' do
expect do
client.query('SELECT INVALID')
end.must_raise Trilogy::Error

_(span.events).must_be_nil
end
end

describe 'when record_exception is false' do
let(:config) { { record_exception: false } }

Expand Down
Loading