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
8 changes: 4 additions & 4 deletions instana/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def is_agent_listening(self, host, port):

server_header = response.headers["Server"]
if server_header == AGENT_HEADER:
logger.debug("Host agent found on %s:%d", host, port)
logger.debug("Instana host agent found on %s:%d", host, port)
rv = True
else:
logger.debug("...something is listening on %s:%d but it's not the Instana Host Agent: %s",
Expand Down Expand Up @@ -179,7 +179,7 @@ def is_agent_ready(self):
return True
return False
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("is_agent_ready: host agent connection error")
logger.debug("is_agent_ready: Instana host agent connection error")

def report_data(self, entity_data):
"""
Expand All @@ -197,7 +197,7 @@ def report_data(self, entity_data):
if response.status_code is 200:
self.last_seen = datetime.now()
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("report_data: host agent connection error")
logger.debug("report_data: Instana host agent connection error")
finally:
return response

Expand All @@ -222,7 +222,7 @@ def report_traces(self, spans):
if response.status_code is 200:
self.last_seen = datetime.now()
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("report_traces: host agent connection error")
logger.debug("report_traces: Instana host agent connection error")
finally:
return response

Expand Down
4 changes: 2 additions & 2 deletions instana/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def lookup_agent_host(self, e):
return True

if self.warnedPeriodic is False:
logger.warn("Instana Host Agent couldn't be found. Will retry periodically...")
logger.info("Instana Host Agent couldn't be found. Will retry periodically...")
self.warnedPeriodic = True

self.schedule_retry(self.lookup_agent_host, e, self.THREAD_NAME + ": agent_lookup")
Expand Down Expand Up @@ -177,7 +177,7 @@ def schedule_retry(self, fun, e, name):
self.timer.start()

def on_ready(self, _):
logger.info("Host agent available. We're in business. Announced pid: %s (true pid: %s)",
logger.info("Instana host agent available. We're in business. Announced pid: %s (true pid: %s)",
str(os.getpid()), str(self.agent.from_.pid))

def __get_real_pid(self):
Expand Down
56 changes: 40 additions & 16 deletions instana/log.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
import logging as log
import logging
import os
import sys

logger = log.getLogger('instana')
logger = None


def init(level):
ch = log.StreamHandler()
f = log.Formatter('%(asctime)s: %(process)d %(levelname)s %(name)s: %(message)s')
def get_standard_logger():
"""
Retrieves and configures a standard logger for the Instana package

:return: Logger
"""
standard_logger = logging.getLogger("instana")

ch = logging.StreamHandler()
f = logging.Formatter('%(asctime)s: %(process)d %(levelname)s %(name)s: %(message)s')
ch.setFormatter(f)
logger.addHandler(ch)
standard_logger.addHandler(ch)
if "INSTANA_DEBUG" in os.environ:
logger.setLevel(log.DEBUG)
standard_logger.setLevel(logging.DEBUG)
else:
logger.setLevel(level)
standard_logger.setLevel(logging.WARN)

return standard_logger

def debug(s, *args):
logger.debug("%s %s", s, ' '.join(args))

def running_in_gunicorn():
"""
Determines if we are running inside of a gunicorn process and that the gunicorn logging package
is available.

def info(s, *args):
logger.info("%s %s", s, ' '.join(args))
:return: Boolean
"""
process_check = False
package_check = False

for arg in sys.argv:
if arg.find('gunicorn') >= 0:
process_check = True

try:
from gunicorn import glogging
except ImportError:
pass
else:
package_check = True

def warn(s, *args):
logger.warn("%s %s", s, ' '.join(args))
return process_check and package_check


def error(s, *args):
logger.error("%s %s", s, ' '.join(args))
if running_in_gunicorn():
logger = logging.getLogger("gunicorn.error")
else:
logger = get_standard_logger()
2 changes: 1 addition & 1 deletion instana/meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def metric_work():
self.process()

if self.agent.is_timed_out():
logger.warn("Host agent offline for >1 min. Going to sit in a corner...")
logger.warn("Instana host agent unreachable for >1 min. Going to sit in a corner...")
self.agent.reset()
return False
return True
Expand Down
8 changes: 3 additions & 5 deletions instana/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import

from .log import init as init_logger
from .meter import Meter
from .options import Options

Expand All @@ -12,15 +11,14 @@ class Sensor(object):

def __init__(self, agent, options=None):
self.set_options(options)
init_logger(self.options.log_level)

self.agent = agent
self.meter = Meter(agent)

def set_options(self, options):
self.options = options
if not self.options:
if options is None:
self.options = Options()
else:
self.options = options

def start(self):
# Nothing to do for the Sensor; Pass onto Meter
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from distutils.version import LooseVersion
from setuptools import find_packages, setup

VERSION = '1.15.2'
VERSION = '1.15.3'

# Import README.md into long_description
pwd = path.abspath(path.dirname(__file__))
Expand Down