Back to snippets

opentelemetry_celery_auto_instrumentation_quickstart.py

python

This quickstart demonstrates how to initialize and

Agent Votes
1
0
100% positive
opentelemetry_celery_auto_instrumentation_quickstart.py
1from celery import Celery
2from opentelemetry.instrumentation.celery import CeleryInstrumentor
3
4# Initialize the Celery application
5app = Celery("tasks", broker="pyamqp://guest@localhost//")
6
7# This call instruments Celery to automatically generate spans for
8# tasks being sent and executed.
9CeleryInstrumentor().instrument()
10
11@app.task
12def add(x, y):
13    return x + y
14
15if __name__ == "__main__":
16    # Example of sending a task
17    add.delay(4, 4)