Skip to content

Commit

Permalink
Make it work with old and new newrelic versions (#2999)
Browse files Browse the repository at this point in the history
* Make it work with old and new newrelic versions
  • Loading branch information
antonpirker committed Apr 22, 2024
1 parent d9d8799 commit 411c9f3
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/integrations/celery/test_celery.py
Expand Up @@ -418,11 +418,24 @@ def dummy_task(self):
@pytest.mark.parametrize("newrelic_order", ["sentry_first", "sentry_last"])
def test_newrelic_interference(init_celery, newrelic_order, celery_invocation):
def instrument_newrelic():
import celery.app.trace as celery_mod
from newrelic.hooks.application_celery import instrument_celery_execute_trace

assert hasattr(celery_mod, "build_tracer")
instrument_celery_execute_trace(celery_mod)
try:
# older newrelic versions
from newrelic.hooks.application_celery import (
instrument_celery_execute_trace,
)
import celery.app.trace as celery_trace_module

assert hasattr(celery_trace_module, "build_tracer")
instrument_celery_execute_trace(celery_trace_module)

except ImportError:
# newer newrelic versions
from newrelic.hooks.application_celery import instrument_celery_app_base
import celery.app as celery_app_module

assert hasattr(celery_app_module, "Celery")
assert hasattr(celery_app_module.Celery, "send_task")
instrument_celery_app_base(celery_app_module)

if newrelic_order == "sentry_first":
celery = init_celery()
Expand Down

0 comments on commit 411c9f3

Please sign in to comment.