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

Enable access to context provider #183

Merged
merged 2 commits into from
Aug 31, 2017
Merged

Enable access to context provider #183

merged 2 commits into from
Aug 31, 2017

Conversation

p-lambert
Copy link
Member

Also:

  • Add DefaultContextProvider#context= method

@palazzem palazzem self-requested a review August 31, 2017 07:45
@palazzem palazzem added core Involves Datadog core libraries enhancement labels Aug 31, 2017
@palazzem palazzem added this to the 0.8.2 milestone Aug 31, 2017
@@ -8,6 +8,9 @@ def initialize
@context = Datadog::ThreadLocalContext.new
end

# Sets the current context.
attr_writer :context
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the point, but in that case we're going to simply replace the way to do context propagation (the ThreadLocalContext is a specific implementation to get/set the propagation). I think it would be better to have a def context= that simply sets the @context.local to the given value (so it replaces the thread-local storage).

With the PR API we're having:

ctx = tracer.provider.context  # assuming we're not using the shortcut
tracer.prover.context = Datadog::ThreadLocalContext.new

My goal here is having:

ctx = tracer.provider.context
tracer.provider.context = Datadog::Context(...)  # you will do that in distributed tracing

The second approach is more symmetric and the API is just a "wrapper" to get/set the active Context regardless where it's stored.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

humn, this is part of the API that still doesn't make sense to me. In my opinion, it really feels that the ThreadLocalContext is precisely a context provider! All it is doing is binding the context object to a thread-local variable, so it really feels that it overlaps with the provider responsibility. On the other hand, I don't understand what .local would mean for contexts other than the ThreadLocalContext.
I also find confusing that we we say ThreadLocalContext, because that object doesn't expose the same API that the Context does. Maybe ThreadLocalContext Should be merely a delegator around Context? I think the goal is make it transparent for the Tracer, right? I just don't agree/understand this interface Provider->ThreadLocalContext->Context
Long rambling here, lol. Maybe I'd understand this better if I knew future use-cases/implementations for these objects, but right now these abstractions don't make much sense for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

The final implementation we need is a Provider that returns the current active Context (or Span). I definitely agree that ThreadLocalContext is a level of indirection, so to me the goal here could be simply:

  • DefaultContextProvider is the provider (as said in the name) that offers a way to get/set the current active Context
  • DefaultContextProvider includes the logic of ThreadLocalContext that is a level of indirection and doesn't need to exist
  • Context is left untouched

I think that ^^ makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

awesome! yes, that makes much more sense imo. Do you think we should "merge" the DefaultContextProvider and ThreadLocalContext in this PR, or leave it for a future one and just update the setter now? I'm fine with either.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to do that in the PR where we're propagating the Span instead of the Context. Lot of changes here, I prefer a clean 0.8.2 without breaking changes (even if this one is "internal" and nobody should use it). Cool?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perfect. Thanks!

Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

No breaking changes here, only the new setter so all good to me to ship with a minor release.

@p-lambert p-lambert merged commit 5a85f94 into master Aug 31, 2017
@palazzem palazzem deleted the pedro/update-provider branch September 1, 2017 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants