Skip to content

Feature request: include meta data with trace.reportError #135

Open
@devilleweppenaar

Description

@devilleweppenaar

We use a custom winston transport to log errors to Trace (see below).

reportError only supports passing instances of Error, so we pass on the error if we have one, or wrap our custom message in an error if we only have a message.

Winston supports the concept of meta data, which it then includes in the log entry as a string. We use this to include extra context with the log entry.

It would be awesome if Trace could do the same.

Custom winston transport:

const winston = require('winston');

class TraceLogger extends winston.Transport {
	constructor(options) {
		super(options);

		this.name = 'traceLogger';
		this.level = 'error'; // only log errors to trace

		this.trace = (options && options.trace) || require('@risingstack/trace');
	}

	log(level, msg, meta, callback) {
		let traceError;

		if (!meta && msg) {
			traceError = new Error(msg);
		} else if (meta instanceof Error) {
			traceError = meta;
		}

		if (traceError) {
			this.trace.reportError('winston_error', traceError);
		}

		callback(null, true);
	}
}

winston.transports.TraceLogger = TraceLogger;
module.exports = TraceLogger;

As you can see from the code snippet, we only use winston meta when it is of type Error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions