-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (42 loc) · 1.28 KB
/
main.py
File metadata and controls
54 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import tornado
import tornado.ioloop
import tornado.web
from tornado.httpserver import HTTPServer
from tornado_elastic import ApiElasticHandlerAPM, TornadoApm
class MainTest1(ApiElasticHandlerAPM):
def get(self, *args, **kwargs):
self.write({'status': 'ok'})
self.finish()
class MainTest2(ApiElasticHandlerAPM):
def get(self):
raise Exception("Value Error")
def post(self):
try:
raise Exception("erro message")
except Exception as error:
# This error(Personalized) captured an send elastic
self.capture_message("personalized error test")
self.set_status(500)
self.write("Internal Server Error")
self.finish()
def make_app():
settings = {
'ELASTIC_APM':
{
"SERVICE_NAME": "Teste tornado",
"SECRET_TOKEN": "",
"Debug": False},
"compress_response": True,
}
application = tornado.web.Application([
(r"/", MainTest1),
(r"/error", MainTest2),
], **settings)
TornadoApm(application)
return application
if __name__ == "__main__":
app = make_app()
server = HTTPServer(app)
server.bind(8888)
server.start(1)
tornado.ioloop.IOLoop.current().start()