Skip to content

Commit

Permalink
time blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
clutchski committed Aug 24, 2016
1 parent 07c9736 commit 02449fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def initialize(tracer, name, options={})
@end_time = nil
end


def trace()
if block_given?
yield(self)
end
self.finish()
return self
end

# Mark the span finished at the current time and submit it.
def finish()
self.finish_at(Time.now.utc)
Expand Down
5 changes: 5 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
def get_test_tracer()
return Datadog::Tracer.new
end


class Writer

end
12 changes: 12 additions & 0 deletions test/test_span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ def test_span_with_parent()
assert_equal(span.name, 'my.op')
end

def test_span_block()
start = Time.now.utc
span = Datadog::Span.new(nil, 'my.op').trace do |s|
assert_equal(s.name, 'my.op')
assert_equal(s.end_time, nil)
end

assert span.end_time != nil
assert span.end_time < Time.now.utc
assert span.end_time > start
end

end

0 comments on commit 02449fe

Please sign in to comment.