Skip to content

Commit a324938

Browse files
fix: Include span kind in ActiveSupport Instrumentation helper (#1036)
* 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
1 parent 4bb7262 commit a324938

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def self.subscribe(
2020
pattern,
2121
notification_payload_transform = nil,
2222
disallowed_notification_payload_keys = [],
23-
kind = nil
23+
kind: nil
2424
)
2525
subscriber = OpenTelemetry::Instrumentation::ActiveSupport::SpanSubscriber.new(
2626
name: pattern,
2727
tracer: tracer,
2828
notification_payload_transform: notification_payload_transform,
2929
disallowed_notification_payload_keys: disallowed_notification_payload_keys,
30-
kind: nil
30+
kind: kind
3131
)
3232

3333
subscriber_object = ::ActiveSupport::Notifications.subscribe(pattern, subscriber)

instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def finish(name, id, payload)
223223
_(last_span).wont_be_nil
224224
_(last_span.name).must_equal('foo bar')
225225
_(last_span.attributes['extra']).must_equal('context')
226+
_(last_span.kind).must_equal(:internal)
226227
end
227228

228229
it 'finishes spans even when block subscribers blow up' do
@@ -260,5 +261,15 @@ def finish(name, id, payload)
260261
_(obj.class).must_equal(ActiveSupport::Notifications::Fanout::Subscribers::Evented)
261262
_(last_span).must_be_nil
262263
end
264+
265+
it 'supports setting the span kind' do
266+
OpenTelemetry::Instrumentation::ActiveSupport.subscribe(tracer, 'bar.foo', nil, [], kind: :client)
267+
ActiveSupport::Notifications.instrument('bar.foo', extra: 'context')
268+
269+
_(last_span).wont_be_nil
270+
_(last_span.name).must_equal('foo bar')
271+
_(last_span.attributes['extra']).must_equal('context')
272+
_(last_span.kind).must_equal(:client)
273+
end
263274
end
264275
end

0 commit comments

Comments
 (0)