Skip to content

Commit

Permalink
fix: Include span kind in ActiveSupport Instrumentation helper (#1036)
Browse files Browse the repository at this point in the history
* fix: Include span kind in AS helper

This change fixes a bug where the kind parameter was not passed along to the subscriber object

* squash: add test coverage

* squash: updated example
  • Loading branch information
arielvalentin authored Jun 20, 2024
1 parent 4bb7262 commit a324938
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def self.subscribe(
pattern,
notification_payload_transform = nil,
disallowed_notification_payload_keys = [],
kind = nil
kind: nil
)
subscriber = OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber.new(
name: pattern,
tracer: tracer,
notification_payload_transform: notification_payload_transform,
disallowed_notification_payload_keys: disallowed_notification_payload_keys,
kind: nil
kind: kind
)

subscriber_object = ::ActiveSupport::Notifications.subscribe(pattern, subscriber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def finish(name, id, payload)
_(last_span).wont_be_nil
_(last_span.name).must_equal('foo bar')
_(last_span.attributes['extra']).must_equal('context')
_(last_span.kind).must_equal(:internal)
end

it 'finishes spans even when block subscribers blow up' do
Expand Down Expand Up @@ -260,5 +261,15 @@ def finish(name, id, payload)
_(obj.class).must_equal(ActiveSupport::Notifications::Fanout::Subscribers::Evented)
_(last_span).must_be_nil
end

it 'supports setting the span kind' do
OpenTelemetry::Instrumentation::ActiveSupport.subscribe(tracer, 'bar.foo', nil, [], kind: :client)
ActiveSupport::Notifications.instrument('bar.foo', extra: 'context')

_(last_span).wont_be_nil
_(last_span.name).must_equal('foo bar')
_(last_span.attributes['extra']).must_equal('context')
_(last_span.kind).must_equal(:client)
end
end
end

0 comments on commit a324938

Please sign in to comment.