Skip to content

Commit 3e9ec40

Browse files
authored
Merge pull request #7997 from dengyh/refactor/trace_improve
refactor: 修复定时任务trace不连通的问题 --story=126421543
2 parents 2be1927 + c1ccd6f commit 3e9ec40

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

app_desc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ modules:
189189
plan: 4C1G5R
190190
replicas: 2
191191
cworker:
192-
command: python manage.py celery worker -Q pipeline_additional_task,pipeline_additional_task_priority,node_auto_retry,timeout_node_execute,timeout_nodes_record,task_callback -n common_worker@%h -P threads -c 6 -l info
192+
command: celery worker -A blueapps.core.celery -P threads -Q pipeline_additional_task,pipeline_additional_task_priority,node_auto_retry,timeout_node_execute,timeout_nodes_record,task_callback -n common_worker@%h -c 6 -l info
193193
plan: 4C1G5R
194194
replicas: 2
195195
er-e:

gcloud/core/trace.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def propagate_attributes(attributes: dict):
6363
provider.add_span_processor(AttributeInjectionSpanProcessor(attributes))
6464

6565

66+
def append_attributes(attributes: dict):
67+
"""追加属性到span上
68+
69+
:param attributes: 需要追加的属性
70+
"""
71+
current_span = trace.get_current_span()
72+
for key, value in attributes.items():
73+
current_span.set_attribute(f"bk_sops.{key}", value)
74+
75+
6676
@contextmanager
6777
def start_trace(span_name: str, propagate: bool = False, **attributes):
6878
"""Start a trace

gcloud/periodictask/signals/handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from gcloud.constants import PROJECT, TaskCreateMethod
2424
from gcloud.core.models import EngineConfig
25+
from gcloud.core.trace import CallFrom, append_attributes, propagate_attributes
2526
from gcloud.periodictask.models import PeriodicTaskHistory
2627
from gcloud.shortcuts.message import send_periodic_task_message
2728
from gcloud.taskflow3.domains.auto_retry import AutoRetryNodeStrategyCreator
@@ -45,6 +46,10 @@ def pre_periodic_task_start_handler(sender, periodic_task, pipeline_instance, **
4546
engine_ver=periodic_task.extra_info.get("engine_ver", EngineConfig.ENGINE_VER_V1),
4647
)
4748

49+
# 设置传播到后台所有Span的公共属性
50+
propagate_attributes({"project_id": task.project.id, "call_from": CallFrom.BACKEND.value, "task_id": task.id})
51+
append_attributes({"executor": task.executor})
52+
4853
task.record_and_get_executor_proxy(task.executor or periodic_task.creator)
4954

5055
# crete auto retry strategy

0 commit comments

Comments
 (0)