Skip to content

Commit 3421588

Browse files
author
Emanuele Palazzetti
committed
[celery] safe-guard for double instrumentation
1 parent 99d717d commit 3421588

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ddtrace/contrib/celery/app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ def patch_app(app, pin=None):
1818
"""Attach the Pin class to the application and connect
1919
our handlers to Celery signals.
2020
"""
21+
if getattr(app, '__datadog_patch', False):
22+
return
23+
setattr(app, '__datadog_patch', True)
24+
25+
# attach the PIN object
2126
pin = pin or Pin(service=WORKER_SERVICE, app=APP, app_type=AppTypes.worker)
2227
pin.onto(app)
23-
28+
# connect to the Signal framework
2429
signals.task_prerun.connect(trace_prerun)
2530
signals.task_postrun.connect(trace_postrun)
2631
signals.before_task_publish.connect(trace_before_publish)
@@ -33,6 +38,10 @@ def unpatch_app(app):
3338
"""Remove the Pin instance from the application and disconnect
3439
our handlers from Celery signal framework.
3540
"""
41+
if not getattr(app, '__datadog_patch', False):
42+
return
43+
setattr(app, '__datadog_patch', False)
44+
3645
pin = Pin.get_from(app)
3746
if pin is not None:
3847
delattr(app, _DD_PIN_NAME)

0 commit comments

Comments
 (0)