Skip to content

Make it work with old and new newrelic versions #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
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