Permalink
Browse files

Fix up tests and harnesses per log_kv

  • Loading branch information...
1 parent 3ea474a commit b44fc79fe0190fe85f7d2cda79cf8cc93167275f @bensigelman bensigelman committed Sep 11, 2016
Showing with 28 additions and 12 deletions.
  1. +9 −0 opentracing/harness/api_check.py
  2. +5 −3 opentracing/span.py
  3. +14 −9 tests/test_noop_span.py
@@ -112,6 +112,15 @@ def test_span_tags_with_chaining(self):
def test_span_logs(self):
span = self.tracer().start_span(operation_name='Fry')
+
+ # Newer API
+ span.log_kv(
+ {'frozen.year': 1999, 'frozen.place': 'Cryogenics Labs'})
+ span.log_kv(
+ {'defrosted.year': 2999, 'defrosted.place': 'Cryogenics Labs'},
+ time.time())
+
+ # Older API
span.\
log_event('frozen', {'year': 1999, 'place': 'Cryogenics Labs'}). \
log_event('defrosted', {'year': 2999}). \
View
@@ -201,9 +201,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
as a tag to the span.
"""
if exc_type:
- self.log_event('python.exception', {'type': exc_type,
- 'val': exc_val,
- 'tb': exc_tb})
+ self.log_kv({
+ 'python.exception.type': exc_type,
+ 'python.exception.val': exc_val,
+ 'python.exception.tb': exc_tb,
+ })
self.finish()
def log_event(self, event, payload=None):
@@ -20,6 +20,7 @@
from __future__ import absolute_import
import mock
+import time
from opentracing import child_of
from opentracing import Format
from opentracing import Tracer
@@ -31,24 +32,28 @@ def test_span():
parent = tracer.start_span('parent')
child = tracer.start_span('test', references=child_of(parent.context))
assert parent == child
+ child.log_kv({'event': 'cache_hit', 'size.bytes': 42})
+ child.log_kv({'event': 'cache_miss'}, time.time())
child.log_event('cache_hit', ['arg1', 'arg2'])
with mock.patch.object(parent, 'finish') as finish:
with mock.patch.object(parent, 'log_event') as log_event:
- try:
- with parent:
- raise ValueError()
- except ValueError:
- pass
- assert finish.call_count == 1
- assert log_event.call_count == 1
+ with mock.patch.object(parent, 'log_kv') as log_kv:
+ try:
+ with parent:
+ raise ValueError()
+ except ValueError:
+ pass
+ assert finish.call_count == 1
+ assert log_event.call_count == 0
+ assert log_kv.call_count == 1
with mock.patch.object(parent, 'finish') as finish:
- with mock.patch.object(parent, 'log_event') as log_event:
+ with mock.patch.object(parent, 'log_event') as log_kv:
with parent:
pass
assert finish.call_count == 1
- assert log_event.call_count == 0
+ assert log_kv.call_count == 0
parent.set_tag('x', 'y').set_tag('z', 1) # test chaining
parent.set_tag(tags.PEER_SERVICE, 'test-service')

0 comments on commit b44fc79

Please sign in to comment.