From efe91b25784b007c956dca0099fbe7c7f1e90d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Tue, 25 Jun 2024 12:00:00 +0000 Subject: [PATCH] test: Add extra coverage for root exit span scenarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- test/instrumentation/graphql_test.rb | 41 +++++++++++++++++++ .../rails_action_mailer_test.rb | 18 ++++++++ 2 files changed, 59 insertions(+) diff --git a/test/instrumentation/graphql_test.rb b/test/instrumentation/graphql_test.rb index ba1e6333..7404359f 100644 --- a/test/instrumentation/graphql_test.rb +++ b/test/instrumentation/graphql_test.rb @@ -83,6 +83,10 @@ class Schema < GraphQL::Schema mutation MutationType end + def teardown + ::Instana.config[:allow_exit_as_root] = false + end + def test_it_works assert defined?(GraphQL) end @@ -127,6 +131,43 @@ def test_query assert_equal expected_data, query_span[:data][:graphql] end + def test_query_as_root_exit_span + clear_all! + + query = "query FirstTwoTaskSamples { + tasks(after: \"\", first: 2) { + nodes { + action + } + } + }" + + expected_data = { + :operationName => "FirstTwoTaskSamples", + :operationType => "query", + :arguments => { "tasks" => ["after", "first"] }, + :fields => { "tasks" => ["nodes"], "nodes" => ["action"] } + } + expected_results = { + "data" => { + "tasks" => { + "nodes" => [{"action" => "Sample 00"}, {"action" => "Sample 01"}] + } + } + } + + ::Instana.config[:allow_exit_as_root] = true + results = Schema.execute(query) + ::Instana.config[:allow_exit_as_root] = false + queued_spans = Instana.processor.queued_spans + assert_equal 1, queued_spans.length + query_span = queued_spans[0] + + assert_equal expected_results, results.to_h + assert_equal :'graphql.server', query_span[:n] + assert_equal expected_data, query_span[:data][:graphql] + end + def test_query_with_fragment clear_all! diff --git a/test/instrumentation/rails_action_mailer_test.rb b/test/instrumentation/rails_action_mailer_test.rb index 032c385b..731623f6 100644 --- a/test/instrumentation/rails_action_mailer_test.rb +++ b/test/instrumentation/rails_action_mailer_test.rb @@ -34,6 +34,10 @@ def setup clear_all! end + def teardown + ::Instana.config[:allow_exit_as_root] = false + end + def test_mailer Instana.tracer.start_or_continue_trace(:test) do TestMailer.sample_email.deliver_now @@ -45,4 +49,18 @@ def test_mailer assert_equal 'RailsActionMailerTest::TestMailer', mail_span[:data][:actionmailer][:class] assert_equal 'sample_email', mail_span[:data][:actionmailer][:method] end + + def test_mailer_as_root_exit_span + ::Instana.config[:allow_exit_as_root] = true + TestMailer.sample_email.deliver_now + ::Instana.config[:allow_exit_as_root] = false + + queued_spans = Instana.processor.queued_spans + assert_equal 1, queued_spans.length + mail_span = queued_spans[0] + + assert_equal :"mail.actionmailer", mail_span[:n] + assert_equal 'RailsActionMailerTest::TestMailer', mail_span[:data][:actionmailer][:class] + assert_equal 'sample_email', mail_span[:data][:actionmailer][:method] + end end