|
11 | 11 |
|
12 | 12 | from celery import Celery, VERSION |
13 | 13 | from celery.bin import worker |
14 | | -from celery.signals import task_success |
15 | 14 |
|
16 | 15 | try: |
17 | 16 | from unittest import mock # python 3.3 and above |
@@ -360,7 +359,7 @@ def dummy_task(self): |
360 | 359 | # TODO: This test is hanging when running test with `tox --parallel auto`. Find out why and fix it! |
361 | 360 | @pytest.mark.skip |
362 | 361 | @pytest.mark.forked |
363 | | -def test_redis_backend_trace_propagation(init_celery, capture_events_forksafe, tmpdir): |
| 362 | +def test_redis_backend_trace_propagation(init_celery, capture_events_forksafe): |
364 | 363 | celery = init_celery(traces_sample_rate=1.0, backend="redis", debug=True) |
365 | 364 |
|
366 | 365 | events = capture_events_forksafe() |
@@ -493,17 +492,36 @@ def test_task_headers(celery): |
493 | 492 | "sentry-monitor-check-in-id": "123abc", |
494 | 493 | } |
495 | 494 |
|
496 | | - @celery.task(name="dummy_task") |
497 | | - def dummy_task(x, y): |
498 | | - return x + y |
499 | | - |
500 | | - def crons_task_success(sender, **kwargs): |
501 | | - headers = _get_headers(sender) |
502 | | - assert headers == sentry_crons_setup |
503 | | - |
504 | | - task_success.connect(crons_task_success) |
| 495 | + @celery.task(name="dummy_task", bind=True) |
| 496 | + def dummy_task(self, x, y): |
| 497 | + return _get_headers(self) |
505 | 498 |
|
506 | 499 | # This is how the Celery Beat auto-instrumentation starts a task |
507 | 500 | # in the monkey patched version of `apply_async` |
508 | 501 | # in `sentry_sdk/integrations/celery.py::_wrap_apply_async()` |
509 | | - dummy_task.apply_async(args=(1, 0), headers=sentry_crons_setup) |
| 502 | + result = dummy_task.apply_async(args=(1, 0), headers=sentry_crons_setup) |
| 503 | + assert result.get() == sentry_crons_setup |
| 504 | + |
| 505 | + |
| 506 | +def test_baggage_propagation(init_celery): |
| 507 | + celery = init_celery(traces_sample_rate=1.0, release="abcdef") |
| 508 | + |
| 509 | + @celery.task(name="dummy_task", bind=True) |
| 510 | + def dummy_task(self, x, y): |
| 511 | + return _get_headers(self) |
| 512 | + |
| 513 | + with start_transaction() as transaction: |
| 514 | + result = dummy_task.apply_async( |
| 515 | + args=(1, 0), |
| 516 | + headers={"baggage": "custom=value"}, |
| 517 | + ).get() |
| 518 | + |
| 519 | + assert sorted(result["baggage"].split(",")) == sorted( |
| 520 | + [ |
| 521 | + "sentry-release=abcdef", |
| 522 | + "sentry-trace_id={}".format(transaction.trace_id), |
| 523 | + "sentry-environment=production", |
| 524 | + "sentry-sample_rate=1.0", |
| 525 | + "custom=value", |
| 526 | + ] |
| 527 | + ) |
0 commit comments