diff --git a/instana/agent.py b/instana/agent.py index 667cff05..f4d1571e 100644 --- a/instana/agent.py +++ b/instana/agent.py @@ -1,5 +1,5 @@ import json -import instana.log as l +from instana import log import instana.fsm as f import instana.agent_const as a import threading @@ -38,7 +38,7 @@ class Agent(object): from_ = None def __init__(self, sensor): - l.debug("initializing agent") + log.debug("initializing agent") self.sensor = sensor self.fsm = f.Fsm(self) @@ -49,7 +49,7 @@ def to_json(self, o): return json.dumps(o, default=lambda o: o.__dict__, sort_keys=False, separators=(',', ':')).encode() except Exception as e: - l.info("to_json: ", e, o) + log.info("to_json: ", e, o) def can_send(self): return self.fsm.fsm.current == "good2go" @@ -87,8 +87,7 @@ def full_request_response(self, url, method, o, body, header): self.reset() else: if response.getcode() < 200 or response.getcode() >= 300: - l.error("Request returned erroneous code", - response.getcode()) + log.error("Request returned erroneous code", response.getcode()) if self.can_send(): self.reset() else: @@ -104,7 +103,8 @@ def full_request_response(self, url, method, o, body, header): # No need to show the initial 404s or timeouts. The agent # should handle those correctly. if not (type(e) is urllib2.HTTPError and e.code == 404): - l.debug("%s: full_request_response: %s" % (threading.current_thread().name, str(e))) + log.debug("%s: full_request_response: %s" % + (threading.current_thread().name, str(e))) return (b, h) diff --git a/instana/django19.py b/instana/django19.py index d7ed9ed8..be94c072 100644 --- a/instana/django19.py +++ b/instana/django19.py @@ -44,7 +44,6 @@ def process_response(self, request, response): return response - def hook(module): """ Hook method to install the Instana middleware into Django """ if "INSTANA_DEV" in os.environ: @@ -52,7 +51,6 @@ def hook(module): print("Instana: Running django19 hook") print("==============================================================") - if DJ19_INSTANA_MIDDLEWARE in module.settings.MIDDLEWARE_CLASSES: return diff --git a/instana/fsm.py b/instana/fsm.py index 561ecffd..85cd38ad 100644 --- a/instana/fsm.py +++ b/instana/fsm.py @@ -4,7 +4,7 @@ import socket import threading as t import fysom as f -import instana.log as l +from instana import log import instana.agent_const as a @@ -36,8 +36,8 @@ class Fsm(object): timer = None def __init__(self, agent): - l.info("Stan is on the scene. Starting Instana instrumentation.") - l.debug("initializing fsm") + log.info("Stan is on the scene. Starting Instana instrumentation.") + log.debug("initializing fsm") self.agent = agent self.fsm = f.Fysom({ @@ -53,8 +53,8 @@ def __init__(self, agent): "onchangestate": self.printstatechange}}) def printstatechange(self, e): - l.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' % \ - (os.getpid(), t.current_thread().name, e.event, e.src, e.dst)) + log.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' % + (os.getpid(), t.current_thread().name, e.event, e.src, e.dst)) def reset(self): self.fsm.lookup() @@ -79,26 +79,27 @@ def lookup_agent_host(self, e): self.fsm.announce() return True - l.warn("Instana Host Agent can't be found. Scheduling retry.") + log.warn("Instana Host Agent can't be found. Scheduling retry.") self.schedule_retry(self.lookup_agent_host, e, "agent_lookup") return False def get_default_gateway(self): - l.debug("checking default gateway") + log.debug("checking default gateway") try: proc = subprocess.Popen( - "/sbin/ip route | awk '/default/' | cut -d ' ' -f 3 | tr -d '\n'", shell=True, stdout=subprocess.PIPE) + "/sbin/ip route | awk '/default/' | cut -d ' ' -f 3 | tr -d '\n'", + shell=True, stdout=subprocess.PIPE) addr = proc.stdout.read() return addr.decode("UTF-8") except Exception as e: - l.error(e) + log.error(e) return None def check_host(self, host): - l.debug("checking host", host) + log.debug("checking host", host) (_, h) = self.agent.request_header( self.agent.make_host_url(host, "/"), "GET", "Server") @@ -106,7 +107,7 @@ def check_host(self, host): return h def announce_sensor(self, e): - l.debug("announcing sensor to the agent") + log.debug("announcing sensor to the agent") s = None pid = os.getpid() @@ -135,23 +136,24 @@ def announce_sensor(self, e): if b: self.agent.set_from(b) self.fsm.ready() - l.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % (pid, self.agent.from_.pid)) + log.warn("Host agent available. We're in business. Announced pid: %i (true pid: %i)" % + (pid, self.agent.from_.pid)) return True else: - l.warn("Cannot announce sensor. Scheduling retry.") + log.warn("Cannot announce sensor. Scheduling retry.") self.schedule_retry(self.announce_sensor, e, "announce") return False def schedule_retry(self, fun, e, name): - l.debug("Scheduling: " + name) + log.debug("Scheduling: " + name) self.timer = t.Timer(self.RETRY_PERIOD, fun, [e]) self.timer.daemon = True self.timer.name = name self.timer.start() - l.debug('Threadlist: ', str(t.enumerate())) + log.debug('Threadlist: ', str(t.enumerate())) def test_agent(self, e): - l.debug("testing communication with the agent") + log.debug("testing communication with the agent") (b, _) = self.agent.head(self.agent.make_url(a.AGENT_DATA_URL)) diff --git a/instana/log.py b/instana/log.py index 12c227d1..d6691ac5 100644 --- a/instana/log.py +++ b/instana/log.py @@ -1,16 +1,16 @@ -import logging as l +import logging as log import os -logger = l.getLogger('instana(' + str(os.getpid()) + ')') +logger = log.getLogger('instana(' + str(os.getpid()) + ')') def init(level): - ch = l.StreamHandler() - f = l.Formatter('%(asctime)s: %(levelname)s: %(name)s: %(message)s') + ch = log.StreamHandler() + f = log.Formatter('%(asctime)s: %(levelname)s: %(name)s: %(message)s') ch.setFormatter(f) logger.addHandler(ch) if "INSTANA_DEV" in os.environ: - logger.setLevel(l.DEBUG) + logger.setLevel(log.DEBUG) else: logger.setLevel(level) diff --git a/instana/meter.py b/instana/meter.py index 1e6348ef..1fd48c72 100644 --- a/instana/meter.py +++ b/instana/meter.py @@ -1,5 +1,5 @@ import threading as t -import instana.log as l +from instana import log import resource import os import gc as gc_ @@ -7,7 +7,6 @@ import instana.agent_const as a import copy import time -import json from types import ModuleType @@ -178,7 +177,7 @@ def collect_snapshot(self): return s except Exception as e: - l.debug("collect_snapshot: ", str(e)) + log.debug("collect_snapshot: ", str(e)) return None @@ -210,11 +209,11 @@ def collect_modules(self): r[k] = "builtin" except Exception as e: r[k] = "unknown" - l.debug("collect_modules: could not process module ", k, str(e)) + log.debug("collect_modules: could not process module ", k, str(e)) return r except Exception as e: - l.debug("collect_modules: ", str(e)) + log.debug("collect_modules: ", str(e)) return None diff --git a/instana/recorder.py b/instana/recorder.py index e7d23170..a48b26a9 100644 --- a/instana/recorder.py +++ b/instana/recorder.py @@ -85,8 +85,8 @@ def build_registered_span(self, span): baggage=span.context.baggage, custom=sd.CustomData(tags=span.tags, logs=self.collect_logs(span))) - entityFrom = { 'e': self.sensor.agent.from_.pid, - 'h': self.sensor.agent.from_.agentUuid } + entityFrom = {'e': self.sensor.agent.from_.pid, + 'h': self.sensor.agent.from_.agentUuid} return sd.InstanaSpan( n=span.operation_name, @@ -114,8 +114,8 @@ def build_sdk_span(self, span): sdk_data.Type = self.get_span_kind(span) data = sd.Data(service=self.get_service_name(span), sdk=sdk_data) - entityFrom = { 'e': self.sensor.agent.from_.pid, - 'h': self.sensor.agent.from_.agentUuid } + entityFrom = {'e': self.sensor.agent.from_.pid, + 'h': self.sensor.agent.from_.agentUuid} return sd.InstanaSpan( t=span.context.trace_id, @@ -169,7 +169,7 @@ def collect_logs(self, span): logs = {} for l in span.logs: ts = int(round(l.timestamp * 1000)) - if not ts in logs: + if ts not in logs: logs[ts] = {} for f in l.key_values: @@ -177,6 +177,7 @@ def collect_logs(self, span): return logs + class InstanaSampler(Sampler): def sampled(self, _): diff --git a/instana/runtime.py b/instana/runtime.py index 30ffb25a..ed06ba21 100644 --- a/instana/runtime.py +++ b/instana/runtime.py @@ -1,6 +1,5 @@ import opentracing as ot from instana import tracer, options -import logging import os diff --git a/instana/sensor.py b/instana/sensor.py index 973e3ca5..f2baa95c 100644 --- a/instana/sensor.py +++ b/instana/sensor.py @@ -1,8 +1,7 @@ import instana.options as o -import instana.log as l import instana.meter as m import instana.agent as a -import os +from instana import log class Sensor(object): @@ -13,12 +12,12 @@ class Sensor(object): def __init__(self, options): self.set_options(options) - l.init(options.log_level) + log.init(options.log_level) self.configure_service_name() self.agent = a.Agent(self) self.meter = m.Meter(self) - l.debug("initialized sensor") + log.debug("initialized sensor") def set_options(self, options): self.options = options diff --git a/instana/wsgi.py b/instana/wsgi.py index 801e828d..983ee1e3 100644 --- a/instana/wsgi.py +++ b/instana/wsgi.py @@ -1,7 +1,6 @@ import opentracing as ot from instana import tracer, options import opentracing.ext.tags as tags -import logging class iWSGIMiddleware(object):