refactor: include binary name in service field in log entries (#2077)

This commit is contained in:
Sanchith Hegde
2023-09-04 17:14:47 +05:30
committed by GitHub
parent e1cebd4179
commit 20d44acd20
10 changed files with 43 additions and 54 deletions

View File

@ -147,13 +147,14 @@ macro_rules! commit {
// };
// }
/// Service name deduced from name of the crate.
/// Service name deduced from name of the binary.
/// This macro must be called within binaries only.
///
/// Example: `router`.
#[macro_export]
macro_rules! service_name {
() => {
env!("CARGO_CRATE_NAME")
env!("CARGO_BIN_NAME")
};
}

View File

@ -32,7 +32,7 @@ pub struct TelemetryGuard {
/// current cargo workspace are automatically considered for verbose logging.
pub fn setup(
config: &config::Log,
service_name: &'static str,
service_name: &str,
crates_to_filter: impl AsRef<[&'static str]>,
) -> TelemetryGuard {
let mut guards = Vec::new();
@ -133,7 +133,7 @@ fn get_opentelemetry_exporter(config: &config::LogTelemetry) -> TonicExporterBui
fn setup_tracing_pipeline(
config: &config::LogTelemetry,
service_name: &'static str,
service_name: &str,
) -> Option<tracing_opentelemetry::OpenTelemetryLayer<tracing_subscriber::Registry, trace::Tracer>>
{
global::set_text_map_propagator(TraceContextPropagator::new());
@ -144,7 +144,7 @@ fn setup_tracing_pipeline(
))
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
service_name,
service_name.to_owned(),
)]));
if config.use_xray_generator {
trace_config = trace_config.with_id_generator(trace::XrayIdGenerator::default());