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

chore: Backports to v0.1.x #2298

Merged
merged 11 commits into from
Sep 19, 2022
Merged

chore: Backports to v0.1.x #2298

merged 11 commits into from
Sep 19, 2022

Conversation

davidbarsky
Copy link
Member

Some additional backports.

(Let's see if CI passes first—I suspect that it won't...)

@hawkw
Copy link
Member

hawkw commented Sep 8, 2022

looks like there are some surprising clippy warnings: https://github.com/tokio-rs/tracing/runs/8255803899?check_suite_focus=true

if those exist on the main branch as well, we should fix them separately...

@davidbarsky
Copy link
Member Author

looks like there are some surprising clippy warnings: https://github.com/tokio-rs/tracing/runs/8255803899?check_suite_focus=true

Yeah, they are. I"ll try taking a look tomorrow morning.

@hawkw
Copy link
Member

hawkw commented Sep 15, 2022

@davidbarsky any updates on this?

hawkw and others added 10 commits September 19, 2022 11:26
This fixes new Clippy lints introduced in the latest Rust version.

* chore: fix `clippy::borrow_deref_ref` lints
* chore: fix `clippy::partial_eq_without_eq` lint
`tracing-subscriber` has been on `0.3` for almost a year now.

I naively copied the versions from the README, and when trying to use
the library with the current versions of e.g. `tracing-opentelemetry`, I
ran into the same error message as seen in this issue:
#852

Co-authored-by: Bryan Garza <[email protected]>
## Motivation

Return type errors on instrumented async functions are a bit vague,
since the type error originates within the macro itself due to the
indirection of additional `async {}` blocks generated in the proc-macro
(and due to the way that inference propagates around in Rust).

This leads to a pretty difficult to understand error. For example:

```rust
#[instrument]
async fn foo() -> String {
  ""
}
```

results in...

```
error[E0308]: mismatched types
 --> src/main.rs:1:1
  |
1 | #[tracing::instrument]
  | ^^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
  | |
  | expected struct `String`, found `&str`
```

## Solution

Installs a fake `return` statement as the first thing that happens in
the auto-generated block of an instrumented async function.

This causes the coercion machinery within rustc to infer the right
return type (matching the the outer function) eagerly, as opposed to
after the `async {}` block has been type-checked.

This will cause us to both be able to point out the return type span
correctly, and properly suggest fixes on the expressions that cause the
type mismatch.

After this change, the example code above compiles to:

```
error[E0308]: mismatched types
  --> src/main.rs:3:5
   |
3  |     ""
   |     ^^- help: try using a conversion method: `.to_string()`
   |     |
   |     expected struct `String`, found `&str`
   |
note: return type inferred to be `String` here
  --> src/main.rs:2:20
   |
2  | async fn foo() -> String {
   |                   ^^^^^^
```
I just saw this warning when trying to debug something in Miri:
```
warning: some trace filter directives would enable traces that are disabled statically
 | `miri::tls=trace` would enable the TRACE level for the `miri::tls` target
 = note: the static max level is `info`
 = help: to enable DEBUG logging, remove the `max_level_info` feature
```

I spent 10min figuring out why the `log` crate is doing this (Miri is
using env-logger for logging), until I realized that this error actually
originates from inside rustc, which I guess uses `tracing`. It would
have helped if the error message would say which crate is even talking
to me here. :)
The `on_register_dispatch` method is invoked when a `Subscriber` is
registered as a `Dispatch`. This method should be overridden to
perform actions upon the installation of a subscriber/layer;
for instance, to send a copy of the subscriber's `Dispatch` to a
worker thread.
Fixes #2280

## Motivation

I've implemented an alternative to [`tracing-wasm`] to fix some issues
that I had when using it (most are open as longer time bug reports, no
need to recount them here). It should be more up to date with the
current tracing framework and, being layer based, is easier to compose
with other subscribers, e.g. supports formatting and timing on event
logs out of the box.

## Solution

Add the [`tracing-web`] crate to the list of related crates.

[`tracing-wasm`]: (https://github.com/storyai/tracing-wasm)
[`tracing-web`]: https://crates.io/crates/tracing-web/
…#2296)

One can want to have an event added from outside context of a span,
especially in an async code (e.g. between polls of the future, or
between polling multiple futures instrumented with that span). Then it
is expected that the event will be attached indeed to the span specified
as the parent and not the contextual one.

Fixes: #2295

See #2295
## Motivation

Support the latest OpenTelemetry specification.

## Solution

Update `opentelemetry` to the latest `0.18.x` release. Breaking changes
in the metrics spec have removed value recorders and added histograms so
the metrics layer's `value.` prefix has been changed to `histogram.` and
behaves accordingly. Additionally the `PushController` configuration for
the metrics layer has been simplified to accept a `BasicController` that
can act in either push or pull modes. Finally trace sampling in the
sdk's `PreSampledTracer` impl has been updated to match the sampling
logic in open-telemetry/opentelemetry-rust#839.

* Update MSRV to 1.56
* Update examples
* Fix async-trait dep
* Update msrv action

Co-authored-by: Eliza Weisman <[email protected]>
@hawkw
Copy link
Member

hawkw commented Sep 19, 2022

The reason for the Clippy failures is that PR #2269 wasn't backported correctly, and the on_register_dispatch method was never actually being called, resulting in dead code. I've fixed that.

We probably should have had a test that on_register_dispatch is called when registering a dispatcher, as that would have caught this...

…#2308)

## Motivation

`bare_trait_objects` lint will become a hard error in Rust 2021.

While tracing is still using Rust 2018, `bare_trait_objects` is a
warning in the MSRV and `dyn` keyword is recommended.

## Solution

Replace all `&Value` with `&dyn Value` in macro expansions.
@hawkw hawkw merged commit ffad660 into v0.1.x Sep 19, 2022
@hawkw hawkw deleted the david/v0.1.0-backports branch September 19, 2022 18:47
@davidbarsky
Copy link
Member Author

sorry, i thought i replied; thanks for catching my mistake there.

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.