Skip to content

Commit be696db

Browse files
committed
Leverage new opentelemetry-api release
1 parent 55b9d89 commit be696db

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,29 @@ module Client
1616
def initialize(options = {})
1717
@connection_options = options # This is normally done by Trilogy#initialize
1818

19-
in_span(
19+
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
2627
end
2728

2829
def ping(...)
29-
in_span(
30+
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
3638
end
3739

3840
def query(sql)
39-
in_span(
41+
tracer.in_span(
4042
OpenTelemetry::Helpers::MySQL.database_span_name(
4143
sql,
4244
OpenTelemetry::Instrumentation::Trilogy.attributes[
@@ -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
@@ -64,19 +67,6 @@ def query(sql)
6467

6568
private
6669

67-
def in_span(name, attributes: nil, kind: nil)
68-
span = tracer.start_span(name, attributes: attributes, kind: kind)
69-
OpenTelemetry::Trace.with_span(span) { |s, c| yield s, c }
70-
rescue Exception => e # rubocop:disable Lint/RescueException
71-
if config[:record_exception]
72-
span&.record_exception(e)
73-
end
74-
span&.status = OpenTelemetry::Trace::Status.error("Exception of type: #{e.class}")
75-
raise e
76-
ensure
77-
span&.finish
78-
end
79-
8070
def client_attributes(sql = nil)
8171
attributes = {
8272
::OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM => 'mysql',

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.0'
2929
spec.add_dependency 'opentelemetry-helpers-mysql'
3030
spec.add_dependency 'opentelemetry-helpers-sql'
3131
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation'

0 commit comments

Comments
 (0)