Tornado Support
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. The Elastic APM Python agent enables you to trace the execution of operations in your Python applications, sending performance metrics and errors to the Elastic APM Server. Availability This functionality is generally available and ready for production usage. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless Observability
Generally available
Stack
Generally available
APM Agent Python
Generally available
Incorporating Elastic APM into your Tornado project only requires a few easy steps.
Install the Elastic APM agent using pip:
$ pip install elastic-apm
or add elastic-apm to your project’s requirements.txt file.
To set up the agent, you need to initialize it with appropriate settings.
The settings are configured either via environment variables, the application’s settings, or as initialization arguments.
You can find a list of all available settings in the Configuration page.
To initialize the agent for your application using environment variables:
import tornado.web
from elasticapm.contrib.tornado import ElasticAPM
app = tornado.web.Application()
apm = ElasticAPM(app)
To configure the agent using ELASTIC_APM in your application’s settings:
import tornado.web
from elasticapm.contrib.tornado import ElasticAPM
app = tornado.web.Application()
app.settings['ELASTIC_APM'] = {
'SERVICE_NAME': '<SERVICE-NAME>',
'SECRET_TOKEN': '<SECRET-TOKEN>',
}
apm = ElasticAPM(app)
Once you have configured the agent, it will automatically track transactions and capture uncaught exceptions within tornado.
Capture an arbitrary exception by calling capture_exception:
try:
1 / 0
except ZeroDivisionError:
apm.client.capture_exception()
Log a generic message with capture_message:
apm.client.capture_message('hello, world!')
If you’ve followed the instructions above, the agent has installed our instrumentation within the base RequestHandler class in tornado.web. This will measure response times, as well as detailed performance data for all supported technologies.
Due to the fact that asyncio drivers are usually separate from their synchronous counterparts, specific instrumentation is needed for all drivers. The support for asynchronous drivers is currently quite limited.
You can use the TRANSACTIONS_IGNORE_PATTERNS configuration option to ignore specific routes. The list given should be a list of regular expressions which are matched against the transaction name:
app.settings['ELASTIC_APM'] = {
# ...
'TRANSACTIONS_IGNORE_PATTERNS': ['^GET SecretHandler', 'MainHandler']
# ...
}
This would ignore any requests using the GET SecretHandler route and any requests containing MainHandler.
A list of supported tornado and Python versions can be found on our Supported Technologies page.
Elastic APM only supports asyncio when using Python 3.7+