From a3249381392bbfdb7ce06a69bcc6840a0d955c7b Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Thu, 20 Jun 2024 15:06:15 -0500 Subject: [PATCH] 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 --- .../instrumentation/active_support/span_subscriber.rb | 4 ++-- .../active_support/span_subscriber_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb index 41efeb94a..8c9e879e8 100644 --- a/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb +++ b/instrumentation/active_support/lib/opentelemetry/instrumentation/active_support/span_subscriber.rb @@ -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) diff --git a/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb b/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb index 4b6b596d7..61afd26fa 100644 --- a/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb +++ b/instrumentation/active_support/test/opentelemetry/instrumentation/active_support/span_subscriber_test.rb @@ -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 @@ -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