From 384dd2f7cd542a1999c34361231e84ee8163627d Mon Sep 17 00:00:00 2001 From: Robert Laurin Date: Fri, 29 Aug 2025 10:15:54 -0500 Subject: [PATCH 1/2] feat: add record_exception option for in_span --- api/lib/opentelemetry/trace/tracer.rb | 4 ++-- sdk/test/opentelemetry/sdk/trace/tracer_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/lib/opentelemetry/trace/tracer.rb b/api/lib/opentelemetry/trace/tracer.rb index 2a5f311946..48866d1ab6 100644 --- a/api/lib/opentelemetry/trace/tracer.rb +++ b/api/lib/opentelemetry/trace/tracer.rb @@ -31,12 +31,12 @@ class Tracer # # @yield [span, context] yields the newly created span and a context containing the # span to the block. - def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil) + def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, record_exception: true) span = nil span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind) Trace.with_span(span) { |s, c| yield s, c } rescue Exception => e # rubocop:disable Lint/RescueException - span&.record_exception(e) + span&.record_exception(e) if record_exception span&.status = Status.error("Unhandled exception of type: #{e.class}") raise e ensure diff --git a/sdk/test/opentelemetry/sdk/trace/tracer_test.rb b/sdk/test/opentelemetry/sdk/trace/tracer_test.rb index 88ae0b5179..cbd11bc1f5 100644 --- a/sdk/test/opentelemetry/sdk/trace/tracer_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/tracer_test.rb @@ -330,6 +330,18 @@ _(span.status.description).must_equal('Unhandled exception of type: RuntimeError') end + it 'does not record an exception if record_exception is false' do + span = nil + _(proc do + tracer.in_span('op', record_exception: false) do |s| + span = s + raise 'this is fine' + end + end).must_raise(RuntimeError) + + _(span.events).must_be_nil + end + it 'yields a no-op span within an untraced block' do tracer.in_span('root') do span_id = OpenTelemetry::Trace.current_span.context.span_id From 4a4d8aad042b3476982c0923fe440b883499cd81 Mon Sep 17 00:00:00 2001 From: Robert Laurin Date: Fri, 29 Aug 2025 11:44:17 -0500 Subject: [PATCH 2/2] chore: fix stuck cla check