-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for custom context storage #1
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
base: master
Are you sure you want to change the base?
Conversation
| * | ||
| * @since 0.5 | ||
| */ | ||
| public final class ContextUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiding ContextUtils to force everyone to migrate to CtxUtils or use other abstractions like CurrentSpanUtils.
| import io.opencensus.trace.Ctx; | ||
| import io.opencensus.trace.Span; | ||
|
|
||
| public class CtxUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally wanted to keep ContextUtils, but unfortunately its method signatures require working with gRPC context.
I've introduced the Ctx interface to allow using implementations not using gRPC, and had to declare this new class to keep the original ContextUtils untouched.
| * Overrides context manager with a custom implementation | ||
| * @param cm custom {@code ContextManager} to be used instead of a default one. | ||
| */ | ||
| public static void setContextManager(ContextManager cm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change in the OpenCensus Java code, allowing us to set a custom implementation, which can be hosted in the opentelemetry-operations-java repo. This way we don't need to add a dependency on OpenTelemetry jars here.
The implementation may be customized to make it thread safe later, keeping it simple for now.
| /** | ||
| * Default {@code ContextManager} implementation using {@see io.grpc.Context} | ||
| */ | ||
| public class ContextManagerImpl implements ContextManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default implementation simply redirects all calls to ContextUtils (original implementation).
Experimental change: declare the
ContextManagerinterface which allows for overriding the context storage in OpenCensus.Default implementation keeps backward compatible behavior using gRPC context with OpenCensus-specific key.