Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/sentry/taskworker/workerchild.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,18 @@ def _execute_activation(task_func: Task[Any, Any], activation: TaskActivation) -
name=activation.taskname,
origin="taskworker",
)
sampling_context = {
"taskworker": {
"task": activation.taskname,
}
}
with (
track_memory_usage(
"taskworker.worker.memory_change",
tags={"namespace": activation.namespace, "taskname": activation.taskname},
),
sentry_sdk.isolation_scope(),
sentry_sdk.start_transaction(transaction),
sentry_sdk.start_transaction(transaction, custom_sampling_context=sampling_context),
):
transaction.set_data(
"taskworker-task", {"args": args, "kwargs": kwargs, "id": activation.id}
Expand Down
6 changes: 6 additions & 0 deletions src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ def traces_sampler(sampling_context):
if task_name in SAMPLED_TASKS:
return SAMPLED_TASKS[task_name]

if "taskworker" in sampling_context:
task_name = sampling_context["taskworker"].get("task")

if task_name in SAMPLED_TASKS:
return SAMPLED_TASKS[task_name]

# Default to the sampling rate in settings
return float(settings.SENTRY_BACKEND_APM_SAMPLING or 0)

Expand Down
Loading