tracing-bunyan-formatter icon indicating copy to clipboard operation
tracing-bunyan-formatter copied to clipboard

Preventing certain fields of a span being logged with BunyanFormattingLayer

Open Bauxitedev opened this issue 3 years ago • 1 comments

Quick question, is it possible to configure BunyanFormattingLayer to prevent logging certain fields to the console?

My use case is as follows. I have a panic hook set up with color-eyre that gives me a fancy backtrace (with colors and stuff) whenever a panic occurs in my web app. I use tracing::error(error_report = %panic_report) to log the fancy backtrace generated by color-eyre to the BunyanFormattingLayer. The problem is, I want these logs to only appear in the context of an external observability solution, such as Jaeger, so not in the console.

So right now my panic logs in the console look like this: (without the newlines)

{
	"v": 0,
	"name": "<app name here>",
	"msg": "[REQUEST - EVENT] Lazy instance has previously been poisoned",
	"level": 50,
	"hostname": "<hostname here>",
	"pid": 34264,
	"time": "2022-07-17T11:32:18Z",
	"target": "panic_hook",
	"line": 20,
	"file": "<filename here>",
	"error_report": "<insert extremely long backtrace here>"
}

So the extremely long backtrace is polluting my logs.

My question is: is it possible to prevent the "error_report" field from appearing in the logs, while still having it available to external observability solutions?

Bauxitedev avatar Jul 19 '22 10:07 Bauxitedev

Yes, this is possible - we just need to skip those fields when serializing the event/span. If you'd like to work on a PR, I'm happy to review it.

LukeMathWalker avatar Jul 19 '22 14:07 LukeMathWalker