Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

aspecto-io/aspecto-celery-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Installs:

pip install opentelemetry-exporter-otlp
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-instrumentation-celery
pip install redis
# optional if not installed - pip install celery

Sample task file

This is the task.py that defines the celery task and adds a task to the queue in redis. It uses the instrument function that resides in tracing.py file that you can copy to your own repo.

from celery import Celery
from tracing import instrument

instrument()
app = Celery('tasks', broker_url='redis://localhost:6379/0')

@app.task
def add(x, y):
    return x + y

add.delay(2, 3)

Running your celery task:

Take the aspecto token from the settings in aspecto.io and put it here as env var. Also, replace OTEL_SERVICE_NAME with the relevant service name Also, replace the word task after celery -A with the file name that contains your celery task. same as

OTEL_SERVICE_NAME=service-name OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otelcol.aspecto.io:4317 OTEL_EXPORTER_OTLP_HEADERS=Authorization=aspecto-token celery -A task worker -l INFO --concurrency=1

If you encounter encoding issues: this is the solution(launch in current shell): https://stackoverflow.com/questions/36651680/click-will-abort-further-execution-because-python-3-was-configured-to-use-ascii

export LC_ALL=de_DE.utf-8
export LANG=de_DE.utf-8

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages