Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FastraceEvent should not hardcode layout #46

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix
  • Loading branch information
andylokandy committed Aug 14, 2024
commit 534715b24810f1a94930eccc41337cc29b63059d
15 changes: 12 additions & 3 deletions src/append/fastrace.rs
Original file line number Diff line number Diff line change
@@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::borrow::Cow;

use jiff::Zoned;
use log::Record;

use crate::append::Append;
use crate::layout::collect_kvs;
use crate::layout::KvDisplay;

/// An appender that adds log records to fastrace as an event associated to the current span.
#[derive(Default, Debug, Clone)]
@@ -27,8 +28,16 @@ impl Append for FastraceEvent {
fn append(&self, record: &Record) -> anyhow::Result<()> {
let message = format!("{}", record.args());
fastrace::Event::add_to_local_parent(message, || {
[("level", record.level()), ("timestamp", Zoned::now())]
.chain(collect_kvs(record.key_values()))
[
(Cow::from("level"), Cow::from(record.level().as_str())),
(Cow::from("timestamp"), Cow::from(Zoned::now().to_string())),
]
.into_iter()
.chain(
collect_kvs(record.key_values())
.into_iter()
.map(|(k, v)| (Cow::from(k), Cow::from(v))),
)
});
Ok(())
}