From 937c9f7ae705ba3f1ba86a235430a18810cc2e00 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Mon, 11 Mar 2024 16:36:30 +0000 Subject: [PATCH 1/7] * Adding (failing) testcase to cover Issue #2029 --- .../tests/test_duplicate.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py new file mode 100644 index 0000000000..83bad6e1d4 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py @@ -0,0 +1,30 @@ +# 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 unittest + +from opentelemetry.instrumentation.celery import CeleryInstrumentor + +class TestUtils(unittest.TestCase): + + def test_duplicate_instrumentaion(self): + first = CeleryInstrumentor() + first.instrument() + second = CeleryInstrumentor() + second.instrument() + CeleryInstrumentor().uninstrument() + self.assertIsNotNone(first.metrics) + self.assertIsNotNone(second.metrics) + self.assertEqual(first.task_id_to_start_time,{}) + self.assertEqual(second.task_id_to_start_time, {}) From ae97898bd8486ac881efd7e08e4a5a04c7bf37d2 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Mon, 11 Mar 2024 16:41:09 +0000 Subject: [PATCH 2/7] * move Instance variables to class variables. Since the object in question will be a singelton. This will resolve #2029 where multiple calls to the instrumentation will assign Null values. --- .../src/opentelemetry/instrumentation/celery/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 94cac68b70..30382b282a 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -113,10 +113,11 @@ def keys(self, carrier): class CeleryInstrumentor(BaseInstrumentor): + metrics = None + task_id_to_start_time = {} + def __init__(self): super().__init__() - self.metrics = None - self.task_id_to_start_time = {} def instrumentation_dependencies(self) -> Collection[str]: return _instruments From 0a2eab14066341d687e0a8fb22f86ed24957dfd1 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Mon, 11 Mar 2024 18:49:31 +0000 Subject: [PATCH 3/7] * black formatting --- .../tests/test_duplicate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py index 83bad6e1d4..ab1f7804cf 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_duplicate.py @@ -16,8 +16,8 @@ from opentelemetry.instrumentation.celery import CeleryInstrumentor -class TestUtils(unittest.TestCase): +class TestUtils(unittest.TestCase): def test_duplicate_instrumentaion(self): first = CeleryInstrumentor() first.instrument() @@ -26,5 +26,5 @@ def test_duplicate_instrumentaion(self): CeleryInstrumentor().uninstrument() self.assertIsNotNone(first.metrics) self.assertIsNotNone(second.metrics) - self.assertEqual(first.task_id_to_start_time,{}) + self.assertEqual(first.task_id_to_start_time, {}) self.assertEqual(second.task_id_to_start_time, {}) From e3439f481d35f7f77197a7428109c92378001dd0 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Mon, 11 Mar 2024 18:53:31 +0000 Subject: [PATCH 4/7] * Changelog stub entry, PR # to follow --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e841a0bdc8..2a71475c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Version 1.23.0/0.44b0 (2024-02-23) +- `opentelemetry-instrumentation-celery` Allow Celery instrumentation to be installed multiple times + ([#XXXX](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/XXXX)) - Drop support for 3.7 ([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2151)) - `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector From 62e1b4c4ce8064ad531d11e00b895aac9b1ead24 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Mon, 11 Mar 2024 19:39:00 +0000 Subject: [PATCH 5/7] * updating the pullrequest number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a71475c1e..5d17534c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Version 1.23.0/0.44b0 (2024-02-23) - `opentelemetry-instrumentation-celery` Allow Celery instrumentation to be installed multiple times - ([#XXXX](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/XXXX)) + ([#2342](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2342)) - Drop support for 3.7 ([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2151)) - `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector From fa61334fcc2aa3deee1185fff7587c6d2c1752f9 Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Tue, 12 Mar 2024 14:27:06 +0000 Subject: [PATCH 6/7] * remove superfluous constructor --- .../src/opentelemetry/instrumentation/celery/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 30382b282a..10ccca1270 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -116,9 +116,6 @@ class CeleryInstrumentor(BaseInstrumentor): metrics = None task_id_to_start_time = {} - def __init__(self): - super().__init__() - def instrumentation_dependencies(self) -> Collection[str]: return _instruments From 871390a59094e09099216dd7923c0721f09b41ff Mon Sep 17 00:00:00 2001 From: Markus Jonsson Date: Tue, 12 Mar 2024 20:57:43 +0000 Subject: [PATCH 7/7] * moving Change log to unreleased section --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d17534c2d..673623d89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Fixed +- `opentelemetry-instrumentation-celery` Allow Celery instrumentation to be installed multiple times + ([#2342](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2342)) - Align gRPC span status codes to OTEL specification ([#1756](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1756)) ## Version 1.23.0/0.44b0 (2024-02-23) -- `opentelemetry-instrumentation-celery` Allow Celery instrumentation to be installed multiple times - ([#2342](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2342)) - Drop support for 3.7 ([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2151)) - `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector