'Is there a way to set custom field globally for tracing_subscriber without much effort?
I use tracing
and tracing_subscriber
rust libs 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
?
Solution 1:[1]
You can use spans
to instrument your code and add metadata as needed for all subsecuent logging:
span!(Level::INFO, "my_span", name= "instance1");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Netwave |