Add metadata parameter to score_current_span and score_current_trace #1501
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.
Summary
This PR adds an optional
metadataparameter to bothscore_current_spanandscore_current_tracemethods, bringing these convenience methods to feature parity with the underlyingcreate_scoremethod which already supports metadata.Changes
metadata: Optional[Any] = Noneparameter to all overloads ofscore_current_spanmetadata: Optional[Any] = Noneparameter to all overloads ofscore_current_tracecreate_scorecallsMotivation
The
create_scoremethod already supports attaching metadata to scores, but the convenience methodsscore_current_spanandscore_current_tracedid not expose this parameter. This made it impossible to attach metadata when using these convenience methods without falling back to the lower-levelcreate_scoreAPI.Example Usage
Before (not possible):
After:
Test plan
create_scoreImportant
Add optional
metadataparameter toscore_current_spanandscore_current_traceinclient.py, updating docstrings and examples.metadata: Optional[Any] = Noneparameter to all overloads ofscore_current_spanandscore_current_traceinclient.py.metadataparameter tocreate_scorecalls inscore_current_spanandscore_current_trace.score_current_spanandscore_current_traceto includemetadataparameter.metadatausage.This description was created by
for b55d88a. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Added optional
metadataparameter toscore_current_spanandscore_current_traceconvenience methods, bringing them to feature parity with the underlyingcreate_scoremethod.Key Changes:
metadata: Optional[Any] = Noneparameter to all overloads and implementations of both methodscreate_scorecallsImpact:
create_scoreAPINoneConfidence Score: 5/5
create_scoreandScoreBody, so this PR simply exposes it through convenience methods. All parameter additions are optional with defaultNonevalues, ensuring backward compatibility. The implementation correctly passes metadata through to the underlyingcreate_scorecalls. Existing tests will continue to pass since metadata is optional.Important Files Changed
score_current_spanandscore_current_traceconvenience methods, matching the existingcreate_scoreAPI. Changes include type hints, docstrings, and passing metadata through to underlying calls.Sequence Diagram
sequenceDiagram participant User participant score_current_span participant score_current_trace participant create_score participant ScoreBody participant ResourceManager User->>score_current_span: score_current_span(name, value, metadata, ...) score_current_span->>score_current_span: Get current span context score_current_span->>score_current_span: Extract trace_id and observation_id score_current_span->>create_score: create_score(trace_id, observation_id, name, value, metadata, ...) User->>score_current_trace: score_current_trace(name, value, metadata, ...) score_current_trace->>score_current_trace: Get current span context score_current_trace->>score_current_trace: Extract trace_id score_current_trace->>create_score: create_score(trace_id, name, value, metadata, ...) create_score->>ScoreBody: new ScoreBody(id, traceId, observationId, name, value, metadata, ...) ScoreBody-->>create_score: ScoreBody instance create_score->>create_score: Create score event create_score->>ResourceManager: add_score_task(event) ResourceManager-->>create_score: Task queued create_score-->>User: Score created