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

core: add Collect impl for Box<dyn Collect + ...> #1358

Merged
merged 1 commit into from Apr 27, 2021
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Apr 15, 2021

In some cases, users may wish to erase the type of a Colelct
implementation, such as when it is dynamically constructed from a
complex parameterized type. When doing so, it's important to ensure that
all trait methods with default implementations are properly forwarded to
the inner erased type. For example, if the type does not implement
try_close, but the inner erased collector does, then the the
collector will not be notified when spans close — which could result in
a memory leak.

To avoid potential footguns resulting from users implementing
type-erased collectors incorrectly, this branch adds a new impl Collect for Box<dyn Collect + Send + Sync + 'static> in tracing-core, when
the alloc feature flag is enabled. This is also somewhat more
ergonomic than any solution in another crate, since the implementation
is for Box<dyn Collect + ...> directly, rather than some
BoxedCollector newtype.

Closes #1371

Signed-off-by: Eliza Weisman eliza@buoyant.io

In some cases, users may wish to erase the type of a `Colelct`
implementation, such as when it is dynamically constructed from a
complex parameterized type. When doing so, it's important to ensure that
all trait methods with default implementations are properly forwarded to
the inner erased type. For example, if the type does not implement
`try_close`, but the inner erased collector does, then the the
collector will not be notified when spans close — which could result in
a memory leak.

To avoid potential footguns resulting from users implementing
type-erased collectors incorrectly, this branch adds a new `impl Collect
for Box<dyn Collect + Send + Sync + 'static>` in `tracing-core`, when
the `alloc` feature flag is enabled. This is also somewhat more
ergonomic than any solution in another crate, since the implementation
is for `Box<dyn Collect + ...>` directly, rather than some
`BoxedCollector` newtype.
@hawkw hawkw requested a review from carllerche as a code owner April 15, 2021 21:51
@hawkw hawkw merged commit d59a2ca into master Apr 27, 2021
@hawkw hawkw deleted the eliza/box-subscriber branch April 27, 2021 16:30
hawkw added a commit that referenced this pull request Apr 27, 2021
Users may wish to erase the type of a `Collect`
implementation, such as when it is dynamically constructed from a
complex parameterized type. PR #1358 added a `Collect` implementation
for `Box<dyn Collect + Send + Sync + 'static>`, allowing the use of
type-erased trait objects. In some cases, it may also be useful to share
a type-erased collector, _without_ using `Dispatch` --- such as when
different sets of `tracing-subscriber` subscribers are layered on one
shared collector.

## Solution

This branch builds on #1358 by adding an `impl Collect for Arc<dyn
Collect + Send + Sync + 'static>`. I also added quick tests for both
`Arc`ed and `Box`ed collectors.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 28, 2021
Users may wish to erase the type of a `Collect`
implementation, such as when it is dynamically constructed from a
complex parameterized type. PR #1358 added a `Collect` implementation
for `Box<dyn Collect + Send + Sync + 'static>`, allowing the use of
type-erased trait objects. In some cases, it may also be useful to share
a type-erased collector, _without_ using `Dispatch` --- such as when
different sets of `tracing-subscriber` subscribers are layered on one
shared collector.

## Solution

This branch builds on #1358 by adding an `impl Collect for Arc<dyn
Collect + Send + Sync + 'static>`. I also added quick tests for both
`Arc`ed and `Box`ed collectors.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Apr 30, 2021
In some cases, users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. When doing so, it's important to ensure that
all trait methods with default implementations are properly forwarded to
the inner erased type. For example, if the type does not implement
`try_close`, but the inner erased subscriber does, then the the
subscriber will not be notified when spans close — which could result in
a memory leak.

To avoid potential footguns resulting from users implementing
type-erased subscribers incorrectly, this branch adds a new `impl
Subscriber for Box<dyn Subscriber + Send + Sync + 'static>` in
`tracing-core`. This is also somewhat more ergonomic than any solution
in another crate, since the implementation  is for `Box<dyn Subscriber +
...>` directly, rather than some `BoxedSubscriber` newtype.
hawkw added a commit that referenced this pull request Apr 30, 2021
## Motivation (#1374)

Users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. PR #1358 added a `Subscriber` implementation
for `Box<dyn Subscriber + Send + Sync + 'static>`, allowing the use of
type-erased trait objects. In some cases, it may also be useful to share
a type-erased subscriber, _without_ using `Dispatch` --- such as when
different sets of `tracing-subscriber` subscribers are layered on one
shared subscriber.

## Solution

This branch builds on #1358 by adding an `impl Subscriber for Arc<dyn
Subscriber + Send + Sync + 'static>`. I also added quick tests for both
`Arc`ed and `Box`ed subscribers.

Signed-off-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
In some cases, users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. When doing so, it's important to ensure that
all trait methods with default implementations are properly forwarded to
the inner erased type. For example, if the type does not implement
`try_close`, but the inner erased subscriber does, then the the
subscriber will not be notified when spans close — which could result in
a memory leak.

To avoid potential footguns resulting from users implementing
type-erased subscribers incorrectly, this branch adds a new `impl
Subscriber for Box<dyn Subscriber + Send + Sync + 'static>` in
`tracing-core`. This is also somewhat more ergonomic than any solution
in another crate, since the implementation  is for `Box<dyn Subscriber +
...>` directly, rather than some `BoxedSubscriber` newtype.
hawkw added a commit that referenced this pull request Apr 30, 2021
## Motivation (#1374)

Users may wish to erase the type of a `Subscriber`
implementation, such as when it is dynamically constructed from a
complex parameterized type. PR #1358 added a `Subscriber` implementation
for `Box<dyn Subscriber + Send + Sync + 'static>`, allowing the use of
type-erased trait objects. In some cases, it may also be useful to share
a type-erased subscriber, _without_ using `Dispatch` --- such as when
different sets of `tracing-subscriber` subscribers are layered on one
shared subscriber.

## Solution

This branch builds on #1358 by adding an `impl Subscriber for Arc<dyn
Subscriber + Send + Sync + 'static>`. I also added quick tests for both
`Arc`ed and `Box`ed subscribers.

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

### 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 `Current` and
  `Option<Id>` ([#1335])
- `Attributes::fields` accessor that returns the set of fields defined
  on a span's `Attributes` ([#1331])

Thanks to @Folyd for contributing to this release!

[#1358]: #1358
[#1374]: #1374
[#1335]: #1335
[#1331]: #1331
hawkw added a commit that referenced this pull request Apr 30, 2021
# 0.1.18 (April 30, 2010)

### 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 `Current` and
  `Option<Id>` ([#1335])
- `Attributes::fields` accessor that returns the set of fields defined
  on a span's `Attributes` ([#1331])

Thanks to @Folyd for contributing to this release!

[#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
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
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.

None yet

1 participant