tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.14k stars 671 forks source link

info_span!/error_span!/warn_span! macros accept constants for field names, but `#[instrument(fields(...))]` seemingly doesnt #2969

Closed merc1031 closed 1 month ago

merc1031 commented 1 month ago

Bug Report

Version

cargo tree | grep tracing
│   │   └── tracing v0.1.40
│   │       ├── tracing-attributes v0.1.27 (proc-macro)
│   │       └── tracing-core v0.1.32
│   │   │   │   └── tracing v0.1.40 (*)
│   │   │   └── tracing v0.1.40 (*)
│   │   │   └── tracing v0.1.40 (*)
│   │   └── tracing v0.1.40 (*)
│   └── tracing v0.1.40 (*)
├── axum-tracing-opentelemetry v0.18.0
│   ├── tracing v0.1.40 (*)
│   ├── tracing-opentelemetry v0.23.0
│   │   ├── tracing v0.1.40 (*)
│   │   ├── tracing-core v0.1.32 (*)
│   │   ├── tracing-log v0.2.0
│   │   │   └── tracing-core v0.1.32 (*)
│   │   └── tracing-subscriber v0.3.18
│   │       ├── tracing v0.1.40 (*)
│   │       ├── tracing-core v0.1.32 (*)
│   │       ├── tracing-log v0.2.0 (*)
│   │       ├── tracing-serde v0.1.3
│   │       │   ├── tracing-core v0.1.32 (*)
│   └── tracing-opentelemetry-instrumentation-sdk v0.18.0
│       ├── tracing v0.1.40 (*)
│       └── tracing-opentelemetry v0.23.0 (*)
│   │   │   └── tracing v0.1.40 (*)
│   │   │   ├── tracing v0.1.40 (*)
│   │   ├── tracing v0.1.40 (*)
│   ├── tracing v0.1.40 (*)
│       ├── tracing v0.1.40 (*)
│   │   │   ├── tracing v0.1.40 (*)
│   │   │   └── tracing v0.1.40 (*)
│   ├── tracing v0.1.40 (*)
│   ├── tracing-core v0.1.32 (*)
│   ├── tracing-ecs v0.4.0
│   │   ├── tracing v0.1.40 (*)
│   │   ├── tracing-core v0.1.32 (*)
│   │   ├── tracing-log v0.2.0 (*)
│   │   └── tracing-subscriber v0.3.18 (*)
│   ├── tracing-elastic-apm v3.2.3 (https://github.com/merc1031/tracing-elastic-apm.git?rev=bd8cc1f9de82915c888bfd33460dc2a9e766d902#bd8cc1f9)
│   │   ├── tracing v0.1.40 (*)
│   │   ├── tracing-subscriber v0.3.18 (*)
│   ├── tracing-subscriber v0.3.18 (*)
├── tracing v0.1.40 (*)
├── tracing-core v0.1.32 (*)
├── tracing-ecs v0.4.0 (*)
├── tracing-elastic-apm v3.2.3 (https://github.com/merc1031/tracing-elastic-apm.git?rev=bd8cc1f9de82915c888bfd33460dc2a9e766d902#bd8cc1f9) (*)
├── tracing-subscriber v0.3.18 (*)

Platform

uname -a                  
Linux lloucas-ThinkPad-T15-Gen-2i 6.2.0-39-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 14 14:18:00 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Description

I expected to be able to use a constant in the fields portion of the instrument macro.

I wrote the following expecting it to work like info_span!({OUTCOME} = "success"); (which does work)

pub const OUTCOME: &str = "outcome";

#[instrument(fields({OUTCOME} = "success"))]
fn name() {

However it doesnt compile. Am I misunderstanding?

davidbarsky commented 1 month ago

This was a missing feature and fixed by #2941.