Skip to content

Commit 104f82d

Browse files
committed
Linter happiness & peace ☮️
1 parent 9971d94 commit 104f82d

File tree

9 files changed

+42
-45
lines changed

9 files changed

+42
-45
lines changed

instana/agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
import instana.log as l
2+
from instana import log
33
import instana.fsm as f
44
import instana.agent_const as a
55
import threading
@@ -38,7 +38,7 @@ class Agent(object):
3838
from_ = None
3939

4040
def __init__(self, sensor):
41-
l.debug("initializing agent")
41+
log.debug("initializing agent")
4242

4343
self.sensor = sensor
4444
self.fsm = f.Fsm(self)
@@ -49,7 +49,7 @@ def to_json(self, o):
4949
return json.dumps(o, default=lambda o: o.__dict__,
5050
sort_keys=False, separators=(',', ':')).encode()
5151
except Exception as e:
52-
l.info("to_json: ", e, o)
52+
log.info("to_json: ", e, o)
5353

5454
def can_send(self):
5555
return self.fsm.fsm.current == "good2go"
@@ -87,8 +87,7 @@ def full_request_response(self, url, method, o, body, header):
8787
self.reset()
8888
else:
8989
if response.getcode() < 200 or response.getcode() >= 300:
90-
l.error("Request returned erroneous code",
91-
response.getcode())
90+
log.error("Request returned erroneous code", response.getcode())
9291
if self.can_send():
9392
self.reset()
9493
else:
@@ -104,7 +103,8 @@ def full_request_response(self, url, method, o, body, header):
104103
# No need to show the initial 404s or timeouts. The agent
105104
# should handle those correctly.
106105
if not (type(e) is urllib2.HTTPError and e.code == 404):
107-
l.debug("%s: full_request_response: %s" % (threading.current_thread().name, str(e)))
106+
log.debug("%s: full_request_response: %s" %
107+
(threading.current_thread().name, str(e)))
108108

109109
return (b, h)
110110

instana/django19.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ def process_response(self, request, response):
4444
return response
4545

4646

47-
4847
def hook(module):
4948
""" Hook method to install the Instana middleware into Django """
5049
if "INSTANA_DEV" in os.environ:
5150
print("==============================================================")
5251
print("Instana: Running django19 hook")
5352
print("==============================================================")
5453

55-
5654
if DJ19_INSTANA_MIDDLEWARE in module.settings.MIDDLEWARE_CLASSES:
5755
return
5856

instana/fsm.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import socket
55
import threading as t
66
import fysom as f
7-
import instana.log as l
7+
from instana import log
88
import instana.agent_const as a
99

1010

@@ -36,8 +36,8 @@ class Fsm(object):
3636
timer = None
3737

3838
def __init__(self, agent):
39-
l.info("Stan is on the scene. Starting Instana instrumentation.")
40-
l.debug("initializing fsm")
39+
log.info("Stan is on the scene. Starting Instana instrumentation.")
40+
log.debug("initializing fsm")
4141

4242
self.agent = agent
4343
self.fsm = f.Fysom({
@@ -53,8 +53,8 @@ def __init__(self, agent):
5353
"onchangestate": self.printstatechange}})
5454

5555
def printstatechange(self, e):
56-
l.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' % \
57-
(os.getpid(), t.current_thread().name, e.event, e.src, e.dst))
56+
log.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' %
57+
(os.getpid(), t.current_thread().name, e.event, e.src, e.dst))
5858

5959
def reset(self):
6060
self.fsm.lookup()
@@ -79,34 +79,35 @@ def lookup_agent_host(self, e):
7979
self.fsm.announce()
8080
return True
8181

82-
l.warn("Instana Host Agent can't be found. Scheduling retry.")
82+
log.warn("Instana Host Agent can't be found. Scheduling retry.")
8383
self.schedule_retry(self.lookup_agent_host, e, "agent_lookup")
8484
return False
8585

8686
def get_default_gateway(self):
87-
l.debug("checking default gateway")
87+
log.debug("checking default gateway")
8888

8989
try:
9090
proc = subprocess.Popen(
91-
"/sbin/ip route | awk '/default/' | cut -d ' ' -f 3 | tr -d '\n'", shell=True, stdout=subprocess.PIPE)
91+
"/sbin/ip route | awk '/default/' | cut -d ' ' -f 3 | tr -d '\n'",
92+
shell=True, stdout=subprocess.PIPE)
9293

9394
addr = proc.stdout.read()
9495
return addr.decode("UTF-8")
9596
except Exception as e:
96-
l.error(e)
97+
log.error(e)
9798

9899
return None
99100

100101
def check_host(self, host):
101-
l.debug("checking host", host)
102+
log.debug("checking host", host)
102103

103104
(_, h) = self.agent.request_header(
104105
self.agent.make_host_url(host, "/"), "GET", "Server")
105106

106107
return h
107108

108109
def announce_sensor(self, e):
109-
l.debug("announcing sensor to the agent")
110+
log.debug("announcing sensor to the agent")
110111
s = None
111112
pid = os.getpid()
112113

@@ -135,23 +136,24 @@ def announce_sensor(self, e):
135136
if b:
136137
self.agent.set_from(b)
137138
self.fsm.ready()
138-
l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (pid, self.agent.from_.pid))
139+
log.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" %
140+
(pid, self.agent.from_.pid))
139141
return True
140142
else:
141-
l.warn("Cannot announce sensor. Scheduling retry.")
143+
log.warn("Cannot announce sensor. Scheduling retry.")
142144
self.schedule_retry(self.announce_sensor, e, "announce")
143145
return False
144146

145147
def schedule_retry(self, fun, e, name):
146-
l.debug("Scheduling: " + name)
148+
log.debug("Scheduling: " + name)
147149
self.timer = t.Timer(self.RETRY_PERIOD, fun, [e])
148150
self.timer.daemon = True
149151
self.timer.name = name
150152
self.timer.start()
151-
l.debug('Threadlist: ', str(t.enumerate()))
153+
log.debug('Threadlist: ', str(t.enumerate()))
152154

153155
def test_agent(self, e):
154-
l.debug("testing communication with the agent")
156+
log.debug("testing communication with the agent")
155157

156158
(b, _) = self.agent.head(self.agent.make_url(a.AGENT_DATA_URL))
157159

instana/log.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import logging as l
1+
import logging as log
22
import os
33

4-
logger = l.getLogger('instana(' + str(os.getpid()) + ')')
4+
logger = log.getLogger('instana(' + str(os.getpid()) + ')')
55

66

77
def init(level):
8-
ch = l.StreamHandler()
9-
f = l.Formatter('%(asctime)s: %(levelname)s: %(name)s: %(message)s')
8+
ch = log.StreamHandler()
9+
f = log.Formatter('%(asctime)s: %(levelname)s: %(name)s: %(message)s')
1010
ch.setFormatter(f)
1111
logger.addHandler(ch)
1212
if "INSTANA_DEV" in os.environ:
13-
logger.setLevel(l.DEBUG)
13+
logger.setLevel(log.DEBUG)
1414
else:
1515
logger.setLevel(level)
1616

instana/meter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import threading as t
2-
import instana.log as l
2+
from instana import log
33
import resource
44
import os
55
import gc as gc_
66
import sys
77
import instana.agent_const as a
88
import copy
99
import time
10-
import json
1110
from types import ModuleType
1211

1312

@@ -178,7 +177,7 @@ def collect_snapshot(self):
178177

179178
return s
180179
except Exception as e:
181-
l.debug("collect_snapshot: ", str(e))
180+
log.debug("collect_snapshot: ", str(e))
182181

183182
return None
184183

@@ -210,11 +209,11 @@ def collect_modules(self):
210209
r[k] = "builtin"
211210
except Exception as e:
212211
r[k] = "unknown"
213-
l.debug("collect_modules: could not process module ", k, str(e))
212+
log.debug("collect_modules: could not process module ", k, str(e))
214213

215214
return r
216215
except Exception as e:
217-
l.debug("collect_modules: ", str(e))
216+
log.debug("collect_modules: ", str(e))
218217

219218
return None
220219

instana/recorder.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def build_registered_span(self, span):
8585
baggage=span.context.baggage,
8686
custom=sd.CustomData(tags=span.tags,
8787
logs=self.collect_logs(span)))
88-
entityFrom = { 'e': self.sensor.agent.from_.pid,
89-
'h': self.sensor.agent.from_.agentUuid }
88+
entityFrom = {'e': self.sensor.agent.from_.pid,
89+
'h': self.sensor.agent.from_.agentUuid}
9090

9191
return sd.InstanaSpan(
9292
n=span.operation_name,
@@ -114,8 +114,8 @@ def build_sdk_span(self, span):
114114

115115
sdk_data.Type = self.get_span_kind(span)
116116
data = sd.Data(service=self.get_service_name(span), sdk=sdk_data)
117-
entityFrom = { 'e': self.sensor.agent.from_.pid,
118-
'h': self.sensor.agent.from_.agentUuid }
117+
entityFrom = {'e': self.sensor.agent.from_.pid,
118+
'h': self.sensor.agent.from_.agentUuid}
119119

120120
return sd.InstanaSpan(
121121
t=span.context.trace_id,
@@ -169,14 +169,15 @@ def collect_logs(self, span):
169169
logs = {}
170170
for l in span.logs:
171171
ts = int(round(l.timestamp * 1000))
172-
if not ts in logs:
172+
if ts not in logs:
173173
logs[ts] = {}
174174

175175
for f in l.key_values:
176176
logs[ts][f] = l.key_values[f]
177177

178178
return logs
179179

180+
180181
class InstanaSampler(Sampler):
181182

182183
def sampled(self, _):

instana/runtime.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import opentracing as ot
22
from instana import tracer, options
3-
import logging
43
import os
54

65

instana/sensor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import instana.options as o
2-
import instana.log as l
32
import instana.meter as m
43
import instana.agent as a
5-
import os
4+
from instana import log
65

76

87
class Sensor(object):
@@ -13,12 +12,12 @@ class Sensor(object):
1312

1413
def __init__(self, options):
1514
self.set_options(options)
16-
l.init(options.log_level)
15+
log.init(options.log_level)
1716
self.configure_service_name()
1817
self.agent = a.Agent(self)
1918
self.meter = m.Meter(self)
2019

21-
l.debug("initialized sensor")
20+
log.debug("initialized sensor")
2221

2322
def set_options(self, options):
2423
self.options = options

instana/wsgi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import opentracing as ot
22
from instana import tracer, options
33
import opentracing.ext.tags as tags
4-
import logging
54

65

76
class iWSGIMiddleware(object):

0 commit comments

Comments
 (0)