Skip to content

#[instrument(fields(...))] does not support field::Empty #1211

@nikclayton-dfinity

Description

@nikclayton-dfinity

Bug Report

Version

│   │   ├── tracing v0.1.15
│   │   │   ├── tracing-attributes v0.1.8
│   │   │   └── tracing-core v0.1.10
│   │   │       │   │   │   │   │   └── tracing v0.1.15 (*)
│   │   └── tracing v0.1.15 (*)
├── tracing v0.1.15 (*)
├── tracing-futures v0.2.4
│   └── tracing v0.1.15 (*)
├── tracing-opentelemetry v0.10.0
│   ├── tracing v0.1.15 (*)
│   ├── tracing-core v0.1.10 (*)
│   ├── tracing-log v0.1.1
│   │   └── tracing-core v0.1.10 (*)
│   └── tracing-subscriber v0.2.9
│       ├── tracing-core v0.1.10 (*)
│       ├── tracing-log v0.1.1 (*)
│       └── tracing-serde v0.1.2
│           └── tracing-core v0.1.1

Platform

Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin

Description

Since you can't record a new field on a span after it's been created (per the docs) I wanted to pre-create some fields on the #[instrument(fields(...))].

The documentation doesn't suggest this is possible, but gives the example:

let span = trace_span!("my_span", greeting = "hello world", parting = field::Empty);

Given that, I figured that

#[instrument(fields(foo = tracing::field::Empty))]

would make sense.

Sadly, that results in

error: expected literal
   --> redacted/mod.rs:168:36
    |
168 | #[instrument(fields(foo = tracing::field::Empty), err, skip(registry_client, metrics))]
    |                           ^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions