Skip to content

Commit 42d9b0c

Browse files
authored
Tornado: Don't import modules if not installed (#152)
* Avoid calling tornado if not installed * Skip client tests until they are made deterministic * Pass CL args through to nose * Assure Tornado tracer is init before instrumentation
1 parent 0a4983f commit 42d9b0c

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

instana/instrumentation/tornado/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import functools
66

77
from ...log import logger
8-
from ...singletons import agent, tornado_tracer
8+
from ...singletons import agent, setup_tornado_tracer, tornado_tracer
99
from ...util import strip_secrets
1010

1111
from distutils.version import LooseVersion
1212

1313
try:
1414
import tornado
1515

16+
setup_tornado_tracer()
17+
1618
# Tornado >=6.0 switched to contextvars for context management. This requires changes to the opentracing
1719
# scope managers which we will tackle soon.
1820
# Limit Tornado version for the time being.

instana/instrumentation/tornado/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from __future__ import absolute_import
22

33
import opentracing
4-
from opentracing.scope_managers.tornado import tracer_stack_context
54
import wrapt
65

76
from ...log import logger
8-
from ...singletons import agent, tornado_tracer
7+
from ...singletons import agent, setup_tornado_tracer, tornado_tracer
98
from ...util import strip_secrets
109

1110
from distutils.version import LooseVersion
1211

1312
try:
1413
import tornado
14+
from opentracing.scope_managers.tornado import tracer_stack_context
15+
16+
setup_tornado_tracer()
1517

1618
# Tornado >=6.0 switched to contextvars for context management. This requires changes to the opentracing
1719
# scope managers which we will tackle soon.

instana/singletons.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@
2525
from opentracing.scope_managers.asyncio import AsyncioScopeManager
2626
async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager())
2727

28-
from opentracing.scope_managers.tornado import TornadoScopeManager
29-
tornado_tracer = InstanaTracer(scope_manager=TornadoScopeManager())
28+
29+
# Mock the tornado tracer until tornado is detected and instrumented first
30+
tornado_tracer = tracer
31+
32+
33+
def setup_tornado_tracer():
34+
global tornado_tracer
35+
from opentracing.scope_managers.tornado import TornadoScopeManager
36+
tornado_tracer = InstanaTracer(scope_manager=TornadoScopeManager())
37+
3038

3139
# Set ourselves as the tracer.
3240
opentracing.tracer = tracer

runtests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
if (LooseVersion(sys.version) >= LooseVersion('3.7.0')):
1111
command_line.extend(['-e', 'sudsjurko'])
1212

13+
command_line.extend(sys.argv[1:])
14+
1315
print("Nose arguments: %s" % command_line)
1416
result = nose.main(argv=command_line)
1517

tests/test_tornado_client.py

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

1111
from .helpers import testenv
1212

13+
from nose.plugins.skip import SkipTest
14+
raise SkipTest("Non deterministic tests TBR")
15+
1316

1417
class TestTornadoClient(unittest.TestCase):
1518

@@ -37,6 +40,7 @@ async def test():
3740
assert isinstance(response, tornado.httpclient.HTTPResponse)
3841

3942
spans = self.recorder.queued_spans()
43+
4044
self.assertEqual(3, len(spans))
4145

4246
server_span = spans[0]

0 commit comments

Comments
 (0)