Skip to content

Commit b807e59

Browse files
kirsrobertlaurin
andauthored
feat: Trilogy: introduce record_exception setting (#1653)
feat: trilogy record_exception config Co-authored-by: Robert <[email protected]>
1 parent 0481298 commit b807e59

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/instrumentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2828
option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name]
2929
option :obfuscation_limit, default: 2000, validate: :integer
3030
option :propagator, default: nil, validate: :string
31+
option :record_exception, default: true, validate: :boolean
3132

3233
attr_reader :propagator
3334

instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def initialize(options = {})
1919
tracer.in_span(
2020
'connect',
2121
attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
22-
kind: :client
22+
kind: :client,
23+
record_exception: config[:record_exception]
2324
) do
2425
super
2526
end
@@ -29,7 +30,8 @@ def ping(...)
2930
tracer.in_span(
3031
'ping',
3132
attributes: client_attributes.merge!(OpenTelemetry::Instrumentation::Trilogy.attributes),
32-
kind: :client
33+
kind: :client,
34+
record_exception: config[:record_exception]
3335
) do
3436
super
3537
end
@@ -48,7 +50,8 @@ def query(sql)
4850
attributes: client_attributes(sql).merge!(
4951
OpenTelemetry::Instrumentation::Trilogy.attributes
5052
),
51-
kind: :client
53+
kind: :client,
54+
record_exception: config[:record_exception]
5255
) do |_span, context|
5356
if propagator && sql.frozen?
5457
sql = +sql

instrumentation/trilogy/opentelemetry-instrumentation-trilogy.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
2525
spec.require_paths = ['lib']
2626
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
2727

28-
spec.add_dependency 'opentelemetry-api', '~> 1.0'
28+
spec.add_dependency 'opentelemetry-api', '~> 1.7'
2929
spec.add_dependency 'opentelemetry-helpers-mysql'
3030
spec.add_dependency 'opentelemetry-helpers-sql'
3131
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation'

instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@
277277
_(span.events.first.attributes['exception.message']).wont_be_nil
278278
_(span.events.first.attributes['exception.stacktrace']).wont_be_nil
279279
end
280+
281+
describe 'when record_exception is false' do
282+
let(:config) { { record_exception: false } }
283+
284+
it 'does not record exception when record_exception is false' do
285+
expect do
286+
client.query('SELECT INVALID')
287+
end.must_raise Trilogy::Error
288+
289+
_(span.events).must_be_nil
290+
end
291+
end
280292
end
281293

282294
describe 'when db_statement is set to include' do

0 commit comments

Comments
 (0)