Skip to content

Commit

Permalink
minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettg committed Mar 15, 2012
1 parent 398567e commit b871495
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,39 @@ For production use, you'll need to set the collection host and port:

ziggy.configure("127.0.0.1", 3514)

### Tornado Hooks

Ziggy comes out of the box with support for Tornado web server. This is
particularly challenging since one of the goals for ziggy is to, like the
logging module, have globally accessible contexts so you don't have to pass
anything around to have access to all the heirarchical goodness.

Since you'll likely want to have a context per web request, it's difficult o
work around tornado's async machinery to make that work well.
Fear not, batteries included: `ziggy.tornado_utils`

The most straightfoward way to integrate ziggy into a tornado application requires two things:

1. Allow ziggy to monkey patch async tooling (tornado.gen primarily)
1. Use or re-implement the provided base request handler `ziggy.tornado_utils.SampleRequestHandler`

To install the monkey patching, add the line:

ziggy.tornado_utils.install()

This must be executed BEFORE any of your RequestHandlers are imported.

This is required if you are using @asynchronous and @gen.engine. If you are
manually managing callbacks (which you probably shouldn't be), you'll need
manually recall the ziggy context with `self.ziggy.start()`

See `tests/tornado_app.py` for an example of all this.

If you have your own base request handlers you'll likely want to reimplement
based on the one provided rather than trying to use inheritance. This will also
make it really clear what you are including in your top-level event and allow
you to name it whatever you want.


Event Collection
-----------------
Expand Down
1 change: 1 addition & 0 deletions ziggy/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def stop(self):
_remove_context(self)

def done(self):
self.stop() # Just be sure
if self.enabled and _recorder_function:
_recorder_function(self)

Expand Down
2 changes: 1 addition & 1 deletion ziggy/tornado_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def finish(self):
return res

_execute = wrap_execute('request')(tornado.web.RequestHandler._execute)
finish = wrap_finish(tornado.web.RequestHandler.finish)
finish = wrap_finish(finish)


# We need a custom version of this decorator so that we can pass in our ziggy
Expand Down

0 comments on commit b871495

Please sign in to comment.