From c14935b68140b2fa4d18065cb6812f0a6455f8be Mon Sep 17 00:00:00 2001 From: Kirill Ivanov Date: Thu, 15 Aug 2024 15:30:52 +0300 Subject: [PATCH] fix fields not preserved --- libs/blockscout-service-launcher/Cargo.toml | 2 +- .../src/tracing/request_id_layer.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/blockscout-service-launcher/Cargo.toml b/libs/blockscout-service-launcher/Cargo.toml index cd0bb9209..f7ba6f2d2 100644 --- a/libs/blockscout-service-launcher/Cargo.toml +++ b/libs/blockscout-service-launcher/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blockscout-service-launcher" -version = "0.13.0" +version = "0.13.1" description = "Allows to launch blazingly fast blockscout rust services" license = "MIT" repository = "https://github.com/blockscout/blockscout-rs" diff --git a/libs/blockscout-service-launcher/src/tracing/request_id_layer.rs b/libs/blockscout-service-launcher/src/tracing/request_id_layer.rs index fc1d0f36c..cf1c4955c 100644 --- a/libs/blockscout-service-launcher/src/tracing/request_id_layer.rs +++ b/libs/blockscout-service-launcher/src/tracing/request_id_layer.rs @@ -1,7 +1,7 @@ use std::{fmt::Debug, str::FromStr}; use tracing::{field::Field, span::Attributes, Id, Subscriber}; use tracing_subscriber::{ - fmt::{format::JsonFields, FormattedFields}, + fmt::{format::JsonFields, FormatFields, FormattedFields}, layer::Context, registry::LookupSpan, Layer, @@ -29,7 +29,18 @@ impl LookupSpan<'lookup>> Layer for RequestIdSto .get_mut::>() .is_none() { - extensions.insert(FormattedFields::::new("{}".to_string())); + let mut fields = FormattedFields::::new(String::new()); + if JsonFields::new() + .format_fields(fields.as_writer(), attrs) + .is_ok() + { + extensions.insert(fields); + } else { + eprintln!( + "[tracing-subscriber] Unable to format the following event, ignoring: {:?}", + attrs + ); + } } let data = extensions.get_mut::>().unwrap(); if let Some(request_id) = request_id {