From 90b2c853f6f09b8d9e32c0f4dde45bbfbfd7698d Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Sun, 1 Sep 2024 19:29:36 -0300 Subject: [PATCH 1/7] feature: adds on_ending method as an optional callback for span processors Signed-off-by: Gustavo Pantuza --- sdk/lib/opentelemetry/sdk/trace/span_processor.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb index f1874f6504..c5c7c7e173 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb @@ -23,6 +23,20 @@ class SpanProcessor # started span. def on_start(span, parent_context); end + # Called when a {Span} is ending, after the end timestamp has been set + # but before span becomes immutable. This allows for updating the span + # by setting attributes or adding links and events. + # + # This method is called synchronously and should not blocks the current + # thread nor throw exceptions. + # + # This method is optional on the Span Processor interface. It will only + # get called if it exists within the processor. + # + # @param [Span] span the {Span} that just is ending (still mutable). + # @return [void] + def on_ending(span); end + # Called when a {Span} is ended, if the {Span#recording?} # returns true. # From 93e6d9fa08c4f2946fb3af52f3c39c6bacb88ee7 Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Sun, 1 Sep 2024 19:31:47 -0300 Subject: [PATCH 2/7] feature: calls every span processor that has on_ending implemented right after setting the end timestamp Signed-off-by: Gustavo Pantuza --- sdk/lib/opentelemetry/sdk/trace/span.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index 274ac4c24d..c67346b65e 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span.rb @@ -271,6 +271,9 @@ def finish(end_timestamp: nil) return self end @end_timestamp = relative_timestamp(end_timestamp) + @span_processors.each do |processor| + processor.on_ending(self) if processor.respond_to?(:on_ending) + end @attributes = validated_attributes(@attributes).freeze @events.freeze @links.freeze From 0f1cf1640bfffc9d63129b88d1b92c953f875859 Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Sun, 1 Sep 2024 19:32:40 -0300 Subject: [PATCH 3/7] test: adds tests for the new on_ending method from span processors Signed-off-by: Gustavo Pantuza --- sdk/test/opentelemetry/sdk/trace/span_processor_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb b/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb index 262ad53b92..635fd59589 100644 --- a/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb @@ -15,6 +15,10 @@ processor.on_start(span, context) end + it 'implements #on_ending' do + processor.on_ending(span) + end + it 'implements #on_finish' do processor.on_finish(span) end From 2c28b768daa0ffe6c9a24a5b5f37f811454aa2f8 Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Mon, 2 Sep 2024 11:30:56 -0300 Subject: [PATCH 4/7] docs: Informs the on_ending callback is an experimental features from official spec Signed-off-by: Gustavo Pantuza --- sdk/lib/opentelemetry/sdk/trace/span_processor.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb index c5c7c7e173..089c9b3b25 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb @@ -23,6 +23,8 @@ class SpanProcessor # started span. def on_start(span, parent_context); end + # The on_ending is an experimental feature and may have breaking changes. + # # Called when a {Span} is ending, after the end timestamp has been set # but before span becomes immutable. This allows for updating the span # by setting attributes or adding links and events. From 9d9c944712eeaffc731d96564902e319de569ad1 Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Wed, 4 Sep 2024 11:05:43 -0300 Subject: [PATCH 5/7] Update sdk/lib/opentelemetry/sdk/trace/span_processor.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- sdk/lib/opentelemetry/sdk/trace/span_processor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb index 089c9b3b25..57d62a1828 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb @@ -23,7 +23,7 @@ class SpanProcessor # started span. def on_start(span, parent_context); end - # The on_ending is an experimental feature and may have breaking changes. + # The on_ending method is an experimental feature and may have breaking changes. # # Called when a {Span} is ending, after the end timestamp has been set # but before span becomes immutable. This allows for updating the span From 173e57abadb6e5a7ac222babfd534a62c587a56a Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Wed, 4 Sep 2024 11:05:57 -0300 Subject: [PATCH 6/7] Update sdk/lib/opentelemetry/sdk/trace/span_processor.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- sdk/lib/opentelemetry/sdk/trace/span_processor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb index 57d62a1828..d143299a9c 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb @@ -29,7 +29,7 @@ def on_start(span, parent_context); end # but before span becomes immutable. This allows for updating the span # by setting attributes or adding links and events. # - # This method is called synchronously and should not blocks the current + # This method is called synchronously and should not block the current # thread nor throw exceptions. # # This method is optional on the Span Processor interface. It will only From fc085c3d5d36e8c31201fa2d4e8d10c1c256f55e Mon Sep 17 00:00:00 2001 From: Gustavo Pantuza Date: Tue, 17 Sep 2024 21:00:36 -0300 Subject: [PATCH 7/7] refactor: switch method name from on_ending to on_finish to comply with project name strategy Signed-off-by: Gustavo Pantuza --- sdk/lib/opentelemetry/sdk/trace/span.rb | 2 +- sdk/lib/opentelemetry/sdk/trace/span_processor.rb | 6 ++++-- sdk/test/opentelemetry/sdk/trace/span_processor_test.rb | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index c67346b65e..c1f32657f8 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span.rb @@ -272,7 +272,7 @@ def finish(end_timestamp: nil) end @end_timestamp = relative_timestamp(end_timestamp) @span_processors.each do |processor| - processor.on_ending(self) if processor.respond_to?(:on_ending) + processor.on_finishing(self) if processor.respond_to?(:on_finishing) end @attributes = validated_attributes(@attributes).freeze @events.freeze diff --git a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb index d143299a9c..2a60c3ba53 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span_processor.rb @@ -23,7 +23,9 @@ class SpanProcessor # started span. def on_start(span, parent_context); end - # The on_ending method is an experimental feature and may have breaking changes. + # The on_finishing method is an experimental feature and may have breaking changes. + # The OpenTelemetry specification defines it as "On Ending". As `end` is a reserved + # keyword in Ruby, we are using `on_finishing` instead. # # Called when a {Span} is ending, after the end timestamp has been set # but before span becomes immutable. This allows for updating the span @@ -37,7 +39,7 @@ def on_start(span, parent_context); end # # @param [Span] span the {Span} that just is ending (still mutable). # @return [void] - def on_ending(span); end + def on_finishing(span); end # Called when a {Span} is ended, if the {Span#recording?} # returns true. diff --git a/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb b/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb index 635fd59589..2bfc1532ba 100644 --- a/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/span_processor_test.rb @@ -15,8 +15,8 @@ processor.on_start(span, context) end - it 'implements #on_ending' do - processor.on_ending(span) + it 'implements #on_finishing' do + processor.on_finishing(span) end it 'implements #on_finish' do