Skip to content

Commit aa8ae2e

Browse files
reiktarshalevr
andauthored
Celery duplicated instrumentation (#2342)
* * Adding (failing) testcase to cover Issue #2029 * * 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. * * black formatting * * Changelog stub entry, PR # to follow * * updating the pullrequest number * * remove superfluous constructor * * moving Change log to unreleased section --------- Co-authored-by: Shalev Roda <[email protected]>
1 parent 1e0b11f commit aa8ae2e

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
### Fixed
11+
- `opentelemetry-instrumentation-celery` Allow Celery instrumentation to be installed multiple times
12+
([#2342](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2342))
1113
- Align gRPC span status codes to OTEL specification ([#1756](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1756))
1214

1315
## Version 1.23.0/0.44b0 (2024-02-23)

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ def keys(self, carrier):
113113

114114

115115
class CeleryInstrumentor(BaseInstrumentor):
116-
def __init__(self):
117-
super().__init__()
118-
self.metrics = None
119-
self.task_id_to_start_time = {}
116+
metrics = None
117+
task_id_to_start_time = {}
120118

121119
def instrumentation_dependencies(self) -> Collection[str]:
122120
return _instruments
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from opentelemetry.instrumentation.celery import CeleryInstrumentor
18+
19+
20+
class TestUtils(unittest.TestCase):
21+
def test_duplicate_instrumentaion(self):
22+
first = CeleryInstrumentor()
23+
first.instrument()
24+
second = CeleryInstrumentor()
25+
second.instrument()
26+
CeleryInstrumentor().uninstrument()
27+
self.assertIsNotNone(first.metrics)
28+
self.assertIsNotNone(second.metrics)
29+
self.assertEqual(first.task_id_to_start_time, {})
30+
self.assertEqual(second.task_id_to_start_time, {})

0 commit comments

Comments
 (0)