Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions clients/python/src/taskbroker_client/worker/workerchild.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
TaskActivation,
TaskActivationStatus,
)
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.crons import MonitorStatus, capture_checkin

from taskbroker_client.app import import_app
Expand Down Expand Up @@ -658,30 +658,25 @@ def _execute_activation(
if "__start_time" in kwargs:
kwargs.pop("__start_time")

try:
with contextlib.ExitStack() as stack:
with metrics.timer(
"taskworker.worker.context_rebuild.duration",
tags={
"namespace": activation.namespace,
"taskname": activation.taskname,
},
):
for hook in context_hooks:
stack.enter_context(hook.on_execute(headers))
if task_func.pass_headers:
if "headers" in kwargs:
raise TypeError(
f"Task '{task_func.name}' has pass_headers=True, but 'headers' was passed in kwargs. "
"The 'headers' parameter is injected by the worker and cannot be passed by the caller."
)
task_func(*args, headers=headers, **kwargs)
else:
task_func(*args, **kwargs)
transaction.set_status(SPANSTATUS.OK)
except Exception:
transaction.set_status(SPANSTATUS.INTERNAL_ERROR)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this being set in the new code? Does the sdk do this automatically?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the SDK. It's set in Span.__exit__() (or StreamedSpan.__exit__()) in the SDK (invoked when the context manager exits). The link to the former is below.

https://github.com/getsentry/sentry-python/blob/3a50950e632d9923f45a9b6fb18d89e1f27badad/sentry_sdk/tracing.py#L395

raise
with contextlib.ExitStack() as stack:
with metrics.timer(
"taskworker.worker.context_rebuild.duration",
tags={
"namespace": activation.namespace,
"taskname": activation.taskname,
},
):
for hook in context_hooks:
stack.enter_context(hook.on_execute(headers))
if task_func.pass_headers:
if "headers" in kwargs:
raise TypeError(
f"Task '{task_func.name}' has pass_headers=True, but 'headers' was passed in kwargs. "
"The 'headers' parameter is injected by the worker and cannot be passed by the caller."
)
task_func(*args, headers=headers, **kwargs)
else:
task_func(*args, **kwargs)
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Comment thread
alexander-alderman-webb marked this conversation as resolved.

def record_task_execution(
activation: TaskActivation,
Expand Down
Loading