Repository navigation
feat(tasks): send the current span as ParentSpanId in taskSourceMetadata [ACTN-11909] #1948
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
base: main
Are you sure you want to change the base?
Changes from all commits
218747a
a84b8b5
6d6a93a
404dcf9
0ef02b5
873c095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| import asyncio | ||
| import logging | ||
| import os | ||
| import uuid | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.trace import format_span_id | ||
| from uipath.core.feature_flags import ( | ||
| JIT_ESCALATION_APPS_FEATURE_FLAG, | ||
| FeatureFlags, | ||
| ) | ||
| from uipath.core.tracing import traced | ||
| from uipath.core.tracing.span_utils import UiPathSpanUtils | ||
|
|
||
| from uipath.platform.constants import ( | ||
| ENV_TENANT_ID, | ||
|
|
@@ -23,6 +27,8 @@ | |
| from .task_schema import TaskSchema | ||
| from .tasks import Task, TaskRecipient, TaskRecipientType | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _ensure_string_value(value: Any) -> str: | ||
| """Convert any value to a string for use in field Value.""" | ||
|
|
@@ -190,6 +196,17 @@ def _apply_priority_labels_and_actionable_toggle( | |
| payload["isActionableMessageEnabled"] = is_actionable_message_enabled | ||
|
|
||
|
|
||
| def _current_span_id() -> Optional[str]: | ||
| try: | ||
| span = UiPathSpanUtils.get_external_current_span() or trace.get_current_span() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's get_external?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get_external_current_span() returns the span the agents runtime registers with UiPathSpanUtils, which is the Escalation span during an escalation. As said followed the way span_id is taken here: #1948 (comment) |
||
| span_context = span.get_span_context() | ||
| if span_context.is_valid and span_context.span_id: | ||
| return format_span_id(span_context.span_id) | ||
| except Exception: | ||
| logger.debug("Could not read the current span id", exc_info=True) | ||
| return None | ||
|
|
||
|
|
||
| def _apply_task_source( | ||
| payload: Dict[str, Any], | ||
| source_name: str, | ||
|
|
@@ -210,6 +227,7 @@ def _apply_task_source( | |
| trace_id = UiPathConfig.trace_id | ||
| if not (project_id and trace_id): | ||
| return | ||
| parent_span_id = _current_span_id() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| payload["taskSource"] = { | ||
| "sourceName": source_name, | ||
| "sourceId": project_id, | ||
|
|
@@ -218,6 +236,7 @@ def _apply_task_source( | |
| "FolderKey": UiPathConfig.folder_key, | ||
| "JobKey": UiPathConfig.job_key, | ||
| "ProcessKey": UiPathConfig.process_uuid, | ||
| **({"ParentSpanId": parent_span_id} if parent_span_id else {}), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be behind a feature flag, same as the LLM spans ( |
||
| **(custom_metadata or {}), | ||
| }, | ||
| "jobId": UiPathConfig.job_key, | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
we already do this exact lookup inline in
_inject_trace_context(common/_base_service.py, external span or OTel current span, thenformat_span_id). and_add_tracingin_processes_service.pybuilds ParentSpanId too, but only from the OTel span, so it can give a different parent than this one.can we move this into
common(e.g._SpanUtils.current_span_id()) and reuse it there instead of adding a third copy?