小编Bos*_*Man的帖子

如何访问跟踪范围中字段的值?

我在项目中使用跟踪库,但有一件事我无法弄清楚:如何访问我的 中的值(我在创建它时在跨度中设置的值)Layer

我的图层看起来像这样:

impl<S> Layer<S> for CustomLayer where S: Subscriber {
    fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
        Interest::sometimes() //hardcoding so enabled() will be called everytime a span is created
    }

    fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
        if metadata.is_span() {
            // How do I access value of key here?
            if value == X {
                true
            } else if value == Y {
                false
            }
        }
        true // default
    }
}
Run Code Online (Sandbox Code Playgroud)

rust rust-tracing

6
推荐指数
1
解决办法
1931
查看次数

标签 统计

rust ×1

rust-tracing ×1