Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .riot/requirements/1099f43.txt

This file was deleted.

22 changes: 0 additions & 22 deletions .riot/requirements/116a9e0.txt

This file was deleted.

24 changes: 0 additions & 24 deletions .riot/requirements/17298d6.txt

This file was deleted.

20 changes: 0 additions & 20 deletions .riot/requirements/18f2a74.txt

This file was deleted.

22 changes: 0 additions & 22 deletions .riot/requirements/1d03e99.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate --resolver=backtracking .riot/requirements/aaa8f63.in
# pip-compile --allow-unsafe --no-annotate .riot/requirements/1da9e5b.in
#
attrs==25.3.0
coverage[toml]==7.8.2
attrs==25.4.0
coverage[toml]==7.10.7
exceptiongroup==1.3.0
hypothesis==6.45.0
importlib-metadata==8.7.0
Expand All @@ -15,11 +15,11 @@ opentracing==2.4.0
packaging==25.0
pluggy==1.6.0
pytest==8.0.0
pytest-cov==6.1.1
pytest-mock==3.14.1
pytest-randomly==3.16.0
pytest-cov==7.0.0
pytest-mock==3.15.1
pytest-randomly==4.0.1
sortedcontainers==2.4.0
tomli==2.2.1
tornado==6.0.4
typing-extensions==4.14.0
tomli==2.3.0
tornado==6.1
typing-extensions==4.15.0
zipp==3.23.0
24 changes: 0 additions & 24 deletions .riot/requirements/2249718.txt

This file was deleted.

2 changes: 1 addition & 1 deletion ddtrace/contrib/integration_registry/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ integrations:
- tornado
tested_versions_by_dependency:
tornado:
min: 6.0.4
min: "6.1"
max: 6.5.1

- integration_name: unittest
Expand Down
99 changes: 99 additions & 0 deletions ddtrace/contrib/internal/tornado/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
r"""
The Tornado integration traces all ``RequestHandler`` defined in a Tornado web application.
Auto instrumentation is available using the ``patch`` function that **must be called before**
importing the tornado library.

This integration supports Tornado >=6.1, which is asyncio-based. The integration properly
handles async/await coroutines and functions that return Futures, ensuring accurate span
durations and correct context propagation.

The following is an example::

# patch before importing tornado and concurrent.futures
import asyncio
import tornado.web
import tornado.httpserver

class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")

async def main():
app = tornado.web.Application([
(r"/", MainHandler),
])
server = tornado.httpserver.HTTPServer(app)
server.listen(8888)

# Let the asyncio loop run forever
await asyncio.Event().wait()

if __name__ == "__main__":
asyncio.run(main())

When any type of ``RequestHandler`` is hit, a request root span is automatically created. If
you want to trace more parts of your application, you can use the ``wrap()`` decorator and
the ``trace()`` method as usual::

class MainHandler(tornado.web.RequestHandler):
async def get(self):
await self.notify()
await self.blocking_method()
with tracer.trace('tornado.before_write') as span:
# trace more work in the handler

@tracer.wrap('tornado.executor_handler')
@tornado.concurrent.run_on_executor
def blocking_method(self):
# do something expensive

@tracer.wrap('tornado.notify', service='tornado-notification')
async def notify(self):
# do something

If you are overriding the ``on_finish`` or ``log_exception`` methods on a
``RequestHandler``, you will need to call the super method to ensure the
tracer's patched methods are called::

class MainHandler(tornado.web.RequestHandler):
async def get(self):
self.write("Hello, world")

def on_finish(self):
super(MainHandler, self).on_finish()
# do other clean-up

def log_exception(self, typ, value, tb):
super(MainHandler, self).log_exception(typ, value, tb)
# do other logging

Tornado settings can be used to change some tracing configuration, like::

settings = {
'datadog_trace': {
'default_service': 'my-tornado-app',
'tags': {'env': 'production'},
'distributed_tracing': False,
},
}

app = tornado.web.Application([
(r'/', MainHandler),
], **settings)

The available settings are:

* ``default_service`` (default: `tornado-web`): set the service name used by the tracer. Usually
this configuration must be updated with a meaningful name. Can also be configured via the
``DD_SERVICE`` environment variable.
* ``tags`` (default: `{}`): set global tags that should be applied to all spans.
* ``enabled`` (default: `True`): define if the tracer is enabled or not. If set to `false`, the
code is still instrumented but no spans are sent to the APM agent.
* ``distributed_tracing`` (default: `None`): enable distributed tracing if this is called
remotely from an instrumented application. Overrides the integration config which is configured via the
``DD_TORNADO_DISTRIBUTED_TRACING`` environment variable.
We suggest to enable it only for internal services where headers are under your control.
* ``agent_hostname`` (default: `localhost`): define the hostname of the APM agent.
* ``agent_port`` (default: `8126`): define the port of the APM agent.
* ``settings`` (default: ``{}``): Tracer extra settings used to change, for instance, the filtering behavior.
"""
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/tornado/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_version():


def _supported_versions() -> Dict[str, str]:
return {"tornado": ">=6.0.0"}
return {"tornado": ">=6.1"}


def patch():
Expand Down
Loading
Loading