Skip to content

Commit

Permalink
Merge pull request #181 from DataDog/talwai/pylons
Browse files Browse the repository at this point in the history
pylons: add autopatching
  • Loading branch information
talwai authored Mar 29, 2017
2 parents 9fa984c + 1dc1e24 commit 419a899
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ddtrace/contrib/pylons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

from .middleware import PylonsTraceMiddleware
from .patch import patch


__all__ = ['PylonsTraceMiddleware']
__all__ = ['PylonsTraceMiddleware', 'patch']
26 changes: 26 additions & 0 deletions ddtrace/contrib/pylons/patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from .middleware import PylonsTraceMiddleware

from ddtrace import tracer, Pin

import wrapt

import pylons.wsgiapp

def patch():
"""Patch the instrumented Flask object
"""
if getattr(pylons.wsgiapp, '_datadog_patch', False):
return

setattr(pylons.wsgiapp, '_datadog_patch', True)

wrapt.wrap_function_wrapper('pylons.wsgiapp', 'PylonsApp.__init__', traced_init)

def traced_init(wrapped, instance, args, kwargs):
wrapped(*args, **kwargs)

service = os.environ.get("DATADOG_SERVICE_NAME") or "pylons"
Pin(service=service, tracer=tracer).onto(instance)
PylonsTraceMiddleware(instance, tracer, service=service)
10 changes: 5 additions & 5 deletions ddtrace/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
'aiohttp': True, # requires asyncio (Python 3.4+)

# Ignore some web framework integrations that might be configured explicitly in code
'django': False,
'flask': False,
'pylons': False,
'falcon': False,
'pyramid': False,
"django": False,
"flask": False,
"falcon": False,
"pylons": False,
"pyramid": False,
}

_LOCK = threading.Lock()
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ envlist =
{py27,py34,py35,py36}-ddtracerun
{py27,py34,py35,py36}-contrib
{py34,py35,py36}-asyncio
{py27}-pylons
{py34,py35,py36}-aiohttp{12,13}-aiohttp_jinja{012,013}
{py27,py34,py35,py36}-bottle{12}-webtest
{py27,py34,py35,py36}-bottle-autopatch{12}-webtest
Expand Down Expand Up @@ -131,6 +132,7 @@ deps =
memcached: python-memcached
mongoengine011: mongoengine>=0.11,<0.12
mysqlconnector21: mysql-connector>=2.1,<2.2
pylons: pylons
pylibmc: pylibmc
pylibmc140: pylibmc>=1.4.0,<1.5.0
pylibmc150: pylibmc>=1.5.0,<1.6.0
Expand Down Expand Up @@ -173,10 +175,11 @@ commands =
# integration tests
integration: nosetests {posargs} tests/test_integration.py
# run all tests for the release jobs except the ones with a different test runner
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|gevent|falcon|flask_autopatch|bottle).*" tests/contrib
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|gevent|falcon|flask_autopatch|bottle|pylons).*" tests/contrib
asyncio: nosetests {posargs} tests/contrib/asyncio
aiohttp{12,13}-aiohttp_jinja{012,013}: nosetests {posargs} tests/contrib/aiohttp
# run subsets of the tests for particular library versions
{py27}-pylons: nosetests {posargs} tests/contrib/pylons
{py27,py34}-boto: nosetests {posargs} tests/contrib/boto
{py27,py34}-botocore: nosetests {posargs} tests/contrib/botocore
bottle{12}: nosetests {posargs} tests/contrib/bottle/test.py
Expand Down

0 comments on commit 419a899

Please sign in to comment.