Skip to content

Commit

Permalink
Fix to not flush local component span when a server span or a consume…
Browse files Browse the repository at this point in the history
…r span is in the stack (#179)

* Fix to not flush local component span when a server span or a consumer span is in the stack

* simplified
  • Loading branch information
ykitamura-mdsol authored Oct 12, 2020
1 parent 9552f9c commit 2faafd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.47.2
* Fix to not flush local component span when a server span or a consumer span is in the stack.

# 0.47.1
* Fix to set `SERVER` span kind at the beginning to avoid being flushed before closing.

Expand Down
2 changes: 1 addition & 1 deletion lib/zipkin-tracer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ZipkinTracer
VERSION = '0.47.1'
VERSION = '0.47.2'
end
6 changes: 2 additions & 4 deletions lib/zipkin-tracer/zipkin_sender_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def start_span(trace_id, name, timestamp = Time.now)
end

def skip_flush?(span)
return true if span.kind == Trace::Span::Kind::CLIENT && span.has_parent_span?
return false if span.kind == Trace::Span::Kind::SERVER || span.kind == Trace::Span::Kind::CONSUMER

if span.kind == Trace::Span::Kind::PRODUCER
return true if spans.any? { |s| s.kind == Trace::Span::Kind::SERVER || s.kind == Trace::Span::Kind::CONSUMER }
end
spans.any? { |s| s.kind == Trace::Span::Kind::SERVER || s.kind == Trace::Span::Kind::CONSUMER }
end

def flush!
Expand Down
16 changes: 5 additions & 11 deletions spec/lib/zipkin_sender_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
include_examples 'flushes span', Trace::Span::Kind::CLIENT
include_examples 'flushes span', Trace::Span::Kind::PRODUCER
include_examples 'flushes span', Trace::Span::Kind::CONSUMER
include_examples 'flushes span', nil

it 'allows you pass an explicit timestamp' do
span #touch it so it happens before we freeze time again
Expand All @@ -109,15 +110,6 @@
end
end

describe '#end_span with parent span' do
let(:span) { tracer.start_span(trace_id_with_parent, rpc_name) }

include_examples 'flushes span', Trace::Span::Kind::SERVER
include_examples 'does not flush span', Trace::Span::Kind::CLIENT
include_examples 'flushes span', Trace::Span::Kind::PRODUCER
include_examples 'flushes span', Trace::Span::Kind::CONSUMER
end

describe '#end_span with another server span' do
before do
span = tracer.start_span(trace_id, rpc_name)
Expand All @@ -127,9 +119,10 @@
let(:span) { tracer.start_span(trace_id, rpc_name) }

include_examples 'flushes span', Trace::Span::Kind::SERVER
include_examples 'flushes span', Trace::Span::Kind::CLIENT
include_examples 'does not flush span', Trace::Span::Kind::CLIENT
include_examples 'does not flush span', Trace::Span::Kind::PRODUCER
include_examples 'flushes span', Trace::Span::Kind::CONSUMER
include_examples 'does not flush span', nil
end

describe '#end_span with another consumer span' do
Expand All @@ -141,9 +134,10 @@
let(:span) { tracer.start_span(trace_id, rpc_name) }

include_examples 'flushes span', Trace::Span::Kind::SERVER
include_examples 'flushes span', Trace::Span::Kind::CLIENT
include_examples 'does not flush span', Trace::Span::Kind::CLIENT
include_examples 'does not flush span', Trace::Span::Kind::PRODUCER
include_examples 'flushes span', Trace::Span::Kind::CONSUMER
include_examples 'does not flush span', nil
end

describe '#with_new_span' do
Expand Down

0 comments on commit 2faafd0

Please sign in to comment.