Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-prokopchenkov committed Jul 26, 2017
1 parent bd6a025 commit bdef103
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ your Zipkin collector is running at localhost:9411.
import requests

def http_transport(encoded_span):
# The collector expects a thrift-encoded list of spans.
requests.post(
'http://localhost:9411/api/v1/spans',
data=encoded_span,
Expand Down
11 changes: 3 additions & 8 deletions py_zipkin/logging_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
binary_annotations=None,
add_logging_annotation=False,
client_context=False,
max_span_portion_size=None,
max_span_batch_size=None,
):
self.zipkin_attrs = zipkin_attrs
self.thrift_endpoint = thrift_endpoint
Expand All @@ -60,7 +60,7 @@ def __init__(
self.sa_binary_annotations = []
self.add_logging_annotation = add_logging_annotation
self.client_context = client_context
self.max_span_portion_size = max_span_portion_size
self.max_span_batch_size = max_span_batch_size

def start(self):
"""Actions to be taken before request is handled.
Expand Down Expand Up @@ -91,7 +91,7 @@ def log_spans(self):
return

span_sender = ZipkinBatchSender(self.transport_handler,
self.max_span_portion_size)
self.max_span_batch_size)
with span_sender:
end_timestamp = time.time()
# Collect additional annotations from the logging handler
Expand Down Expand Up @@ -339,9 +339,6 @@ def add_span(
timestamp_s,
duration_s,
):
if not self.transport_handler:
return

thrift_span = create_span(
span_id,
parent_span_id,
Expand All @@ -352,9 +349,7 @@ def add_span(
timestamp_s,
duration_s,
)
self._add_span_to_queue(thrift_span)

def _add_span_to_queue(self, thrift_span):
self.queue.append(thrift_span)
if len(self.queue) >= self.max_portion_size:
self.flush()
Expand Down
12 changes: 6 additions & 6 deletions py_zipkin/zipkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
span_name='span',
zipkin_attrs=None,
transport_handler=None,
max_span_portion_size=None,
max_span_batch_size=None,
annotations=None,
binary_annotations=None,
port=0,
Expand All @@ -127,9 +127,9 @@ def __init__(
:param transport_handler: Callback function that takes a message parameter
and handles logging it
:type transport_handler: function
:param max_span_portion_size: Spans in a trace are sent in batches,
max_span_portion_size defines max size of one batch
:type max_span_portion_size: int
:param max_span_batch_size: Spans in a trace are sent in batches,
max_span_batch_size defines max size of one batch
:type max_span_batch_size: int
:param annotations: Optional dict of str -> timestamp annotations
:type annotations: dict of str -> int
:param binary_annotations: Optional dict of str -> str span attrs
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(
self.span_name = span_name
self.zipkin_attrs = zipkin_attrs
self.transport_handler = transport_handler
self.max_span_portion_size = max_span_portion_size
self.max_span_batch_size = max_span_batch_size
self.annotations = annotations or {}
self.binary_annotations = binary_annotations or {}
self.port = port
Expand Down Expand Up @@ -299,7 +299,7 @@ def start(self):
binary_annotations=self.binary_annotations,
add_logging_annotation=self.add_logging_annotation,
client_context=client_context,
max_span_portion_size=self.max_span_portion_size,
max_span_batch_size=self.max_span_batch_size,
)
self.logging_context.start()
self.logging_configured = True
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/zipkin_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from thriftpy.protocol.binary import TBinaryProtocol, read_list_begin
from thriftpy.protocol.binary import TBinaryProtocol
from thriftpy.protocol.binary import read_list_begin
from thriftpy.transport import TMemoryBuffer

from py_zipkin import zipkin
Expand Down
4 changes: 2 additions & 2 deletions tests/logging_helper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def test_batch_sender_defensive_about_transport_handler(
):
"""Make sure log_span doesn't try to call the transport handler if it's
None."""
sender = logging_helper.ZipkinBatchSender(None)
sender = logging_helper.ZipkinBatchSender(transport_handler=None)
with sender:
sender.add_span(
span_id='0000000000000002',
Expand All @@ -404,8 +404,8 @@ def test_batch_sender_defensive_about_transport_handler(
timestamp_s=None,
duration_s=None,
)
assert create_sp.call_count == 1
assert thrift_obj.call_count == 0
assert create_sp.call_count == 0


def test_get_local_span_timestamp_and_duration_client():
Expand Down
8 changes: 4 additions & 4 deletions tests/zipkin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_zipkin_span_for_new_trace(
binary_annotations={},
add_logging_annotation=False,
client_context=False,
max_span_portion_size=None,
max_span_batch_size=None,
)
pop_zipkin_attrs_mock.assert_called_once_with()

Expand Down Expand Up @@ -111,7 +111,7 @@ def test_zipkin_span_passed_sampled_attrs(
binary_annotations={},
add_logging_annotation=False,
client_context=False,
max_span_portion_size=None,
max_span_batch_size=None,
)
pop_zipkin_attrs_mock.assert_called_once_with()

Expand Down Expand Up @@ -491,7 +491,7 @@ def test_func(a, b):
binary_annotations={},
add_logging_annotation=False,
client_context=False,
max_span_portion_size=None,
max_span_batch_size=None,
)
pop_zipkin_attrs_mock.assert_called_once_with()

Expand Down Expand Up @@ -547,7 +547,7 @@ def test_func(a, b):
binary_annotations={},
add_logging_annotation=False,
client_context=True,
max_span_portion_size=None,
max_span_batch_size=None,
)
pop_zipkin_attrs_mock.assert_called_once_with()

Expand Down

0 comments on commit bdef103

Please sign in to comment.