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

Support looking up a ContextStore from outside of Advice #3827

Merged
merged 4 commits into from
Aug 18, 2021

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Aug 12, 2021

Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

That's a really cool idea 🚀
Left a few comments, maybe we can simplify the InstrumentationContextProvider a bit more.

Comment on lines 70 to 71
InstrumentationContext.internalSetContextStoreSupplier(
(keyClass, contextClass) -> FieldBackedProvider.getContextStore(keyClass, contextClass));
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably put that somewhere in InstrumentationLoader where InstrumentationContextProvider implementation gets chosen. Maybe that getContextStore() method should be a part of that provider interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to InstrumentationModuleInstaller

if (contextStoreSupplier == null) {
throw new IllegalStateException("");
}
return contextStoreSupplier.get(keyClass, contextClass);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we still need to replace InstrumentationContext.get() calls in FieldBackedProvider - if the provider idea works for helper classes, wouldn't it work everywhere? Removing that part would certainly make FieldBackedProvider a bit simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that it is better to keep replacing InstrumentationContext.get() calls in FieldBackedProvider because this InstrumentationContext.get() implementation isn't really efficient. It involves Class.forName and Class.getMethod which is fine in helper classes where you can do the lookup once and keep ContextStore in a field.

@laurit laurit merged commit 667b87b into open-telemetry:main Aug 18, 2021
@laurit laurit deleted the context-store-outside-advice branch August 18, 2021 07:36
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.

Support looking up a ContextStore from outside of Advice
2 participants