Repository navigation
fix(eval): report scores on resumed Evaluation and Eval Set Run spans #1950
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
Open
Chibionos
wants to merge
1
commit into
main
Choose a base branch
from
fix/eval-resume-scores
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+323
−219
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/uipath/src/uipath/eval/runtime/_resumable_spans.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """Eval spans that outlive a suspended job and are finished by the resuming one.""" | ||
|
|
||
| from contextlib import asynccontextmanager | ||
| from typing import Any, AsyncIterator, cast | ||
|
|
||
| from opentelemetry.sdk.trace import ReadableSpan, Tracer, TracerProvider | ||
| from opentelemetry.sdk.trace.id_generator import IdGenerator | ||
| from opentelemetry.trace import Span | ||
|
|
||
| from uipath.runtime import UiPathRuntimeStorageProtocol | ||
|
|
||
| _NAMESPACE = "eval_parent_span" | ||
|
|
||
|
|
||
| class _SavedIdGenerator(IdGenerator): | ||
| def __init__(self, trace_id: int, span_id: int) -> None: | ||
| self._trace_id = trace_id | ||
| self._span_id = span_id | ||
|
|
||
| def generate_trace_id(self) -> int: | ||
| return self._trace_id | ||
|
|
||
| def generate_span_id(self) -> int: | ||
| return self._span_id | ||
|
|
||
|
|
||
| @asynccontextmanager | ||
| async def start_resumable_span( | ||
| tracer_provider: TracerProvider, | ||
| storage: UiPathRuntimeStorageProtocol | None, | ||
| runtime_id: str, | ||
| key: str, | ||
| *, | ||
| resume: bool, | ||
| name: str, | ||
| attributes: dict[str, Any], | ||
| ) -> AsyncIterator[Span]: | ||
| """Start a span, or on resume re-open the one the suspended job saved under `key`.""" | ||
| tracer = tracer_provider.get_tracer(__name__) | ||
| start_time = None | ||
| saved = await _load(storage, runtime_id, key) if resume else None | ||
| # The trace backend upserts by span id, so this replaces the suspended job's output. | ||
| if saved: | ||
| cast(Tracer, tracer).id_generator = _SavedIdGenerator( | ||
| int(saved["trace_id"], 16), int(saved["span_id"], 16) | ||
| ) | ||
| start_time = saved.get("start_time") | ||
|
|
||
| with tracer.start_as_current_span( | ||
| name, attributes=attributes, start_time=start_time | ||
|
Comment on lines
+49
to
+50
|
||
| ) as span: | ||
| await _save(storage, runtime_id, key, span) | ||
| yield span | ||
|
|
||
|
|
||
| async def _load( | ||
| storage: UiPathRuntimeStorageProtocol | None, runtime_id: str, key: str | ||
| ) -> dict[str, Any] | None: | ||
| if storage is None: | ||
| return None | ||
| return await storage.get_value(runtime_id=runtime_id, namespace=_NAMESPACE, key=key) | ||
|
|
||
|
|
||
| async def _save( | ||
| storage: UiPathRuntimeStorageProtocol | None, | ||
| runtime_id: str, | ||
| key: str, | ||
| span: Span, | ||
| ) -> None: | ||
| if storage is None: | ||
| return | ||
| span_context = span.get_span_context() | ||
| await storage.set_value( | ||
| runtime_id=runtime_id, | ||
| namespace=_NAMESPACE, | ||
| key=key, | ||
| value={ | ||
| "trace_id": format(span_context.trace_id, "032x"), | ||
| "span_id": format(span_context.span_id, "016x"), | ||
| # Absent on a NonRecordingSpan (SDK disabled). | ||
| "start_time": getattr(cast(ReadableSpan, span), "start_time", None), | ||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In a long-lived worker,
UiPathTraceManagerreuses the global tracer provider across jobs, so assigning a fixed generator to this cached tracer persists after the resumed evaluation completes. A later non-resume job does not replace the generator becausesavedis false, causing its Eval Set Run and Evaluation spans to reuse the prior evaluation's trace/span IDs; this can overwrite prior trace data and even give a child the same span ID as its parent. Avoid mutating the shared tracer or restore its original generator after creating the resumed span.Useful? React with 👍 / 👎.