I use tracing
and tracing_subscriber
Rust libraries to write logs in the app and I would like to pass custom field globally for all log messages to separate different instances of the app in a log db. For example, I would like to put instance id in all log messages of that instance.
As such,
{"timestamp": "...", "level": "INFO", "name": "instance1", "msg": "..."}
{"timestamp": "...", "level": "ERROR", "name": "instance1", "msg": "..."}
{"timestamp": "...", "level": "INFO", "name": "instance1", "msg": "..."}
Is there a way to implement this with standard tracing_subscriber
and not implementing my own Layer
?
You can use
spans
to instrument your code and add metadata as needed for all subsecuent logging: