最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Logging OTEL spans to journald using tracing-journald crate in Rust - Stack Overflow

programmeradmin1浏览0评论

I'm using Rust tracing-journald and tracing crate for logging to journalctl in my application. The log events render correctly to journalctl but spans do not appear to journald by default and are only available in verbose mode journalctl -t test-service -n 2 -f -o verbose mode.

ri 2025-01-31 00:41:57.462458 UTC [s=78f20397c39b44be8df7e5034ecc9ab2;i=43a3cb;b=55a752e1c04a416ba07b4942ee50f0e1;m=27cc1cc3c2;t=62cf5cf5736e5;x=41ec2f15bdf0db45]
    _TRANSPORT=journal
    _UID=0
    .
    .
    CODE_LINE=73
    PRIORITY=3
    SPAN_NAME=my_span
    SPAN_TARGET=log
    SPAN_CODE_FILE=src/main.rs
    SPAN_CODE_LINE=69
    MESSAGE=17 My error message

I would prefer them to be formatted as JSON and appear as log to journalctl directly without verbose argument.

{"timestamp":"2025-01-31T01:42:56.385502Z","level":"INFO","fields":{"message":"close","time.busy":"6.37ms","time.idle":"2.76ms"},"target":"zbus::handshake","span":{"command":"Auth(Some(External), Some([48]))","name":"write_command"}}

I added a custom formatting layer before journald layer but it it doesn't work and spans appear on stdout instead of journald

// pseudo code
        let journald_layer = tracing_journald::layer()
            .map_err(TelemetryStackBuildError::JournalDError)?
            .with_syslog_identifier(service_name.to_owned());

        let span_formatter = fmt::layer()
                    .with_span_events(FmtSpan::CLOSE)
                    .flatten_event(false)
                    .with_span_list(false);

        let subscriber = tracing_subscriber::registry()
            .with(journald_layer)
            .with(logcontrol_layer)
            .with(span_formatter);

Please suggest how can I achieve log spans directly to journalctl?

发布评论

评论列表(0)

  1. 暂无评论