Skip to content

Commit

Permalink
Use TBinaryProtocolAccelerated when serializing reports.
Browse files Browse the repository at this point in the history
We're currently seeing our services spend a large amount of time inside of the lightstep sdk
serializing reports when they instrument themselves with tracing.  This is in large part due to
the fact that lightstep is using the pure python implemenation of Thrift.

Fixes lightstep#89
  • Loading branch information
Roy Williams committed Jan 14, 2020
1 parent df79518 commit d843781
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lightstep/thrift_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import threading
from thrift import Thrift
from thrift.transport import THttpClient
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from .crouton import ReportingService

Expand All @@ -21,6 +22,7 @@ class _ThriftConnection(object):
def __init__(self, collector_url):
self._collector_url = collector_url
self._lock = threading.Lock()
self._http_client = None
self._transport = None
self._client = None
self.ready = False
Expand All @@ -38,9 +40,10 @@ def open(self):
"""
self._lock.acquire()
try:
self._transport = THttpClient.THttpClient(self._collector_url)
self._http_client = THttpClient.THttpClient(self._collector_url)
self._transport = TTransport.TBufferedTransport(self._http_client)
self._transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(self._transport)
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self._transport, fallback=True)
self._client = ReportingService.Client(protocol)
except Thrift.TException:
self._open_exceptions_count += 1
Expand All @@ -61,7 +64,7 @@ def report(self, *args, **kwargs):
try:
if self._client:
headers = {"Lightstep-Access-Token": args[0].access_token}
self._transport.setCustomHeaders(headers)
self._http_client.setCustomHeaders(headers)
resp = self._client.Report(*args, **kwargs)
self._report_consecutive_errors = 0
except Thrift.TException:
Expand Down

0 comments on commit d843781

Please sign in to comment.