Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add extra coverage for root exit span scenarios #397

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/instrumentation/graphql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!

Expand Down
18 changes: 18 additions & 0 deletions test/instrumentation/rails_action_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading