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

Add Tracer#start_active_scope and deprecate Tracer#start_active_span #36

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 15 additions & 8 deletions lib/opentracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ def active_span
scope.span if scope
end

# Returns a newly started and activated Scope.
# Returns a newly started and activated Scope
#
# @deprecated Use {#start_active_scope} instead
def start_active_span(*args, &block)
start_active_scope(*args, &block)
end

# Returns a newly started and activated Scope
#
# If the Tracer's ScopeManager#active is not nil, no explicit references
# are provided, and `ignore_active_scope` is false, then an inferred
Expand All @@ -46,13 +53,13 @@ def active_span
# yield the newly-started Scope. If `finish_on_close` is true then the
# Span will be finished automatically after the block is executed.
# @return [Scope] The newly-started and activated Scope
def start_active_span(operation_name,
child_of: nil,
references: nil,
start_time: Time.now,
tags: nil,
ignore_active_scope: false,
finish_on_close: true)
def start_active_scope(operation_name,
child_of: nil,
references: nil,
start_time: Time.now,
tags: nil,
ignore_active_scope: false,
finish_on_close: true)
Scope::NOOP_INSTANCE.tap do |scope|
yield scope if block_given?
end
Expand Down
20 changes: 20 additions & 0 deletions test/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ def test_start_active_span_accepts_block
end
end

def test_start_active_scope
scope = OpenTracing::Tracer.new.start_active_scope('operation_name')
assert_equal OpenTracing::Scope::NOOP_INSTANCE, scope
assert_equal OpenTracing::Span::NOOP_INSTANCE, scope.span
end

def test_start_active_scope_allows_references
references = [OpenTracing::Reference.child_of(OpenTracing::Span::NOOP_INSTANCE)]
scope = OpenTracing::Tracer.new.start_active_scope('operation_name', references: references)
assert_equal OpenTracing::Scope::NOOP_INSTANCE, scope
assert_equal OpenTracing::Span::NOOP_INSTANCE, scope.span
end

def test_start_active_scope_accepts_block
OpenTracing::Tracer.new.start_active_scope('operation_name') do |scope|
assert_equal OpenTracing::Scope::NOOP_INSTANCE, scope
assert_equal OpenTracing::Span::NOOP_INSTANCE, scope.span
end
end

def test_inject_text_map
context = OpenTracing::SpanContext::NOOP_INSTANCE
carrier = {}
Expand Down