Skip to content

Commit

Permalink
Wrap instrument and uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Jul 19, 2024
1 parent 4018ac4 commit a56b835
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/otel_integrations/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from celery.worker.worker import WorkController
from dirty_equals import IsStr
from inline_snapshot import snapshot
from opentelemetry.instrumentation.celery import CeleryInstrumentor

import logfire
from logfire.testing import TestExporter
Expand All @@ -32,14 +33,18 @@


@pytest.fixture
def celery_app() -> Celery:
def celery_app() -> Iterator[Celery]:
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')

@app.task(name='tasks.say_hello') # type: ignore
def say_hello(): # type: ignore
return 'hello'

return app
logfire.instrument_celery()
try:
yield app
finally:
CeleryInstrumentor().uninstrument() # type: ignore


@pytest.fixture(autouse=True)
Expand All @@ -49,8 +54,6 @@ def celery_worker(celery_app: Celery) -> Iterator[WorkController]:


def test_instrument_celery(celery_app: Celery, exporter: TestExporter) -> None:
logfire.instrument_celery()

# Send and wait for the task to be executed
result = celery_app.send_task('tasks.say_hello') # type: ignore
value = result.get(timeout=10) # type: ignore
Expand Down

0 comments on commit a56b835

Please sign in to comment.