-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mauricio/implement-observer
- Loading branch information
Showing
14 changed files
with
107 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
opentelemetry-api/src/opentelemetry/context/default_context.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
opentelemetry-api/tests/context/test_contextvars_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2020, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
from unittest.mock import patch | ||
|
||
from opentelemetry import context | ||
|
||
try: | ||
import contextvars # pylint: disable=unused-import | ||
from opentelemetry.context.contextvars_context import ( | ||
ContextVarsRuntimeContext, | ||
) | ||
except ImportError: | ||
raise unittest.SkipTest("contextvars not available") | ||
|
||
|
||
def do_work() -> None: | ||
context.set_current(context.set_value("say", "bar")) | ||
|
||
|
||
class TestContextVarsContext(unittest.TestCase): | ||
def setUp(self): | ||
self.previous_context = context.get_current() | ||
|
||
def tearDown(self): | ||
context.set_current(self.previous_context) | ||
|
||
@patch( | ||
"opentelemetry.context._RUNTIME_CONTEXT", ContextVarsRuntimeContext() # type: ignore | ||
) | ||
def test_context(self): | ||
self.assertIsNone(context.get_value("say")) | ||
empty = context.get_current() | ||
second = context.set_value("say", "foo") | ||
|
||
self.assertEqual(context.get_value("say", context=second), "foo") | ||
|
||
do_work() | ||
self.assertEqual(context.get_value("say"), "bar") | ||
third = context.get_current() | ||
|
||
self.assertIsNone(context.get_value("say", context=empty)) | ||
self.assertEqual(context.get_value("say", context=second), "foo") | ||
self.assertEqual(context.get_value("say", context=third), "bar") | ||
|
||
@patch( | ||
"opentelemetry.context._RUNTIME_CONTEXT", ContextVarsRuntimeContext() # type: ignore | ||
) | ||
def test_set_value(self): | ||
first = context.set_value("a", "yyy") | ||
second = context.set_value("a", "zzz") | ||
third = context.set_value("a", "---", first) | ||
self.assertEqual("yyy", context.get_value("a", context=first)) | ||
self.assertEqual("zzz", context.get_value("a", context=second)) | ||
self.assertEqual("---", context.get_value("a", context=third)) | ||
self.assertEqual(None, context.get_value("a")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.