test/instrumentation/net-http_test.rb in instana-1.9.7 vs test/instrumentation/net-http_test.rb in instana-1.10.0.slimfast
- old
+ new
@@ -20,44 +20,37 @@
Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
response = http.request(req)
end
end
- assert_equal 2, ::Instana.processor.queue_count
+ spans = ::Instana.processor.queued_spans
+ assert_equal 3, spans.length
- traces = Instana.processor.queued_traces
- rs_trace = traces[0]
- http_trace = traces[1]
+ rs_span = find_first_span_by_name(spans, :rack)
+ first_span = find_first_span_by_name(spans, :'net-http-test')
+ second_span = find_first_span_by_name(spans, :'net-http')
- # Net::HTTP trace validation
- assert_equal 2, http_trace.spans.length
- spans = http_trace.spans.to_a
- first_span = spans[0]
- second_span = spans[1]
-
# Span name validation
assert_equal :sdk, first_span[:n]
assert_equal :'net-http', second_span[:n]
# first_span is the parent of second_span
- assert_equal first_span.id, second_span[:p]
+ assert_equal first_span[:s], second_span[:p]
# data keys/values
refute_nil second_span.key?(:data)
refute_nil second_span[:data].key?(:http)
assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
assert_equal "200", second_span[:data][:http][:status]
assert !second_span.key?(:stack)
- # Rack server trace validation
- assert_equal 1, rs_trace.spans.length
- rs_span = rs_trace.spans.to_a[0]
-
# Rack server trace should have the same trace ID
- assert_equal http_trace.id, rs_span[:t].to_i
+ assert_equal rs_span[:t], first_span[:t]
+ assert_equal first_span[:t], second_span[:t]
+
# Rack server trace should have net-http has parent span
- assert_equal second_span.id, rs_span[:p].to_i
+ assert_equal second_span[:s], rs_span[:p]
WebMock.disable_net_connect!
end
def test_basic_post_without_uri
@@ -68,44 +61,37 @@
Instana.tracer.start_or_continue_trace('net-http-test') do
http = Net::HTTP.new("127.0.0.1", 6511)
response = http.request(Net::HTTP::Post.new("/"))
end
- assert_equal 2, ::Instana.processor.queue_count
+ spans = ::Instana.processor.queued_spans
+ assert_equal 3, spans.length
- traces = Instana.processor.queued_traces
- rs_trace = traces[0]
- http_trace = traces[1]
+ rack_span = find_first_span_by_name(spans, :rack)
+ sdk_span = find_first_span_by_name(spans, :'net-http-test')
+ http_span = find_first_span_by_name(spans, :'net-http')
- # Net::HTTP trace validation
- assert_equal 2, http_trace.spans.length
- spans = http_trace.spans.to_a
- first_span = spans[0]
- second_span = spans[1]
-
# Span name validation
- assert_equal :sdk, first_span[:n]
- assert_equal :'net-http', second_span[:n]
+ assert_equal :sdk, sdk_span[:n]
+ assert_equal :'net-http', http_span[:n]
# first_span is the parent of second_span
- assert_equal first_span.id, second_span[:p]
+ assert_equal sdk_span[:s], http_span[:p]
# data keys/values
- refute_nil second_span.key?(:data)
- refute_nil second_span[:data].key?(:http)
- assert_equal "http://127.0.0.1:6511/", second_span[:data][:http][:url]
- assert_equal "200", second_span[:data][:http][:status]
- assert !second_span.key?(:stack)
+ refute_nil http_span.key?(:data)
+ refute_nil http_span[:data].key?(:http)
+ assert_equal "http://127.0.0.1:6511/", http_span[:data][:http][:url]
+ assert_equal "200", http_span[:data][:http][:status]
+ assert !http_span.key?(:stack)
- # Rack server trace validation
- assert_equal 1, rs_trace.spans.length
- rs_span = rs_trace.spans.to_a[0]
-
# Rack server trace should have the same trace ID
- assert_equal http_trace.id, rs_span[:t].to_i
+ assert_equal rack_span[:t], sdk_span[:t]
+ assert_equal sdk_span[:t], http_span[:t]
+
# Rack server trace should have net-http has parent span
- assert_equal second_span.id, rs_span[:p].to_i
+ assert_equal http_span[:s], rack_span[:p]
WebMock.disable_net_connect!
end
def test_request_with_dns_error
@@ -119,20 +105,19 @@
end
rescue Exception
nil
end
- traces = Instana.processor.queued_traces
- assert_equal 1, traces.length
- t = traces[0]
- assert_equal 1, t.spans.count
- assert t.has_error?
- spans = t.spans.to_a
- first_span = spans[0]
+ spans = ::Instana.processor.queued_spans
+ assert_equal 1, spans.length
- assert_equal :'net-http-error-test', first_span.name
- assert first_span.custom?
+ first_span = spans.first
+
+ assert_equal :sdk, first_span[:n]
+ assert_equal :'net-http-error-test', first_span[:data][:sdk][:name]
+ assert_equal true, first_span[:error]
+ assert_equal 1, first_span[:ec]
ts_key = first_span[:data][:sdk][:custom][:logs].keys.first
assert first_span[:data][:sdk][:custom][:logs].key?(ts_key)
assert first_span[:data][:sdk][:custom][:logs][ts_key].key?(:event)
assert first_span[:data][:sdk][:custom][:logs][ts_key].key?(:parameters)
@@ -147,23 +132,29 @@
Instana.tracer.start_or_continue_trace('net-http-error-test') do
http = Net::HTTP.new("127.0.0.1", 6511)
response = http.request(Net::HTTP::Get.new("/error"))
end
- traces = Instana.processor.queued_traces
- assert_equal 2, traces.length
+ spans = ::Instana.processor.queued_spans
+ assert_equal 3, spans.length
- request_trace = traces[1]
- assert_equal 2, request_trace.spans.length
- assert request_trace.has_error?
- http_span = request_trace.spans.to_a[1]
+ rack_span = find_first_span_by_name(spans, :rack)
+ sdk_span = find_first_span_by_name(spans, :'net-http-error-test')
+ http_span = find_first_span_by_name(spans, :'net-http')
+ assert_equal :sdk, sdk_span[:n]
+ assert_equal :'net-http-error-test', sdk_span[:data][:sdk][:name]
+ assert_equal nil, sdk_span[:error]
+ assert_equal nil, sdk_span[:ec]
+
refute_nil http_span.key?(:data)
refute_nil http_span[:data].key?(:http)
assert_equal "http://127.0.0.1:6511/error", http_span[:data][:http][:url]
assert_equal "500", http_span[:data][:http][:status]
- assert_equal :'net-http', http_span.name
+ assert_equal :'net-http', http_span[:n]
assert !http_span.key?(:stack)
+ assert_equal true, http_span[:error]
+ assert_equal 1, http_span[:ec]
WebMock.disable_net_connect!
end
end