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

Refactor context propagation to work with async #588

Merged
merged 3 commits into from
Apr 1, 2019
Merged

Conversation

reyang
Copy link
Contributor

@reyang reyang commented Mar 29, 2019

This is to merge #566 and #573 to master.

@reyang reyang requested review from c24t, songy23 and a team as code owners March 29, 2019 17:36
Introduced the generic RuntimeContext.
Migrate execution_context to RuntimeContext
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

The context changes LGTM, and this is a huge improvement over threadlocals. We still have some work to do to change how the context is used in the library (e.g. removing the tracer, measure to view map, etc.) and adding/using context managers as in your Span example, but this is a problem for another PR.

I think it's possible that this PR will introduce bugs in instrumented code because of the different behavior between 2 and 3, especially in code that touches thread-local storage or changes the default thread creation behavior (like we do in opencensus-ext-threading). We may want to figure out exactly how this is likely to break instrumented code and document it before releasing.

scripts/twine_upload.sh Outdated Show resolved Hide resolved
context/opencensus-context/version.py Outdated Show resolved Hide resolved

from opencensus.common.runtime_context import RuntimeContext

RuntimeContext.register_slot('correlation_context', lambda: {})
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think it's more idiomatic to use dict than lambda: {}, but your call.

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 picked explicitly lambda in order to tell ctor from a type name.
For example isinstance(x, Foo) and map(lambda x: Foo(x), range(10)).

# See the License for the specific language governing permissions and
# limitations under the License.

from multiprocessing.dummy import Pool as ThreadPool
Copy link
Member

Choose a reason for hiding this comment

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

Why multiprocessing...ThreadPool instead of concurrent.futures.ThreadPoolExecutor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This former works with Python 2.7.


class Slot(object):
def __init__(self, name, default):
import contextvars
Copy link
Member

Choose a reason for hiding this comment

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

Why bury the import in here?

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 was trying to reduce the visibility of contextvars to avoid accidental use.
Alternatively we could use if/else and import at the top level (which seems harder to maintain?)

@reyang
Copy link
Contributor Author

reyang commented Apr 1, 2019

I think it's possible that this PR will introduce bugs in instrumented code because of the different behavior between 2 and 3, especially in code that touches thread-local storage or changes the default thread creation behavior (like we do in opencensus-ext-threading). We may want to figure out exactly how this is likely to break instrumented code and document it before releasing.

We need to take a closer look at opencensus-ext-threading and how we propagate across process (multi-processing).
I plan to add doc, more test cases and samples to the context library in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants