6
6
7
7
from lightstep .collector_pb2 import ReportResponse
8
8
9
- CONSECUTIVE_ERRORS_BEFORE_RECONNECT = 200
10
-
11
9
12
10
class _HTTPConnection (object ):
13
11
"""Instances of _Connection are used to establish a connection to the
14
12
server via HTTP protocol.
15
13
"""
16
- def __init__ (self , collector_url ):
14
+ def __init__ (self , collector_url , timeout_seconds ):
17
15
self ._collector_url = collector_url
18
16
self ._lock = threading .Lock ()
19
17
self .ready = True
20
- self ._report_eof_count = 0
21
- self ._report_consecutive_errors = 0
18
+ self ._timeout_seconds = timeout_seconds
22
19
23
20
def open (self ):
24
21
"""Establish HTTP connection to the server.
@@ -28,9 +25,6 @@ def open(self):
28
25
# May throw an Exception on failure.
29
26
def report (self , * args , ** kwargs ):
30
27
"""Report to the server."""
31
- # Notice the annoying case change on the method name. I chose to stay
32
- # consistent with casing in this class vs staying consistent with the
33
- # casing of the pass-through method.
34
28
auth = args [0 ]
35
29
report = args [1 ]
36
30
with self ._lock :
@@ -39,22 +33,16 @@ def report(self, *args, **kwargs):
39
33
headers = {"Content-Type" : "application/octet-stream" ,
40
34
"Accept" : "application/octet-stream" }
41
35
42
- r = requests .post (self ._collector_url , headers = headers , data = report .SerializeToString ())
36
+ r = requests .post (
37
+ self ._collector_url ,
38
+ headers = headers ,
39
+ data = report .SerializeToString (),
40
+ timeout = self ._timeout_seconds )
43
41
resp = ReportResponse ()
44
42
resp .ParseFromString (r .content )
45
- self ._report_consecutive_errors = 0
46
43
return resp
47
- except EOFError :
48
- self ._report_consecutive_errors += 1
49
- self ._report_eof_count += 1
50
- raise Exception ('EOFError' )
51
- finally :
52
- # In case the client has fallen into an unrecoverable state,
53
- # recreate the data structure if there are continued report
54
- # failures
55
- if self ._report_consecutive_errors == CONSECUTIVE_ERRORS_BEFORE_RECONNECT :
56
- self ._report_consecutive_errors = 0
57
- self .ready = False
44
+ except requests .exceptions .RequestException as err :
45
+ raise err
58
46
59
47
def close (self ):
60
48
"""Close HTTP connection to the server."""
0 commit comments