Skip to content

Conversation

@nilebox
Copy link
Owner

@nilebox nilebox commented Oct 12, 2020

Experimental change: declare the ContextManager interface which allows for overriding the context storage in OpenCensus.
Default implementation keeps backward compatible behavior using gRPC context with OpenCensus-specific key.

*
* @since 0.5
*/
public final class ContextUtils {
Copy link
Owner Author

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 {
Copy link
Owner Author

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) {
Copy link
Owner Author

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 {
Copy link
Owner Author

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).

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