Skip to content
4 changes: 2 additions & 2 deletions lib/instana/instrumentation/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module GRPCCientInstrumentation
current_span.record_exception(e)
raise
ensure
current_span.finish
current_span&.finish
end
end
end
Expand Down Expand Up @@ -83,7 +83,7 @@ module GRPCServerInstrumentation
current_span.record_exception(e)
raise
ensure
current_span.finish if ::Instana.tracer.tracing?
current_span&.finish
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def with_span(span)
#
# @return [Span]
def non_recording_span(span_context)
Span.new(span_context: span_context)
OpenTelemetry::Trace::Span.new(span_context: span_context)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instana/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def clear!
# with_parent=current context, start_timestamp=current time.
#
def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: ::Instana::Util.now_in_ms, kind: nil) # rubocop:disable Metrics/ParameterLists
return if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]
return Instana::Trace.non_recording_span(with_parent) if !::Instana.agent.ready? || !::Instana.config[:tracing][:enabled]

with_parent ||= OpenTelemetry::Context.current
name ||= 'empty'
Expand Down
26 changes: 26 additions & 0 deletions test/instrumentation/aws_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,30 @@ def test_lambda_with_500_status
refute_nil lambda_span[:stack]
assert_equal 30, lambda_span[:stack].length # default limit is 30 in span.add_stack
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
error = nil

::Instana.agent.stub(:ready?, false) do
dynamo = Aws::DynamoDB::Client.new(
region: "local",
access_key_id: "placeholder",
secret_access_key: "placeholder",
endpoint: "http://localhost:8000"
)

assert_silent do
dynamo.get_item(
table_name: 'sample_table',
key: { s: 'sample_item' }
)
rescue StandardError => e
error = e
end
end

# Should not raise instrumentation errors, only the expected AWS error
assert error.is_a?(Aws::DynamoDB::Errors::ServiceError)
assert_empty ::Instana.processor.queued_spans
end
end
20 changes: 20 additions & 0 deletions test/instrumentation/bunny_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'test_helper'

Warning[:deprecated] = false if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('3.4')

class BunnyTest < Minitest::Test # rubocop:disable Metrics/ClassLength
def setup
skip unless defined?(::Bunny)
Expand Down Expand Up @@ -792,4 +794,22 @@ def test_pop_error_handling_with_logging

assert error_raised, "Exception should be raised and logged in pop"
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
skip unless defined?(::Bunny)
clear_all!

error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
@exchange.publish('test message', routing_key: @queue.name)
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
18 changes: 18 additions & 0 deletions test/instrumentation/dalli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

require 'test_helper'

Warning[:deprecated] = false if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('4.0')

class DalliTest < Minitest::Test
def setup
@memcached_host = ENV['MEMCACHED_HOST'] || '127.0.0.1:11211'
Expand Down Expand Up @@ -322,4 +324,20 @@ def test_get_error_logging
assert_equal 'instana_test', second_span[:data][:memcache][:namespace]
assert second_span[:data][:memcache].key?(:error)
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
@dc.set(:instana, :test_value)
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
25 changes: 25 additions & 0 deletions test/instrumentation/excon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,29 @@ def test_basic_get_no_tracing
connection = Excon.new(url)
connection.get(:path => '/?basic_get')
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

# A slight hack but webmock chokes with pipelined requests.
# Delete their excon middleware
Excon.defaults[:middlewares].delete ::WebMock::HttpLibAdapters::ExconAdapter
Excon.defaults[:middlewares].delete ::Excon::Middleware::Mock

url = "http://127.0.0.1:6511"

::Instana.agent.stub(:ready?, false) do
connection = Excon.new(url)

assert_silent do
connection.get(:path => '/?basic_get')
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
26 changes: 26 additions & 0 deletions test/instrumentation/graphql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,30 @@ def test_mutation
assert_equal :'graphql.server', query_span[:n]
assert_equal expected_data, query_span[:data][:graphql]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

query = "query FirstTwoTaskSamples {
tasks(after: \"\", first: 2) {
nodes {
action
}
}
}"

::Instana.agent.stub(:ready?, false) do
assert_silent do

Schema.execute(query)
rescue StandardError => e
error = e

end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
21 changes: 21 additions & 0 deletions test/instrumentation/grpc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,25 @@ def test_bidi_streamer_failure
assert_equal server_span[:p], client_span[:s]
assert_equal client_span[:p], sdk_span[:s]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil
::Instana.agent.stub(:ready?, false) do
assert_silent do
begin
client_stub.ping(
PingPongService::PingRequest.new(message: 'Hello World')
)
rescue StandardError => e
error = e
end
end
end

sleep 0.2

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
17 changes: 17 additions & 0 deletions test/instrumentation/mongo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,21 @@ def test_mongo_as_root_exit_span
assert_equal insert_data[:peer], {hostname: "127.0.0.1", port: 27017}
assert insert_data[:json].include?("insert")
end

def test_mongo_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
error = nil

::Instana.agent.stub(:ready?, false) do
client = Mongo::Client.new('mongodb://127.0.0.1:27017/instana')

assert_silent do
client[:people].delete_many({ name: /$S*/ })
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
19 changes: 19 additions & 0 deletions test/instrumentation/net_http_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,23 @@ def test_request_with_5xx_response

WebMock.disable_net_connect!
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil
WebMock.allow_net_connect!

::Instana.agent.stub(:ready?, false) do
assert_silent do
Net::HTTP.get(URI('http://127.0.0.1:6511/'))
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans

WebMock.disable_net_connect!
end
end
17 changes: 17 additions & 0 deletions test/instrumentation/rack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,21 @@ def test_five_zero_x_trace
assert_equal :rack, first_span[:n]
assert_equal 1, first_span[:ec]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
get '/mrlobster'
rescue StandardError => e
error = e
end
end

assert_nil error
assert last_response.ok?
assert_empty ::Instana.processor.queued_spans
end
end
22 changes: 22 additions & 0 deletions test/instrumentation/rails_action_cable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ def mock_connection
connection.define_singleton_method(:transmit) { |*_args, **_kwargs| true }
connection
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
skip unless defined?(::ActionCable::Connection::Base)
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
connection = mock_connection
channel_klass = Class.new(ActionCable::Channel::Base)

assert_silent do
channel_klass
.new(connection, :test)
.send(:transmit, 'Sample message', via: nil)
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
17 changes: 17 additions & 0 deletions test/instrumentation/rails_action_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,21 @@ def test_log
assert_equal "Warn", log_span[:level]
assert_equal "This is a test warning", log_span[:message]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
get '/base/world'
rescue StandardError => e
error = e
end
end

assert_nil error
assert last_response.ok?
assert_empty ::Instana.processor.queued_spans
end
end
16 changes: 16 additions & 0 deletions test/instrumentation/rails_action_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ def test_mailer_as_root_exit_span
assert_equal 'RailsActionMailerTest::TestMailer', mail_span[:data][:actionmailer][:class]
assert_equal 'sample_email', mail_span[:data][:actionmailer][:method]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
TestMailer.sample_email.deliver_now
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
17 changes: 17 additions & 0 deletions test/instrumentation/rails_action_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,21 @@ def test_render_collection
assert_equal :collection, span[:data][:render][:type]
assert_equal 'blocks/block', span[:data][:render][:name]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
clear_all!
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
get '/render_view'
rescue StandardError => e
error = e
end
end

assert_nil error
assert last_response.ok?
assert_empty ::Instana.processor.queued_spans
end
end
15 changes: 15 additions & 0 deletions test/instrumentation/rails_active_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ def test_enqueue_perform
assert_equal client_span[:t], server_span[:t]
assert_equal client_span[:s], server_span[:p]
end

def test_no_error_is_raised_and_no_spans_are_created_when_agent_is_not_ready
error = nil

::Instana.agent.stub(:ready?, false) do
assert_silent do
SampleJob.perform_now("test_agent_not_ready")
rescue StandardError => e
error = e
end
end

assert_nil error
assert_empty ::Instana.processor.queued_spans
end
end
Loading
Loading