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

Unify span traversal #1429

Closed
nightkr opened this issue Jun 9, 2021 · 0 comments
Closed

Unify span traversal #1429

nightkr opened this issue Jun 9, 2021 · 0 comments
Labels
kind/feature New feature or request

Comments

@nightkr
Copy link
Contributor

nightkr commented Jun 9, 2021

Feature Request

Crates

  • tracing-subscriber

Motivation

Currently there are a way to traverse spans, that all behave subtly differently:

  • Context::scope: implicit leaf span (based on the active span), ordered root-to-leaf, includes leaf span
  • Span::from_root: explicit leaf span, ordered root-to-leaf, excludes leaf span
  • Span::parents: explicit leaf span, ordered leaf-to-root, excludes leaf span
  • while let iteration on Span::parent: explicit leaf span, ordered leaf-to-root, includes leaf span, not an Iterator

All of these are problematic in different ways:

  • Excluding the leaf span leads to issues like JSON formatter: "spans" property does not contain the leaf #1408, where the leaf node is left out of formatting
  • Inferring the leaf span makes the function unusable in Layer::on_event, and other cases where the current Span may not match what you're trying to format (see also: Look up span for event #1428)
  • Manual iteration is harder to compose
  • Root-to-leaf iteration is expensive (requires reifying the whole list and iterating over that), so it should be an explicit choice

Based on a Discord discussion starting at https://canary.discord.com/channels/500028886025895936/627649734592561152/852143116244221973

Proposal

  • Add a new method SpanRef::scope(&self) that returns a leaf-to-root Iterator, including the specified leaf
  • Add a new method Scope::from_root(self) (where Scope is the type returned by SpanRef::scope defined earlier) that returns a root-to-leaf Iterator that ends at the current leaf (in other words: it's essentially the same as Scope::collect::<Vec<_>>().into_iter().rev())
  • Deprecate all existing iterators, since they can be replaced by the new unified mechanism:
    • Span::parents is equivalent to Span::scope().skip(1) (although the skip is typically a bug)
    • Span::from_root is equivalent to Span::scope().skip(1).from_root() (although the skip is typically a bug)
    • Context::scope is equivalent to Context::lookup_current().scope().from_root() (although the lookup_current is sometimes a bug, see also Look up span for event #1428)

Alternatives

  • Keep existing API as-is, add Context::event_scope(&self, event: &Event) (to handle the same use-case as Look up span for event #1428)
    • Yet another special case
    • Less API churn
  • Have SpanRef::scope reify the list immediately
    • Simpler implementation, since we can just reuse the standard library's
    • No need for separate types for going in each direction
    • Leaf-to-root iteration gets the same overhead as root-to-leaf iteration
nightkr added a commit to Appva/tracing that referenced this issue Jun 9, 2021
@hawkw hawkw added the kind/feature New feature or request label Jun 15, 2021
hawkw pushed a commit that referenced this issue Jun 22, 2021
## Motivation

Fixes #1429 

## Solution

Implemented as described in #1429, and migrated all internal uses of the
deprecated methods. All tests passed both before and after the migration
(9ec8130).

- Add a new method `SpanRef::scope(&self)` that returns a leaf-to-root
  `Iterator`, including the specified leaf
- Add a new method `Scope::from_root(self)` (where `Scope` is the type
  returned by `SpanRef::scope` defined earlier) that returns a
  root-to-leaf `Iterator` that ends at the current leaf (in other
  words: it's essentially the same as
  `Scope::collect::<Vec<_>>().into_iter().rev()`)
- Deprecate all existing iterators, since they can be replaced by the
  new unified mechanism:
  - `Span::parents` is equivalent to `Span::scope().skip(1)` (although
    the `skip` is typically a bug)
  - `Span::from_root` is equivalent to `Span::scope().skip(1).from_root()`
    (although the `skip` is typically a bug)
  - `Context::scope` is equivalent to
    `Context::lookup_current().scope().from_root()` (although the
    `lookup_current` is sometimes a bug, see also #1428)
nightkr added a commit to Appva/tracing that referenced this issue Jun 24, 2021
Fixes tokio-rs#1429 (forwardport from v0.1.x branch)

Implemented as described in tokio-rs#1429, and migrated all internal uses of the
deprecated methods. All tests passed both before and after the migration
(9ec8130).

- Add a new method `SpanRef::scope(&self)` that returns a leaf-to-root
  `Iterator`, including the specified leaf
- Add a new method `Scope::from_root(self)` (where `Scope` is the type
  returned by `SpanRef::scope` defined earlier) that returns a
  root-to-leaf `Iterator` that ends at the current leaf (in other
  words: it's essentially the same as
  `Scope::collect::<Vec<_>>().into_iter().rev()`)
- Deprecate all existing iterators, since they can be replaced by the
  new unified mechanism:
  - `Span::parents` is equivalent to `Span::scope().skip(1)` (although
    the `skip` is typically a bug)
  - `Span::from_root` is equivalent to `Span::scope().skip(1).from_root()`
    (although the `skip` is typically a bug)
  - `Context::scope` is equivalent to
    `Context::lookup_current().scope().from_root()` (although the
    `lookup_current` is sometimes a bug, see also tokio-rs#1428)
@hawkw hawkw closed this as completed in f54136c Jun 24, 2021
gilescope added a commit to gilescope/substrate that referenced this issue Aug 6, 2021
gilescope added a commit to paritytech/substrate that referenced this issue Aug 13, 2021
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
akshayknarayan added a commit to akshayknarayan/tracing-timing that referenced this issue Mar 9, 2022
`SpanRef::parent()` was deprecated in tracing-subscriber v0.3, but as
noted at tokio-rs/tracing#1429 it is
equivalent to `Span::scope().skip(1)`, so we use that instead.
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-aura that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-authorship that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-authority-discovery that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-benchmarking that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-bounties that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-collective that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-election-provider-multi-phase that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-democracy that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-elections-phragmen that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-contracts that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-executive that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-im-online that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-merkle-mountain-range that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-lottery that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-multisig that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-offences that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-proxy that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-recovery that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-session that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-try-runtime that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-transaction-storage that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-staking that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-timestamp that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-transaction-payment that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-treasury that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-system that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-utility that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-uniques that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-vesting that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
taqtiqa-mark pushed a commit to subversive-upstream/polkadot-sdk-substrate-frame-support that referenced this issue Sep 14, 2023
Remove unneeded dependencies and dev-dependencies.
Made self_destruct test not dependent on wasm bin size.  
Updated code related to deprecated warning on tracing-subscriber `scope()` 
( See tokio-rs/tracing#1429 )
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
## Motivation

Fixes tokio-rs#1429 

## Solution

Implemented as described in tokio-rs#1429, and migrated all internal uses of the
deprecated methods. All tests passed both before and after the migration
(9ec8130).

- Add a new method `SpanRef::scope(&self)` that returns a leaf-to-root
  `Iterator`, including the specified leaf
- Add a new method `Scope::from_root(self)` (where `Scope` is the type
  returned by `SpanRef::scope` defined earlier) that returns a
  root-to-leaf `Iterator` that ends at the current leaf (in other
  words: it's essentially the same as
  `Scope::collect::<Vec<_>>().into_iter().rev()`)
- Deprecate all existing iterators, since they can be replaced by the
  new unified mechanism:
  - `Span::parents` is equivalent to `Span::scope().skip(1)` (although
    the `skip` is typically a bug)
  - `Span::from_root` is equivalent to `Span::scope().skip(1).from_root()`
    (although the `skip` is typically a bug)
  - `Context::scope` is equivalent to
    `Context::lookup_current().scope().from_root()` (although the
    `lookup_current` is sometimes a bug, see also tokio-rs#1428)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants