@@ -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' ,
0 commit comments