From bdef103d5999ca9301b65f24cb5f8d4d33f6250e Mon Sep 17 00:00:00 2001 From: Dmitry Prokopchenkov Date: Wed, 26 Jul 2017 17:23:37 +0300 Subject: [PATCH] minor changes --- README.md | 1 + py_zipkin/logging_helper.py | 11 +++-------- py_zipkin/zipkin.py | 12 ++++++------ tests/integration/zipkin_integration_test.py | 3 ++- tests/logging_helper_test.py | 4 ++-- tests/zipkin_test.py | 8 ++++---- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 16a1bb8..09178e1 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/py_zipkin/logging_helper.py b/py_zipkin/logging_helper.py index 1c4229a..7399a7d 100644 --- a/py_zipkin/logging_helper.py +++ b/py_zipkin/logging_helper.py @@ -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 @@ -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. @@ -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 @@ -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, @@ -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() diff --git a/py_zipkin/zipkin.py b/py_zipkin/zipkin.py index 8deab54..bf21df1 100644 --- a/py_zipkin/zipkin.py +++ b/py_zipkin/zipkin.py @@ -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, @@ -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 @@ -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 @@ -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 diff --git a/tests/integration/zipkin_integration_test.py b/tests/integration/zipkin_integration_test.py index 3bfe7b5..3f1f503 100644 --- a/tests/integration/zipkin_integration_test.py +++ b/tests/integration/zipkin_integration_test.py @@ -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 diff --git a/tests/logging_helper_test.py b/tests/logging_helper_test.py index 343342d..8aeec37 100644 --- a/tests/logging_helper_test.py +++ b/tests/logging_helper_test.py @@ -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', @@ -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(): diff --git a/tests/zipkin_test.py b/tests/zipkin_test.py index 1767ea7..9228c28 100644 --- a/tests/zipkin_test.py +++ b/tests/zipkin_test.py @@ -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() @@ -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() @@ -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() @@ -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()