Skip to content

Commit 66acee1

Browse files
committed
Fix pylint and Sphinx CI failures
- Add __init__ to CeleryInstrumentor and CeleryWorkerInstrumentor to satisfy attribute-defined-outside-init (W0201) - Remove generic type parameter from CeleryGetter to fix Sphinx reference resolution for Request - Split test_metrics.py into two files to stay under 1000 lines - Mark _run_task as @staticmethod (R6301) - Initialize einfo before try block (E0601) - Add CHANGELOG entries
1 parent 7385de2 commit 66acee1

4 files changed

Lines changed: 737 additions & 668 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Bump `pylint` to `4.0.5`
1717
([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244))
18+
- `opentelemetry-instrumentation-celery`: Add task and worker lifecycle metrics matching Celery Flower
19+
([#4439](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4439))
20+
21+
### Fixed
22+
23+
- `opentelemetry-instrumentation-celery`: Fix memory leak in `task_id_to_start_time` dict never being cleaned up
24+
([#4439](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4439))
1825

1926
### Breaking changes
2027

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def init_celery_tracing(*args, **kwargs):
134134
_TASK_NAME_KEY = "celery.task_name"
135135

136136

137-
class CeleryGetter(Getter["Request"]):
137+
class CeleryGetter(Getter):
138138
def get(self, carrier: "Request", key: str) -> list[str] | None:
139139
value = getattr(carrier, key, None)
140140
if value is None:
@@ -280,6 +280,14 @@ class CeleryInstrumentor(BaseInstrumentor):
280280
Must be initialized in the worker subprocess via the
281281
``worker_process_init`` signal."""
282282

283+
def __init__(self) -> None:
284+
super().__init__()
285+
self.metrics: Optional[_CeleryTaskMetrics] = None
286+
self.task_id_to_start_time: dict = {}
287+
self.task_id_to_received_time: dict = {}
288+
self.prefetched_task_id_to_labels: dict = {}
289+
self.executing_task_id_to_worker: dict = {}
290+
283291
def instrumentation_dependencies(self) -> Collection[str]:
284292
return _instruments
285293

@@ -810,6 +818,11 @@ def init_worker_metrics(sender, instance, conf, **kwargs):
810818
CeleryWorkerInstrumentor().instrument()
811819
"""
812820

821+
def __init__(self) -> None:
822+
super().__init__()
823+
self.metrics: Optional[_CeleryWorkerMetrics] = None
824+
self.online_workers: set = set()
825+
813826
def instrumentation_dependencies(self) -> Collection[str]:
814827
return _instruments
815828

0 commit comments

Comments
 (0)