Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
merc1031 opened this issue May 14, 2024 · 3 comments

Comments

@merc1031
Copy link

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
Copy link
Member

This was a missing feature and fixed by #2941.

@nico-incubiq
Copy link

@davidbarsky the PR you linked is related to setting specific properties such as name and target using constants, I don't think the issue raised here is addressed at all, it's about the tracing fields, or at least the sample code above throws a compiler error, can you confirm?

error: expected ident
   --> src/test.rs:20:30
   |
20 | #[tracing::instrument(fields({OUTCOME} = "success"))]
   |                              ^

@nico-incubiq
Copy link

I'm going to implement that missing behaviour. For reference, the syntax for const fields in spans @merc1031 pointed out was implemented in #2617

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants