Skip to content

Commit a068137

Browse files
bmermetEmanuele Palazzetti
authored andcommitted
Disable autocommit in pyramid patching (#343)
* Disable autocommit in pyramid patching * Fix pyramid: include triggered conflicts * Exclude pyramid from generic contrib tests
1 parent e6d018c commit a068137

File tree

7 files changed

+41
-7
lines changed

7 files changed

+41
-7
lines changed

ddtrace/contrib/pyramid/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
with require_modules(required_modules) as missing_modules:
2424
if not missing_modules:
25-
from .trace import trace_pyramid, trace_tween_factory
25+
from .trace import trace_pyramid, trace_tween_factory, includeme
2626
from .patch import patch
2727

2828
__all__ = [
2929
'patch',
3030
'trace_pyramid',
3131
'trace_tween_factory',
32+
'includeme',
3233
]

ddtrace/contrib/pyramid/patch.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ def traced_init(wrapped, instance, args, kwargs):
2929
settings.update(trace_settings)
3030
kwargs['settings'] = settings
3131

32-
# Commit actions immediately after they are configured so as to
33-
# skip conflict resolution when adding our tween
34-
kwargs['autocommit'] = True
35-
3632
# `caller_package` works by walking a fixed amount of frames up the stack
3733
# to find the calling package. So if we let the original `__init__`
3834
# function call it, our wrapper will mess things up.

ddtrace/contrib/pyramid/trace.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111

1212
def trace_pyramid(config):
13+
config.include('ddtrace.contrib.pyramid')
14+
15+
def includeme(config):
1316
config.add_tween('ddtrace.contrib.pyramid:trace_tween_factory')
1417
# ensure we only patch the renderer once.
1518
if not isinstance(pyramid.renderers.RendererHelper.render, wrapt.ObjectProxy):

tests/contrib/pyramid/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .test_pyramid_autopatch import _include_me
2+
3+
__all__ = ['_include_me']

tests/contrib/pyramid/test_pyramid.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ def json(request):
159159
config.add_view(json, route_name='json', renderer='json')
160160
return config.make_wsgi_app()
161161

162+
def includeme(config):
163+
pass
164+
165+
def test_include():
166+
""" Test that includes do not create conflicts """
167+
from ...test_tracer import get_dummy_tracer
168+
from ...util import override_global_tracer
169+
tracer = get_dummy_tracer()
170+
with override_global_tracer(tracer):
171+
config = Configurator(settings={'pyramid.includes': 'tests.contrib.pyramid.test_pyramid'})
172+
trace_pyramid(config)
173+
app = webtest.TestApp(config.make_wsgi_app())
174+
app.get('/', status=404)
175+
spans = tracer.writer.pop()
176+
assert spans
177+
eq_(len(spans), 1)
162178

163179
def _get_test_app(service=None):
164180
""" return a webtest'able version of our test app. """

tests/contrib/pyramid/test_pyramid_autopatch.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from nose.tools import eq_
77
from pyramid.config import Configurator
88
from pyramid.httpexceptions import HTTPInternalServerError
9+
910
# 3p
1011
from pyramid.response import Response
1112
from pyramid.view import view_config
@@ -24,7 +25,6 @@ def test_config_include():
2425
config = Configurator()
2526
config.include('._include_me')
2627

27-
2828
def test_200():
2929
app, tracer = _get_test_app(service='foobar')
3030
res = app.get('/', status=200)
@@ -128,6 +128,21 @@ def test_json():
128128
eq_(s.error, 0)
129129
eq_(s.span_type, 'template')
130130

131+
def includeme(config):
132+
pass
133+
134+
def test_include():
135+
""" Test that includes do not create conflicts """
136+
from ...test_tracer import get_dummy_tracer
137+
from ...util import override_global_tracer
138+
tracer = get_dummy_tracer()
139+
with override_global_tracer(tracer):
140+
config = Configurator(settings={'pyramid.includes': 'tests.contrib.pyramid.test_pyramid_autopatch'})
141+
app = webtest.TestApp(config.make_wsgi_app())
142+
app.get('/', status=404)
143+
spans = tracer.writer.pop()
144+
assert spans
145+
eq_(len(spans), 1)
131146

132147
def _get_app(service=None, tracer=None):
133148
""" return a pyramid wsgi app with various urls. """

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ commands =
209209
# integration tests
210210
integration: nosetests {posargs} tests/test_integration.py
211211
# run all tests for the release jobs except the ones with a different test runner
212-
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|aiobotocore|aiopg|gevent|falcon|flask_autopatch|bottle|pylons).*" tests/contrib
212+
contrib: nosetests {posargs} --exclude=".*(django|asyncio|aiohttp|aiobotocore|aiopg|gevent|falcon|flask_autopatch|bottle|pylons|pyramid).*" tests/contrib
213213
asyncio: nosetests {posargs} tests/contrib/asyncio
214214
aiohttp{12,13,20,21,22}-aiohttp_jinja{012,013}: nosetests {posargs} tests/contrib/aiohttp
215215
tornado{40,41,42,43,44}: nosetests {posargs} tests/contrib/tornado

0 commit comments

Comments
 (0)