From d3b2314244f4d01671aafbc856110d9e98621181 Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Thu, 20 Jun 2024 14:54:30 -0500 Subject: [PATCH 1/3] fix: Include span kind in AS helper This change fixes a bug where the kind parameter was not passed along to the subscriber object --- .../instrumentation/active_support/span_subscriber.rb | 4 ++-- 1 file changed, 2 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 41efeb94a0..8c9e879e88 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) From 114273f72e93158475dba6b08aad0b697a2e49ea Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Thu, 20 Jun 2024 14:57:27 -0500 Subject: [PATCH 2/3] squash: add test coverage --- .../active_support/span_subscriber_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 4b6b596d72..847e7bc0be 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 @@ -260,5 +260,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 From 7194a79b13f5503f1ac7324eb4aa4946e5311ddc Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Thu, 20 Jun 2024 14:57:58 -0500 Subject: [PATCH 3/3] squash: updated example --- .../instrumentation/active_support/span_subscriber_test.rb | 1 + 1 file changed, 1 insertion(+) 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 847e7bc0be..61afd26fad 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