getsentry / getsentry/sentry-python

Tracing of Celery tasks does not work with Signatures

Đang mở
#1,416 3 bình luận 1 reaction 1 người được giao Được @alexander-alderman-webb nhận Xem trên GitHub
Improvement Integration: Celery Python Traces
Ngôn ngữ chính
Python
Star
2.2k
Fork
669
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
213

Mô tả

### How do you use Sentry?

Sentry Saas (sentry.io)

### Version

1.5.10

### Steps to Reproduce

The python sentry_sdk celery integration uses `_wrap_apply_async` to wrap the `celery.Task.apply_async` method. However it does not wrap celery Signatures as these have their own `apply_async` method defined in the celery package in `celery/canvas.py`. This means that tasks defined using signatures are not traced.

To reproduce:
```
import sentry_sdk
import os
from sentry_sdk.integrations.celery import CeleryIntegration

sentry_sdk.init(os.getenv('SENTRY_DSN'), integrations=[CeleryIntegration()], traces_sample_rate=1.0, debug=True)

group_result = celery.group([
celery.signature('foo', kwargs=kwargs),
celery.signature('bar', kwargs=kwargs)
]).apply_async()
```
This does not produce traces. Alternatively,
```
import sentry_sdk
import os
from sentry_sdk.integrations.celery import CeleryIntegration
from celery.app.task import Task

sentry_sdk.init(os.getenv('SENTRY_DSN'), integrations=[CeleryIntegration()], traces_sample_rate=1.0, debug=True)

# Not wrapped by sentry sdk
print(celery.group.apply_async.__code__)

# Wrapped by sentry sdk
print(Task.apply_async.__code__)
```

Running the following fixes the issue:
```
import celery
from sentry_sdk.integrations.celery import _wrap_apply_async

celery.group.apply_async = _wrap_apply_async(celery.group.apply_async)
celery.chunks.apply_async = _wrap_apply_async(celery.chunks.apply_async)
celery.chain.apply_async = _wrap_apply_async(celery.chain.apply_async)
celery.chord.apply_async = _wrap_apply_async(celery.chord.apply_async)
Signature.apply_async = _wrap_apply_async(Signature.apply_async)
```

### Expected Result

Transactions visible in the UI.

### Actual Result

No transaction visible. Stepping through the code with a debugger, the function created with _wrap_apply_async is not called as the `Signature.apply_async` method is not wrapped.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.