connect-flake

0.1.2 • Public • Published
 _______  _______  _        _        _______  _______ _________     _______  _        _______  _        _______ 
(  ____ \(  ___  )( (    /|( (    /|(  ____ \(  ____ \\__   __/    (  ____ \( \      (  ___  )| \    /\(  ____ \
| (    \/| (   ) ||  \  ( ||  \  ( || (    \/| (    \/   ) (       | (    \/| (      | (   ) ||  \  / /| (    \/
| |      | |   | ||   \ | ||   \ | || (__    | |         | | _____ | (__    | |      | (___) ||  (_/ / | (__    
| |      | |   | || (\ \) || (\ \) ||  __)   | |         | |(_____)|  __)   | |      |  ___  ||   _ (  |  __)   
| |      | |   | || | \   || | \   || (      | |         | |       | (      | |      | (   ) ||  ( \ \ | (      
| (____/\| (___) || )  \  || )  \  || (____/\| (____/\   | |       | )      | (____/\| )   ( ||  /  \ \| (____/\
(_______/(_______)|/    )_)|/    )_)(_______/(_______/   )_(       |/       (_______/|/     \||_/    \/(_______/
                                                                                                                

Connect middleware which assigns a Flake ID to every request.

Usage

$ npm install connect-flake

// load connect-flake
var flake = require('connect-flake');

// use the middleware which sets req.flake
app.use(flake('eth0'));

// add a dynamic helper so the view can see #{req.flake}
app.all(function(req, res, next) {
    res.locals.flake = req.flake;
});

Uses of a Flake ID for each Request

Log the Flake ID in your log files to help you figure out what is going on:

// in your logging
myLogger(req.flake + ' : Something bad happened.');

Tell the user the Flake ID for the failed request, and get them to use it as a reference when they report the issue to you (note: this is a Jade template):

p Your reference is '#{flake}'.

Send yourself the Flake ID of the (failed) request so you can find it quicker:

To: me@example.com
From: noreply@example.com
Subject: 50x error

A web request (013c7990a044-0000-08ff-00027298bef9) failed.

You may even store the requests and/or errors in your database:

sql> SELECT * FROM request WHERE id = '013c7990a044-0000-08ff-00027298bef9';

And there are many other uses too.

Motivation

When you have so many requests, it's hard to grep (search, find, etc) the logs to figure out what went wrong when you get a bad request. connect-flake to the rescue.

Add this module as connect middleware and each request has a Flake ID. When you log anything, make sure you log this Flake ID with it. When you get an error in your application, make sure you use the Flake ID when reporting it (whether that is logged, email or whatever). Also, tell the user (in their 50x page) what the Flake ID is when something goes wrong, so that they can tell you to sort things out.

By doing all this, you can easily find the request and what really happened to it. You may keep detailed or light logs, but either way having a direct reference to the request will really help.

Note

This package was inspired by my other package connect-uuid which was inspired by https://groups.google.com/forum/#!msg/nodejs/2NcBM7eXD94/FVm-jL91cekJ

Author

Written by Andrew Chilton - Blog - Twitter.

License

(Ends)

Dependents (0)

Package Sidebar

Install

npm i connect-flake

Weekly Downloads

2

Version

0.1.2

License

none

Last publish

Collaborators

  • chilts