Skip to content

Commit 602104b

Browse files
committed
fixed threading, first throw of Python 2 and 3 capability
1 parent 1777387 commit 602104b

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

instana/agent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import json
2-
import urllib2
32
import instana.log as l
43
import instana.fsm as f
54
import instana.agent_const as a
65

6+
try:
7+
import urllib.request as urllib2
8+
except ImportError:
9+
import urllib2
710

811
class From(object):
912
pid = ""
@@ -39,7 +42,7 @@ def __init__(self, sensor):
3942
self.reset()
4043

4144
def to_json(self, o):
42-
return json.dumps(o, default=lambda o: o.__dict__, sort_keys=False, indent=4)
45+
return json.dumps(o, default=lambda o: o.__dict__, sort_keys=False, indent=4).encode()
4346

4447
def can_send(self):
4548
return self.fsm.fsm.current == "ready"
@@ -86,7 +89,7 @@ def full_request_response(self, url, method, o, body, header):
8689
b = response.read()
8790

8891
if header:
89-
h = response.info().getheader(header)
92+
h = response.info().get(header)
9093

9194
if method == "HEAD":
9295
b = True

instana/meter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def process(self):
9898
m = self.collect_metrics()
9999
d = EntityData(pid=os.getpid(), snapshot=s, metrics=m)
100100

101-
t.Thread(self.sensor.agent.request, args=(self.sensor.agent.make_url(a.AGENT_DATA_URL), "POST", d)).start()
101+
t.Thread(target=self.sensor.agent.request,
102+
args=(self.sensor.agent.make_url(a.AGENT_DATA_URL), "POST", d)).start()
102103

103104
self.tick()
104105

instana/recorder.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def record_span(self, span):
2929
if not data.service:
3030
data.service = self.sensor.service_name
3131

32-
t.Thread(self.sensor.agent.request,
33-
args=(self.sensor.agent.make_url(a.AGENT_TRACES_URL), "POST",
34-
[InstanaSpan(t=span.context.trace_id,
35-
p=span.parent_id,
36-
s=span.context.span_id,
37-
ts=int(round(span.start_time * 1000)),
38-
d=int(round(span.duration * 1000)),
39-
n=self.get_string_span_log_field(span, "type"),
40-
f=self.sensor.agent.from_,
41-
data=data)])).start()
32+
t.Thread(target=self.sensor.agent.request,
33+
args=(self.sensor.agent.make_url(a.AGENT_TRACES_URL), "POST",
34+
[InstanaSpan(t=span.context.trace_id,
35+
p=span.parent_id,
36+
s=span.context.span_id,
37+
ts=int(round(span.start_time * 1000)),
38+
d=int(round(span.duration * 1000)),
39+
n=self.get_string_span_log_field(span, "type"),
40+
f=self.sensor.agent.from_,
41+
data=data)])).start()
4242

4343
def get_string_span_log_field(self, span, field):
4444
ret = self.get_span_log_field(span, field)

0 commit comments

Comments
 (0)