express-tracer
Express-trace allows you to follow and inspect the
behaviour of your controllers through the response object. It requires that
you instrument your application with tracers. Then you can simply call a
trace
method on your response object each time you want to record something.
Usage
Install it in your project
npm install express-tracer
To add tracing helpers to express, run this module on your express app. Then, configure your tracers at the application level. You're done! Now, each time you want to trace something, call the dedicated function on the response object.
var express = var expressTrace = var debug = 'trace:response' var app = app app
Contributing
To discuss anything on this project, open an issue.
Of course, any code contribution is welcome! To propose your patch make a pull request on the master branch and make sure the Travis tests succeed. If you can't manage to make the tests green, don't worry we'll figure out a way to merge your changes!
Contributor list
- Frank Rousseau
Documentation
API
app.instrument(tracer)
Add a tracer to the application object. This tracer will be activated each time
the trace
method of a response is called.
A tracer is a function which takes an options object as argument. It has the following field:
res
: Response that fired the tracing.req
: Request related to the response that fired the tracing.app
: Application object.event
: String sent by the response to name the event.date
: Date when the tracing occured.args
: Additional arguments provided by the tracing call.
For example:
app;
res.trace(event, [parameters])
Fire all tracers instrumented at the application level.
Optional parameters:
event
, name of the event to send to tracers.parameters
, additional parameters to send to tracers.
app;
Use cases
Example 1: Time interval
In some cases you, may want to capture time spent on a specific request. Here is a way to do it through tracing.
var express = ;var debug = 'trace:response'; var app = ;var responseTime = {}; app app; app
Example 2: Send information to dtrace.
Dtrace is a common tool for tracing. It generates probes that will listen and report any event targeted to it. You can simply reach the probe via the trace function.
var express = ;var dtrace = ; var app = ; var dtp = dtrace;var p1 = dtp;var p2 = dtp;dtp; app; app app;
Example 3: Send information to chrome tracer.
You may want to use the chrome tracer to analyze only some response behaviour.
var express = ;var app = ; var events = ; app app process app;