@@ -75,6 +75,36 @@ def get(self):
7575 return app
7676
7777
78+ @pytest .fixture
79+ def app_no_client ():
80+ class HelloHandler (tornado .web .RequestHandler ):
81+ def get (self ):
82+ with async_capture_span ("test" ):
83+ pass
84+ return self .write ("Hello, world" )
85+
86+ post = get
87+
88+ class RenderHandler (tornado .web .RequestHandler ):
89+ def get (self ):
90+ with async_capture_span ("test" ):
91+ pass
92+ items = ["Item 1" , "Item 2" , "Item 3" ]
93+ return self .render ("test.html" , title = "Testing so hard" , items = items )
94+
95+ class BoomHandler (tornado .web .RequestHandler ):
96+ def get (self ):
97+ raise tornado .web .HTTPError ()
98+
99+ post = get
100+
101+ app = tornado .web .Application (
102+ [(r"/" , HelloHandler ), (r"/boom" , BoomHandler ), (r"/render" , RenderHandler )],
103+ template_path = os .path .join (os .path .dirname (__file__ ), "templates" ),
104+ )
105+ return app
106+
107+
78108@pytest .mark .gen_test
79109async def test_get (app , base_url , http_client ):
80110 elasticapm_client = app .elasticapm_client
@@ -196,3 +226,15 @@ async def test_capture_headers_body_is_dynamic(app, base_url, http_client):
196226 assert transactions [2 ]["context" ]["request" ]["body" ] == "[REDACTED]"
197227 assert "headers" not in errors [1 ]["context" ]["request" ]
198228 assert errors [1 ]["context" ]["request" ]["body" ] == "[REDACTED]"
229+
230+
231+ @pytest .mark .gen_test
232+ async def test_no_elasticapm_client (app_no_client , base_url , http_client , elasticapm_client ):
233+ """
234+ Need to make sure instrumentation works even when tornado is not
235+ explicitly using the agent
236+ """
237+ elasticapm_client .begin_transaction ("test" )
238+ response = await http_client .fetch (base_url )
239+ assert response .code == 200
240+ elasticapm_client .end_transaction ("test" )
0 commit comments