Skip to content
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

Should celery add a span link instead? #3002

Open
Kludex opened this issue Nov 14, 2024 · 2 comments
Open

Should celery add a span link instead? #3002

Kludex opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Kludex
Copy link

Kludex commented Nov 14, 2024

Describe your environment

Currently, the celery task that is executing gets the context from the headers, and attaches it to the new span:

token = context_api.attach(tracectx) if tracectx is not None else None
logger.debug("prerun signal start task_id=%s", task_id)
operation_name = f"{_TASK_RUN}/{task.name}"
span = self._tracer.start_span(
operation_name, context=tracectx, kind=trace.SpanKind.CONSUMER
)

I don't think this is the correct behavior. It should actually be a span link - according to the docs:

Links exist so that you can associate one span with one or more spans, implying a causal relationship. For example, let’s say we have a distributed system where some operations are tracked by a trace.

Which is exactly this case.

When a web framework triggers a celery task, it shouldn't be on the same trace. It's already a new one... But they are linked through the span link.

Would you like to implement a fix?

Yes

@Kludex Kludex added the bug Something isn't working label Nov 14, 2024
@samuelcolvin
Copy link
Contributor

agreed, I think this is exactly what span links are for.

@unflxw
Copy link
Contributor

unflxw commented Nov 14, 2024

To add to the agreement, note that this is the behaviour speciified in the OpenTelemetry Semantic Conventions for Messaging Spans (see "Trace structure" and "Examples")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants