Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions instana/agent.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions instana/django19.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ 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:
print("==============================================================")
print("Instana: Running django19 hook")
print("==============================================================")


if DJ19_INSTANA_MIDDLEWARE in module.settings.MIDDLEWARE_CLASSES:
return

Expand Down
34 changes: 18 additions & 16 deletions instana/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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({
Expand All @@ -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()
Expand All @@ -79,34 +79,35 @@ 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")

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()

Expand Down Expand Up @@ -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))

Expand Down
10 changes: 5 additions & 5 deletions instana/log.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 4 additions & 5 deletions instana/meter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import threading as t
import instana.log as l
from instana import log
import resource
import os
import gc as gc_
import sys
import instana.agent_const as a
import copy
import time
import json
from types import ModuleType


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions instana/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -169,14 +169,15 @@ 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:
logs[ts][f] = l.key_values[f]

return logs


class InstanaSampler(Sampler):

def sampled(self, _):
Expand Down
1 change: 0 additions & 1 deletion instana/runtime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import opentracing as ot
from instana import tracer, options
import logging
import os


Expand Down
7 changes: 3 additions & 4 deletions instana/sensor.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion instana/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import opentracing as ot
from instana import tracer, options
import opentracing.ext.tags as tags
import logging


class iWSGIMiddleware(object):
Expand Down