0.0.6 • Published 7 years ago

inscriber v0.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

Inscriber

ES6 Basic Trace and Span Tracker. Use it to add some structure to your server logs.

Trace and Span Tracker

0.0.4 Basic Release

Implementation

const inscriber = require('inscriber');
const trace = new inscriber.trace(id, name);
const span = new inscriber.span(name, trace, traceId, tags);

Log Class

  • info(message)
  • success(message)
  • error(message)

Trace Class (extends Log)

  • init()
  • recieved()
  • completed()
  • failed()
  • inherited()
  • returnedg()

Span Class (extends Log)

  • init()
  • completed()
  • failed()

Simple example

Talking between two Express servers - in this example local testing on port 3000 and 3090.

Assume the first server is for a Bot and the second for an API.

Send custom headers X-Trace and Trace-Parent-ID.

// Server one on localhost:3000
const inscriber = require('inscriber');

app.get('/log', (req, res) => {
	// Server one
	const trace = new Log.trace('id-reference', 'Log Routing');
	const spanOne = new Log.span('Bot /log route', trace.name, trace.id);

	trace.init();
	span.init()
		.info('Route accessed')
		.info('Attempting to contact API');

	axios.get('http://localhost:3090/apilog', {
			headers: {
				'X-Trace': trace.name,
				'Trace-Parent-ID': trace.id
			}
		})
		.then(data => {
			const spanTwo = new Log.span('Bot /log data returned', trace.name, trace.id);

			span.info('Route return')
				.completed();
			trace.completed();
			spanTwo.completed();

			res.send('Success');
		})
		.catch(err => {
			span.failed();
			trace.failed();
			res.send('err');
		});

});

// Server two on localhost:3090
const inscriber = require('inscriber');

app.get('/log', function(req, res) {
	const trace = new inscriber.trace(req.get('Trace-Parent-ID'), req.get('X-Trace'));
	trace.inherited()
		.info('Trace id and name recieved from other server');
	const span = new inscriber.span('API /log route', trace.name, trace.id);
	res.send('Server is healthy');

	span.completed();
	trace.returned();
});

OUTPUT

# Server One
::TRACE [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: TRACE_INIT (id-reference) Log Routing
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log route): SPAN_INIT Bot /log route
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log route): Route accessed
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log route): Attempting to contact GraphQL
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log route): Route return
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log route): SPAN_COMPLETED Bot /log route
::TRACE [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: TRACE_COMPLETED (id-reference) Log Routing
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (Bot /log data returned): SPAN_COMPLETED Bot /log data returned

# Server Two
::TRACE [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: TRACE_INHERITED (id-reference) Log Routing
::TRACE [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: Trace id and name recieved from other server
::SPAN [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: (API /log route): SPAN_COMPLETED API /log route
::TRACE [Log Routing] [Thu Jul 13 2017 17:00:29 GMT+1000 (AEST)]:: TRACE_RETURNED (id-reference) Log Routing
0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago