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

tracing: impl From<EnteredSpan> for Option<Id> #1325

Merged
merged 4 commits into from
Apr 28, 2021

Conversation

Folyd
Copy link
Contributor

@Folyd Folyd commented Mar 25, 2021

Motivation

The following code compiles failed:

use tracing;

fn main() {
    
    let span = tracing::info_span!("my_span").entered();
    tracing::info!(parent: &span, "test span");
}
   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Option<Id>: From<&EnteredSpan>` is not satisfied
  --> src/main.rs:6:5
   |
6  |     tracing::info!(parent: &span, "test span");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&EnteredSpan>` is not implemented for `Option<Id>`

Solution

  • impl<'a> From<&'a EnteredSpan> for Option<&'a Id>.
  • impl<'a> From<&'a EnteredSpan> for Option<Id>
  • Add id() method into EnteredSpan.

@Folyd Folyd requested review from davidbarsky, hawkw and a team as code owners March 25, 2021 09:50
@Folyd Folyd changed the title tracing: impl Into<Option<Id>> for &EnteredSpan tracing: impl From<EnteredSpan> for Option<Id> Mar 30, 2021
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you

@hawkw hawkw merged commit 822d844 into tokio-rs:master Apr 28, 2021
hawkw added a commit that referenced this pull request Apr 30, 2021
## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? If a new feature is being added, describe the intended
use case that feature fulfills.
-->

The following code compiles failed:
```rust
use tracing;

fn main() {

    let span = tracing::info_span!("my_span").entered();
    tracing::info!(parent: &span, "test span");
}
```

```log
   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Option<Id>: From<&EnteredSpan>` is not satisfied
  --> src/main.rs:6:5
   |
6  |     tracing::info!(parent: &span, "test span");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&EnteredSpan>` is not implemented for `Option<Id>`
```

## Solution

- `impl<'a> From<&'a EnteredSpan> for Option<&'a Id>`.
- `impl<'a> From<&'a EnteredSpan> for Option<Id>`
- Add `id()` method into `EnteredSpan`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw mentioned this pull request Apr 30, 2021
hawkw added a commit that referenced this pull request Apr 30, 2021
## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? If a new feature is being added, describe the intended
use case that feature fulfills.
-->

The following code compiles failed:
```rust
use tracing;

fn main() {

    let span = tracing::info_span!("my_span").entered();
    tracing::info!(parent: &span, "test span");
}
```

```log
   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Option<Id>: From<&EnteredSpan>` is not satisfied
  --> src/main.rs:6:5
   |
6  |     tracing::info!(parent: &span, "test span");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&EnteredSpan>` is not implemented for `Option<Id>`
```

## Solution

- `impl<'a> From<&'a EnteredSpan> for Option<&'a Id>`.
- `impl<'a> From<&'a EnteredSpan> for Option<Id>`
- Add `id()` method into `EnteredSpan`.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 30, 2021
# 0.1.26 (April 30, 2021)

### Fixed

- **attributes**: Compatibility between `#[instrument]` and `async-trait`
  v0.1.43 and newer ([#1228])
- Several documentation fixes ([#1305], [#1344])
### Added

- `Subscriber` impl for `Box<dyn Subscriber + Send + Sync + 'static>`
  ([#1358])
- `Subscriber` impl for `Arc<dyn Subscriber + Send + Sync + 'static>`
  ([#1374])
- Symmetric `From` impls for existing `Into` impls on `span::Current`,
  `Span`, and `Option<Id>` ([#1335], [#1338])
- `From<EnteredSpan>` implementation for `Option<Id>`, allowing
  `EnteredSpan` to be used in a `span!` macro's `parent:` field ([#1325])
- `Attributes::fields` accessor that returns the set of fields defined
  on a span's `Attributes` ([#1331])

Thanks to @Folyd, @nightmared, and new contributors @rmsc and @Fishrock123 for
contributing to this release!

[#1227]: #1228
[#1305]: #1305
[#1325]: #1325
[#1338]: #1338
[#1344]: #1344
[#1358]: #1358
[#1374]: #1374
[#1335]: #1335
[#1331]: #1331
hawkw added a commit that referenced this pull request Apr 30, 2021
# 0.1.26 (April 30, 2021)

### Fixed

- **attributes**: Compatibility between `#[instrument]` and `async-trait`
  v0.1.43 and newer ([#1228])
- Several documentation fixes ([#1305], [#1344])
### Added

- `Subscriber` impl for `Box<dyn Subscriber + Send + Sync + 'static>`
  ([#1358])
- `Subscriber` impl for `Arc<dyn Subscriber + Send + Sync + 'static>`
  ([#1374])
- Symmetric `From` impls for existing `Into` impls on `span::Current`,
  `Span`, and `Option<Id>` ([#1335], [#1338])
- `From<EnteredSpan>` implementation for `Option<Id>`, allowing
  `EnteredSpan` to be used in a `span!` macro's `parent:` field ([#1325])
- `Attributes::fields` accessor that returns the set of fields defined
  on a span's `Attributes` ([#1331])

Thanks to @Folyd, @nightmared, and new contributors @rmsc and @Fishrock123 for
contributing to this release!

[#1227]: #1228
[#1305]: #1305
[#1325]: #1325
[#1338]: #1338
[#1344]: #1344
[#1358]: #1358
[#1374]: #1374
[#1335]: #1335
[#1331]: #1331
@Folyd Folyd deleted the entered-span branch July 2, 2021 02:16
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.1.26 (April 30, 2021)

### Fixed

- **attributes**: Compatibility between `#[instrument]` and `async-trait`
  v0.1.43 and newer ([tokio-rs#1228])
- Several documentation fixes ([tokio-rs#1305], [tokio-rs#1344])
### Added

- `Subscriber` impl for `Box<dyn Subscriber + Send + Sync + 'static>`
  ([tokio-rs#1358])
- `Subscriber` impl for `Arc<dyn Subscriber + Send + Sync + 'static>`
  ([tokio-rs#1374])
- Symmetric `From` impls for existing `Into` impls on `span::Current`,
  `Span`, and `Option<Id>` ([tokio-rs#1335], [tokio-rs#1338])
- `From<EnteredSpan>` implementation for `Option<Id>`, allowing
  `EnteredSpan` to be used in a `span!` macro's `parent:` field ([tokio-rs#1325])
- `Attributes::fields` accessor that returns the set of fields defined
  on a span's `Attributes` ([tokio-rs#1331])

Thanks to @Folyd, @nightmared, and new contributors @rmsc and @Fishrock123 for
contributing to this release!

[tokio-rs#1227]: tokio-rs#1228
[tokio-rs#1305]: tokio-rs#1305
[tokio-rs#1325]: tokio-rs#1325
[tokio-rs#1338]: tokio-rs#1338
[tokio-rs#1344]: tokio-rs#1344
[tokio-rs#1358]: tokio-rs#1358
[tokio-rs#1374]: tokio-rs#1374
[tokio-rs#1335]: tokio-rs#1335
[tokio-rs#1331]: tokio-rs#1331
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

Successfully merging this pull request may close these issues.

2 participants