From 85476faba82a1e5f460ddb4dd800fd7ae19d0210 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 8 Jan 2021 01:33:09 +0530 Subject: [PATCH 1/2] Remove threadlocalcontext --- opentelemetry-api/setup.cfg | 1 - .../context/threadlocal_context.py | 60 ------------------- .../tests/context/test_threadlocal_context.py | 33 ---------- 3 files changed, 94 deletions(-) delete mode 100644 opentelemetry-api/src/opentelemetry/context/threadlocal_context.py delete mode 100644 opentelemetry-api/tests/context/test_threadlocal_context.py diff --git a/opentelemetry-api/setup.cfg b/opentelemetry-api/setup.cfg index 8bb3e6cc6f7..26eafa51154 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() From 0a21680880dc94aea43878dfe0955eefd98a2b82 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 8 Jan 2021 19:44:10 +0530 Subject: [PATCH 2/2] Add CHANGELOG entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d77447ad31..694fbdebf7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-exporter-jaeger` Updated Jaeger exporter status code tag ([#1488](https://github.com/open-telemetry/opentelemetry-python/pull/1488)) +### 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