Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Fix up tests and harnesses per log_kv
Browse files Browse the repository at this point in the history
  • Loading branch information
bhs committed Sep 11, 2016
1 parent 3ea474a commit b44fc79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
9 changes: 9 additions & 0 deletions opentracing/harness/api_check.py
Expand Up @@ -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}). \
Expand Down
8 changes: 5 additions & 3 deletions opentracing/span.py
Expand Up @@ -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):
Expand Down
23 changes: 14 additions & 9 deletions tests/test_noop_span.py
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit b44fc79

Please sign in to comment.