-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from instana/issue_25
For custom traces, the gem should report using the SDK API for spans
- Loading branch information
Showing
7 changed files
with
247 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,9 @@ def key?(k) | |
def raw | ||
@data | ||
end | ||
|
||
def custom? | ||
@data[:n] == :sdk | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
require 'test_helper' | ||
|
||
class CustomTracingTest < Minitest::Test | ||
def test_custom_tracing | ||
::Instana.processor.clear! | ||
|
||
assert_equal false, ::Instana.tracer.tracing? | ||
# Start tracing | ||
::Instana.tracer.log_start_or_continue(:custom_trace, {:one => 1}) | ||
assert_equal true, ::Instana.tracer.tracing? | ||
::Instana.tracer.log_info({:info_logged => 1}) | ||
# End tracing | ||
::Instana.tracer.log_end(:rack, {:close_one => 1}) | ||
assert_equal false, ::Instana.tracer.tracing? | ||
|
||
traces = ::Instana.processor.queued_traces | ||
assert_equal 1, traces.count | ||
t = traces.first | ||
assert_equal 1, t.spans.size | ||
assert t.valid? | ||
|
||
first_span = t.spans.first | ||
assert_equal :sdk, first_span[:n] | ||
|
||
assert first_span.key?(:data) | ||
assert first_span[:data].key?(:sdk) | ||
assert first_span[:data][:sdk].key?(:custom) | ||
assert_equal :custom_trace, first_span[:data][:sdk][:name] | ||
assert_equal 1, first_span[:data][:sdk][:custom][:one] | ||
assert_equal :ruby, first_span[:ta] | ||
|
||
assert first_span.key?(:f) | ||
assert first_span[:f].key?(:e) | ||
assert first_span[:f].key?(:h) | ||
assert_equal ::Instana.agent.agent_uuid, first_span[:f][:h] | ||
end | ||
|
||
def test_custom_tracing_with_args | ||
::Instana.processor.clear! | ||
|
||
assert_equal false, ::Instana.tracer.tracing? | ||
|
||
# Start tracing | ||
::Instana.tracer.log_start_or_continue(:rack, :on_trace_start => 1) | ||
assert_equal true, ::Instana.tracer.tracing? | ||
|
||
kvs = {} | ||
kvs[:on_entry_kv] = 1 | ||
kvs[:arguments] = [[1,2,3], "test_arg", :ok] | ||
kvs[:return] = true | ||
|
||
::Instana.tracer.log_entry(:custom_span, kvs) | ||
::Instana.tracer.log_info({:on_info_kv => 1}) | ||
::Instana.tracer.log_exit(:custom_span, :on_exit_kv => 1) | ||
|
||
# End tracing | ||
::Instana.tracer.log_end(:rack, {:on_trace_end => 1}) | ||
assert_equal false, ::Instana.tracer.tracing? | ||
|
||
traces = ::Instana.processor.queued_traces | ||
assert_equal 1, traces.count | ||
t = traces.first | ||
assert_equal 2, t.spans.size | ||
assert t.valid? | ||
|
||
first_span, second_span = t.spans.to_a | ||
|
||
assert_equal :rack, first_span[:n] | ||
assert first_span.key?(:data) | ||
assert first_span[:data].key?(:on_trace_start) | ||
assert_equal 1, first_span[:data][:on_trace_start] | ||
assert first_span[:data].key?(:on_trace_end) | ||
assert_equal 1, first_span[:data][:on_trace_end] | ||
|
||
assert_equal :sdk, second_span[:n] | ||
assert second_span.key?(:data) | ||
assert second_span[:data].key?(:sdk) | ||
assert second_span[:data][:sdk].key?(:custom) | ||
assert :custom_span, second_span[:data][:sdk][:name] | ||
assert :unknown, second_span[:data][:sdk][:type] | ||
assert [[1, 2, 3], "test_arg", :ok], second_span[:data][:sdk][:arguments] | ||
assert true, second_span[:data][:sdk][:return] | ||
assert_equal 1, second_span[:data][:sdk][:custom][:on_entry_kv] | ||
assert_equal 1, second_span[:data][:sdk][:custom][:on_info_kv] | ||
assert_equal 1, second_span[:data][:sdk][:custom][:on_exit_kv] | ||
end | ||
|
||
def test_custom_tracing_with_error | ||
::Instana.processor.clear! | ||
|
||
assert_equal false, ::Instana.tracer.tracing? | ||
|
||
# Start tracing | ||
::Instana.tracer.log_start_or_continue(:rack, :on_trace_start => 1) | ||
assert_equal true, ::Instana.tracer.tracing? | ||
|
||
begin | ||
kvs = {} | ||
kvs[:on_entry_kv] = 1 | ||
kvs[:arguments] = [[1,2,3], "test_arg", :ok] | ||
kvs[:return] = true | ||
|
||
::Instana.tracer.log_entry(:custom_span, kvs) | ||
raise "custom tracing error. This is only a test" | ||
::Instana.tracer.log_info({:on_info_kv => 1}) | ||
rescue => e | ||
::Instana.tracer.log_error(e) | ||
ensure | ||
::Instana.tracer.log_exit(:custom_span, :on_exit_kv => 1) | ||
end | ||
::Instana.tracer.log_end(:rack, {:on_trace_end => 1}) | ||
assert_equal false, ::Instana.tracer.tracing? | ||
|
||
traces = ::Instana.processor.queued_traces | ||
assert_equal 1, traces.count | ||
t = traces.first | ||
assert_equal 2, t.spans.size | ||
assert t.valid? | ||
|
||
first_span, second_span = t.spans.to_a | ||
|
||
assert_equal :rack, first_span[:n] | ||
assert first_span.key?(:data) | ||
assert first_span[:data].key?(:on_trace_start) | ||
assert_equal 1, first_span[:data][:on_trace_start] | ||
assert first_span[:data].key?(:on_trace_end) | ||
assert_equal 1, first_span[:data][:on_trace_end] | ||
|
||
assert_equal :sdk, second_span[:n] | ||
assert second_span.key?(:data) | ||
assert second_span[:data].key?(:sdk) | ||
assert second_span[:data][:sdk].key?(:custom) | ||
assert :custom_span, second_span[:data][:sdk][:name] | ||
assert :unknown, second_span[:data][:sdk][:type] | ||
assert [[1, 2, 3], "test_arg", :ok], second_span[:data][:sdk][:arguments] | ||
assert true, second_span[:data][:sdk][:return] | ||
assert_equal 1, second_span[:data][:sdk][:custom][:on_entry_kv] | ||
assert !second_span[:data][:sdk][:custom].key?(:on_info_kv) | ||
assert_equal 1, second_span[:data][:sdk][:custom][:on_exit_kv] | ||
|
||
# Check the error | ||
assert_equal true, second_span[:error] | ||
assert_equal 1, second_span[:ec] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.