Skip to content

Commit 419a899

Browse files
authored
Merge pull request #181 from DataDog/talwai/pylons
pylons: add autopatching
2 parents 9fa984c + 1dc1e24 commit 419a899

4 files changed

Lines changed: 37 additions & 7 deletions

File tree

ddtrace/contrib/pylons/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
from .middleware import PylonsTraceMiddleware
19+
from .patch import patch
1920

2021

21-
__all__ = ['PylonsTraceMiddleware']
22+
__all__ = ['PylonsTraceMiddleware', 'patch']

ddtrace/contrib/pylons/patch.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
from .middleware import PylonsTraceMiddleware
4+
5+
from ddtrace import tracer, Pin
6+
7+
import wrapt
8+
9+
import pylons.wsgiapp
10+
11+
def patch():
12+
"""Patch the instrumented Flask object
13+
"""
14+
if getattr(pylons.wsgiapp, '_datadog_patch', False):
15+
return
16+
17+
setattr(pylons.wsgiapp, '_datadog_patch', True)
18+
19+
wrapt.wrap_function_wrapper('pylons.wsgiapp', 'PylonsApp.__init__', traced_init)
20+
21+
def traced_init(wrapped, instance, args, kwargs):
22+
wrapped(*args, **kwargs)
23+
24+
service = os.environ.get("DATADOG_SERVICE_NAME") or "pylons"
25+
Pin(service=service, tracer=tracer).onto(instance)
26+
PylonsTraceMiddleware(instance, tracer, service=service)

ddtrace/monkey.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
'aiohttp': True, # requires asyncio (Python 3.4+)
3232

3333
# Ignore some web framework integrations that might be configured explicitly in code
34-
'django': False,
35-
'flask': False,
36-
'pylons': False,
37-
'falcon': False,
38-
'pyramid': False,
34+
"django": False,
35+
"flask": False,
36+
"falcon": False,
37+
"pylons": False,
38+
"pyramid": False,
3939
}
4040

4141
_LOCK = threading.Lock()

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ envlist =
1616
{py27,py34,py35,py36}-ddtracerun
1717
{py27,py34,py35,py36}-contrib
1818
{py34,py35,py36}-asyncio
19+
{py27}-pylons
1920
{py34,py35,py36}-aiohttp{12,13}-aiohttp_jinja{012,013}
2021
{py27,py34,py35,py36}-bottle{12}-webtest
2122
{py27,py34,py35,py36}-bottle-autopatch{12}-webtest
@@ -131,6 +132,7 @@ deps =
131132
memcached: python-memcached
132133
mongoengine011: mongoengine>=0.11,<0.12
133134
mysqlconnector21: mysql-connector>=2.1,<2.2
135+
pylons: pylons
134136
pylibmc: pylibmc
135137
pylibmc140: pylibmc>=1.4.0,<1.5.0
136138
pylibmc150: pylibmc>=1.5.0,<1.6.0
@@ -173,10 +175,11 @@ commands =
173175
# integration tests
174176
integration: nosetests {posargs} tests/test_integration.py
175177
# run all tests for the release jobs except the ones with a different test runner
176-
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|gevent|falcon|flask_autopatch|bottle).*" tests/contrib
178+
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|gevent|falcon|flask_autopatch|bottle|pylons).*" tests/contrib
177179
asyncio: nosetests {posargs} tests/contrib/asyncio
178180
aiohttp{12,13}-aiohttp_jinja{012,013}: nosetests {posargs} tests/contrib/aiohttp
179181
# run subsets of the tests for particular library versions
182+
{py27}-pylons: nosetests {posargs} tests/contrib/pylons
180183
{py27,py34}-boto: nosetests {posargs} tests/contrib/boto
181184
{py27,py34}-botocore: nosetests {posargs} tests/contrib/botocore
182185
bottle{12}: nosetests {posargs} tests/contrib/bottle/test.py

0 commit comments

Comments
 (0)