Skip to content

Conversation

@CLowbrow
Copy link
Contributor

No description provided.

@CLowbrow CLowbrow requested a review from ibolmo January 21, 2026 00:26
@CLowbrow CLowbrow changed the title [WIP] Python trace scoring candidate Python trace scoring candidate Jan 21, 2026
@CLowbrow CLowbrow marked this pull request as ready for review January 21, 2026 00:26
Copy link
Collaborator

@ibolmo ibolmo left a comment

Choose a reason for hiding this comment

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

i think it's just otel that needs a follow-up, but check my other comments ...

if expected is not None:
score = 1.0 if output == expected else 0.0

if trace:
Copy link
Collaborator

Choose a reason for hiding this comment

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

as a user why/when would trace ever be none?

:return: A function that can be used as a task or scorer.
"""
# Disable span cache since remote function spans won't be in the local cache
_internal_get_global_state().span_cache.disable()
Copy link
Collaborator

Choose a reason for hiding this comment

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

may be too indirect. if the remote function spans are not in the cache what's the big deal in checking the cache?

assert state.span_cache.disabled is False

# Call init_function
f = init_function("test-project", "test-function")
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is a bit odd that loading a function will cause a cache to be disabled.

root_span.log(output=output, metadata=metadata, tags=tags)

# Create trace object for scorers
from braintrust.trace import LocalTrace
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think we have a circ. dep so i'd move this to the top of the file

"""
self._otel_flush_callback = callback

async def flush_otel(self) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

where is this called? you probably need to find the right spot to call this and/or register_otel_flush

aside.. we solved this well with flush async. seems like we're in a similar pattern here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

one option is to insert quickly in mermory and on need to flush you then block to flush.

https://stackoverflow.com/a/29593596

if not line:
continue
try:
record_dict = json.loads(line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe consider some starts_with and maybe prepending the span_id/root_id... etc to avoid too many json.loads

"root_span_id": self._root_span_id,
}

async def get_spans(self, span_type: Optional[list[str]] = None) -> list[SpanData]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

give the option to disable the cache

span_parents=self.span_parents,
span_attributes=serializable_partial_record.get("span_attributes"),
)
self.state.span_cache.queue_write(self.root_span_id, self.span_id, cached_span)
Copy link
Collaborator

Choose a reason for hiding this comment

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

there could a performant problem if we write a lot to filesystem. would be nice to queue an amount and do bulk inserts to files to avoid read/write to filesystem

SpanFetchFn = Callable[[Optional[list[str]]], Awaitable[list[SpanData]]]


class CachedSpanFetcher:
Copy link
Collaborator

Choose a reason for hiding this comment

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

future should we consider fetchign and saving the data locally

@CLowbrow CLowbrow merged commit 51bb20b into main Jan 21, 2026
65 checks passed
@CLowbrow CLowbrow deleted the alex/trace-in-scorer-python branch January 21, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants