diff --git a/CHANGELOG.md b/CHANGELOG.md index 7128e62bfda..49b292522da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-api` `opentelemety-sdk` Moved `idsgenerator` into sdk ([#1514](https://github.com/open-telemetry/opentelemetry-python/pull/1514)) +### Removed +- `opentelemetry-api` Remove ThreadLocalRuntimeContext since python3.4 is not supported. + ## [0.16b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.16b1) - 2020-11-26 ### Added - Add meter reference to observers diff --git a/opentelemetry-api/setup.cfg b/opentelemetry-api/setup.cfg index ab0fcd01ebf..7deb389f18b 100644 --- a/opentelemetry-api/setup.cfg +++ b/opentelemetry-api/setup.cfg @@ -50,7 +50,6 @@ where = src [options.entry_points] opentelemetry_context = contextvars_context = opentelemetry.context.contextvars_context:ContextVarsRuntimeContext - threadlocal_context = opentelemetry.context.threadlocal_context:ThreadLocalRuntimeContext opentelemetry_meter_provider = default_meter_provider = opentelemetry.metrics:DefaultMeterProvider opentelemetry_tracer_provider = diff --git a/opentelemetry-api/src/opentelemetry/context/threadlocal_context.py b/opentelemetry-api/src/opentelemetry/context/threadlocal_context.py deleted file mode 100644 index 43e9fb7ce9e..00000000000 --- a/opentelemetry-api/src/opentelemetry/context/threadlocal_context.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright The 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 threading - -from opentelemetry.context.context import Context, RuntimeContext - - -class ThreadLocalRuntimeContext(RuntimeContext): - """An implementation of the RuntimeContext interface - which uses thread-local storage under the hood. This - implementation is available for usage with Python 3.4. - """ - - class Token: - def __init__(self, context: Context) -> None: - self._context = context - - _CONTEXT_KEY = "current_context" - - def __init__(self) -> None: - self._current_context = threading.local() - - def attach(self, context: Context) -> object: - """See `opentelemetry.context.RuntimeContext.attach`.""" - current = self.get_current() - setattr(self._current_context, self._CONTEXT_KEY, context) - return self.Token(current) - - def get_current(self) -> Context: - """See `opentelemetry.context.RuntimeContext.get_current`.""" - if not hasattr(self._current_context, self._CONTEXT_KEY): - setattr( - self._current_context, self._CONTEXT_KEY, Context(), - ) - context = getattr( - self._current_context, self._CONTEXT_KEY - ) # type: Context - return context - - def detach(self, token: object) -> None: - """See `opentelemetry.context.RuntimeContext.detach`.""" - if not isinstance(token, self.Token): - raise ValueError("invalid token") - # pylint: disable=protected-access - setattr(self._current_context, self._CONTEXT_KEY, token._context) - - -__all__ = ["ThreadLocalRuntimeContext"] diff --git a/opentelemetry-api/tests/context/test_threadlocal_context.py b/opentelemetry-api/tests/context/test_threadlocal_context.py deleted file mode 100644 index 02c62ba1803..00000000000 --- a/opentelemetry-api/tests/context/test_threadlocal_context.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright The 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. - -from unittest.mock import patch - -from opentelemetry import context -from opentelemetry.context.threadlocal_context import ThreadLocalRuntimeContext - -from .base_context import ContextTestCases - - -class TestThreadLocalContext(ContextTestCases.BaseTest): - def setUp(self) -> None: - super(TestThreadLocalContext, self).setUp() - self.mock_runtime = patch.object( - context, "_RUNTIME_CONTEXT", ThreadLocalRuntimeContext(), - ) - self.mock_runtime.start() - - def tearDown(self) -> None: - super(TestThreadLocalContext, self).tearDown() - self.mock_runtime.stop()