Tracing for koa-trace using influxdb-udp.
var app = koa();
require('koa-trace')(app);
var traceInflux = require('koa-trace-influxdb');
app.instrument(traceInflux({
port: 4444,
host: '127.0.0.1'
}));
app.use(function* (next) {
// set an ID for every request.
// optionally, make this a request UUID
this.id = '1234';
// optionally set properties to add to all traces
this.traces = {
user_id: this.session.user_id.toString('hex')
};
// trace something
this.trace('start')
})
This will create a time series called trace.start
.
Thus, it tracks each event as a separate series.
You probably want to track the elapsed time.
app.use(function* (next) {
var start = Date.now();
yield* next;
this.trace('response-time', {
elapsed: Date.now() - start
});
});
You may want to build your own helper for this.
host
port
prefix
- prefix to add to all the series, defaulting totrace.
. If you don't want any prefixes, set it as''
.
- The trace arguments must only be a single object, if anything at all.
- UDP is used underneath, so you may lose events. There is no error reporting for logging these.