Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds on_ending callback to allow processors to mutate spans before End operation #1713

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/lib/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions sdk/lib/opentelemetry/sdk/trace/span_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ class SpanProcessor
# started span.
def on_start(span, parent_context); end

# The on_ending is an experimental feature and may have breaking changes.
pantuza marked this conversation as resolved.
Show resolved Hide resolved
#
# 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
pantuza marked this conversation as resolved.
Show resolved Hide resolved
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an experimental feature and may have breaking changes. How about specifying that here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I will update it.


# Called when a {Span} is ended, if the {Span#recording?}
# returns true.
#
Expand Down
4 changes: 4 additions & 0 deletions sdk/test/opentelemetry/sdk/trace/span_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading