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
3 changes: 3 additions & 0 deletions instana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def boot_agent():

import instana.singletons

# Instrumentation
if "INSTANA_DISABLE_AUTO_INSTR" not in os.environ:
# Import & initialize instrumentation
if sys.version_info >= (3, 5, 3):
Expand Down Expand Up @@ -81,6 +82,8 @@ def boot_agent():
from .instrumentation import urllib3
from .instrumentation.django import middleware

# Hooks
from .hooks import hook_uwsgi

if "INSTANA_MAGIC" in os.environ:
pkg_resources.working_set.add_entry("/tmp/instana/python")
Expand Down
2 changes: 1 addition & 1 deletion instana/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def announce(self, discovery):
"""
try:
url = self.__discovery_url()
logger.debug("making announce request to %s", url)
# logger.debug("making announce request to %s", url)
response = None
response = self.client.put(url,
data=to_json(discovery),
Expand Down
8 changes: 2 additions & 6 deletions instana/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ def reset(self):

:return: void
"""
logger.debug("State machine being reset. Will schedule new announce cycle 6 seconds from now.")

self.timer = t.Timer(6, self.fsm.lookup)
self.timer.daemon = True
self.timer.name = self.THREAD_NAME
self.timer.start()
logger.debug("State machine being reset. Will start a new announce cycle.")
self.fsm.lookup()

def lookup_agent_host(self, e):
self.agent.should_threads_shutdown.clear()
Expand Down
Empty file added instana/hooks/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions instana/hooks/hook_uwsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
The uwsgi and uwsgidecorators packages are added automatically to the Python environment
when running under uWSGI. Here we attempt to detect the presence of these packages and
then use the appropriate hooks.
"""
from __future__ import absolute_import

from ..log import logger
from ..singletons import agent

try:
import uwsgi
logger.debug("uWSGI options: %s", uwsgi.opt)

opt_master = uwsgi.opt.get('master', False)
opt_lazy_apps = uwsgi.opt.get('lazy-apps', False)

if uwsgi.opt.get('enable-threads', False) is False:
logger.warn("Required: uWSGI threads are not enabled. " +
"Please enable by using the uWSGI --enable-threads option.")

if opt_master and opt_lazy_apps is False:
# --master is supplied in uWSGI options (otherwise uwsgidecorators package won't be available)
# When --lazy-apps is True, this postfork hook isn't needed
import uwsgidecorators

@uwsgidecorators.postfork
def uwsgi_handle_fork():
""" This is our uWSGI hook to detect and act when worker processes are forked off. """
logger.debug("Handling uWSGI fork...")
agent.handle_fork()

logger.debug("Applied uWSGI hooks")
else:
logger.debug("uWSGI --master=%s --lazy-apps=%s: postfork hooks not applied", opt_master, opt_lazy_apps)
except ImportError as e:
logger.debug('uwsgi hooks: decorators not available: %s', e)
pass