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

subscriber: explain why we always call inner.register_callsite() before if statement #1433

Merged
merged 3 commits into from
Jun 23, 2021

Conversation

Folyd
Copy link
Contributor

@Folyd Folyd commented Jun 10, 2021

I'm sure we can avoid unnecessary self.inner.register_callsite() call in these two Layered implementations.

@Folyd Folyd requested review from davidbarsky, hawkw and a team as code owners June 10, 2021 13:51
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.

I don't think this is correct. register_callsite is not just responsible for performing filtering, it's also responsible for notifying the collector of the existence of the callsite --- it may choose to, for example, store some data for that callsite. This change means that if the outer Subscriber returns Interest::sometimes, the inner subscriber will never have the opportunity to register a callsite that is enabled.

If the subscriber, for example, preallocates storage for spans originating at particular callsites, it may then see a span from a callsite that it never had the opportunity to prepare storage for. The intention behind calling inner.register_callsite before the if statement was to ensure that the inner subscriber is informed that the callsite exists regardless of the outer subscriber's filtering decision. So, I think this change would actually introduce a bug.

Perhaps a better solution is to add a comment on that line explaining why we always call register_callsite on inner?

@Folyd Folyd force-pushed the improve-subscriber branch from 7eece07 to 617ccfd Compare June 11, 2021 10:51
@Folyd Folyd changed the title subscriber: avoid unnecessary inner register_callsite() call subscriber: explain why we always call inner.register_callsite() before if statement Jun 11, 2021
@Folyd
Copy link
Contributor Author

Folyd commented Jun 11, 2021

I don't think this is correct. register_callsite is not just responsible for performing filtering, it's also responsible for notifying the collector of the existence of the callsite --- it may choose to, for example, store some data for that callsite. This change means that if the outer Subscriber returns Interest::sometimes, the inner subscriber will never have the opportunity to register a callsite that is enabled.

If the subscriber, for example, preallocates storage for spans originating at particular callsites, it may then see a span from a callsite that it never had the opportunity to prepare storage for. The intention behind calling inner.register_callsite before the if statement was to ensure that the inner subscriber is informed that the callsite exists regardless of the outer subscriber's filtering decision. So, I think this change would actually introduce a bug.

Perhaps a better solution is to add a comment on that line explaining why we always call register_callsite on inner?

Thanks, @hawkw. You're right. I have updated the comments. ❤️

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, thanks!

tracing-subscriber/src/subscribe.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/subscribe.rs Outdated Show resolved Hide resolved
@hawkw hawkw merged commit 60f816b into tokio-rs:master Jun 23, 2021
hawkw added a commit that referenced this pull request Jun 25, 2021
…fore if statement (#1433)

This backports #1433 from `master`.

* subscriber: explain why we always call `inner.register_callsite()` before if statement

* Apply suggestions from code review

Co-authored-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this pull request Jun 26, 2021
…fore if statement (#1433)

This backports #1433 from `master`.

* subscriber: explain why we always call `inner.register_callsite()` before if statement

* Apply suggestions from code review

Co-authored-by: Eliza Weisman <[email protected]>
@Folyd Folyd deleted the improve-subscriber branch September 4, 2021 15:34
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…fore if statement (tokio-rs#1433)

This backports tokio-rs#1433 from `master`.

* subscriber: explain why we always call `inner.register_callsite()` before if statement

* Apply suggestions from code review

Co-authored-by: Eliza Weisman <[email protected]>
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