-
Notifications
You must be signed in to change notification settings - Fork 73
python: add celery distributed tracing example #96
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
Open
Kyle-Verhoog
wants to merge
1
commit into
master
Choose a base branch
from
kylev/celery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 0 additions & 4 deletions
4
python/celery4.1/producer.py → python/celery/celery4.1/producer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,4 @@ | ||
| import time | ||
| import random | ||
|
|
||
| from celery import shared_task | ||
| from ddtrace import tracer | ||
|
|
||
| from consumer import add | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .env | ||
| .venv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FROM python:3.8-slim | ||
|
|
||
| RUN apt-get update && apt-get install -y git | ||
|
|
||
| ENV PYTHONUNBUFFERED 1 | ||
|
|
||
| WORKDIR /code | ||
| COPY ./requirements.txt /code | ||
|
|
||
| RUN pip install -r requirements.txt --src /usr/local/src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import random | ||
| import time | ||
|
|
||
| from celery import Celery, shared_task | ||
| from ddtrace import tracer | ||
|
|
||
|
|
||
| @tracer.wrap() | ||
| def consumer_work(): | ||
| time.sleep(random.uniform(0, 0.02)) | ||
|
|
||
|
|
||
| @shared_task | ||
| def add(x, y): | ||
| for _ in range(0, 5): | ||
| consumer_work() | ||
| return x + y | ||
|
|
||
|
|
||
| app = Celery("consumer", broker="redis://redis", backend="redis://redis") |
52 changes: 52 additions & 0 deletions
52
python/celery/celery_distributed_tracing/docker-compose.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| version: '3' | ||
|
|
||
| services: | ||
| redis: | ||
| image: redis:5.0.6-alpine | ||
|
|
||
| producer: | ||
| build: | ||
| context: ./ | ||
| dockerfile: ./Dockerfile | ||
| depends_on: | ||
| - redis | ||
| volumes: | ||
| - .:/code | ||
| environment: | ||
| - DATADOG_TRACE_AGENT_HOSTNAME=datadog | ||
| - DD_CELERY_DISTRIBUTED_TRACING_ENABLED=true | ||
| - DATADOG_TRACE_DEBUG=true | ||
| - DD_SERVICE=producer | ||
| - DD_ENV=celery-example | ||
| command: ddtrace-run python producer.py | ||
|
|
||
| consumer: | ||
| build: | ||
| context: ./ | ||
| dockerfile: ./Dockerfile | ||
| depends_on: | ||
| - redis | ||
| volumes: | ||
| - .:/code | ||
| environment: | ||
| - DATADOG_TRACE_AGENT_HOSTNAME=datadog | ||
| - DD_CELERY_DISTRIBUTED_TRACING_ENABLED=true | ||
| - DATADOG_TRACE_DEBUG=true | ||
| - DD_SERVICE=consumer | ||
| - DD_ENV=celery-example | ||
| command: ddtrace-run celery -A consumer worker --loglevel=info | ||
|
|
||
| datadog: | ||
| image: datadog/agent:latest | ||
| environment: | ||
| - DD_HOSTNAME=trace-example | ||
| - DD_API_KEY=${DD_API_KEY} | ||
| - DD_APM_ENABLED=true | ||
| - DD_BIND_HOST=0.0.0.0 | ||
| ports: | ||
| - 8125 | ||
| - 8126 | ||
| volumes: | ||
| - /var/run/docker.sock:/var/run/docker.sock | ||
| # - /proc/:/host/proc/:ro | ||
| # - /sys/fs/cgroup:/host/sys/fs/cgroup:r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import random | ||
| import time | ||
|
|
||
| from ddtrace import tracer | ||
|
|
||
| from consumer import add | ||
|
|
||
|
|
||
| @tracer.wrap() | ||
| def prod_work(): | ||
| time.sleep(random.uniform(0, 0.05)) | ||
|
|
||
|
|
||
| while True: | ||
| with tracer.trace("myapp.request"): | ||
| # Send off the task | ||
| result = add.apply_async((4, 4)) | ||
|
|
||
| # Do some work in the meantime | ||
| for _ in range(3): | ||
| prod_work() | ||
|
|
||
| # Get the result | ||
| result.get() | ||
|
|
||
| # Do some more work | ||
| for _ in range(2): | ||
| prod_work() | ||
|
|
||
| time.sleep(0.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| amqp==2.5.2 | ||
| billiard==3.6.3.0 | ||
| celery==4.4.2 | ||
| -e git://github.com/thieman/dd-trace-py.git@69d6cfe419468e8a22710068cb74d55694f1d311#egg=ddtrace | ||
| importlib-metadata==1.6.0 | ||
| kombu==4.6.8 | ||
| msgpack==1.0.0 | ||
| pytz==2019.3 | ||
| redis==3.4.1 | ||
| vine==1.3.0 | ||
| zipp==3.1.0 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: update this to 0.37 when released