diff --git a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb index 8f15dd89d..f62ddda42 100644 --- a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb +++ b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb @@ -49,7 +49,7 @@ def query(sql) OpenTelemetry::Instrumentation::Trilogy.attributes ), kind: :client - ) do |_span, context| + ) do |span, context| if propagator && sql.frozen? sql = +sql propagator.inject(sql, context: context) @@ -58,7 +58,12 @@ def query(sql) propagator.inject(sql, context: context) end - super + result = super + + span.set_attribute('db.response.returned_rows', result.count) + span.set_attribute('db.response.affected_rows', result.affected_rows) unless result.affected_rows.nil? + + result end end diff --git a/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb b/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb index 350ee5f83..3e9c150f1 100644 --- a/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb +++ b/instrumentation/trilogy/test/opentelemetry/instrumentation/trilogy/instrumentation_test.rb @@ -164,6 +164,12 @@ _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_SYSTEM]).must_equal 'mysql' _(span.attributes[OpenTelemetry::SemanticConventions::Trace::DB_STATEMENT]).must_equal 'DESELECT ?' end + + it 'includes row count' do + client.query('SELECT 1') + + _(span.attributes['db.response.returned_rows']).must_equal(1) + end end describe 'when connecting' do