Skip to content

Commit 837e8a3

Browse files
authored
Merge pull request #48 from braintrustdata/fix/missing_scorer_purpose_tag
Add purpose tag to Eval score spans
2 parents b06777a + 6a9c8ea commit 837e8a3

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/main/java/dev/braintrust/devserver/Devserver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ private void setScoreSpanAttributes(
607607
Map<String, Object> scoreSpanAttrs = new LinkedHashMap<>();
608608
scoreSpanAttrs.put("type", "score");
609609
scoreSpanAttrs.put("name", scorerName);
610+
scoreSpanAttrs.put("purpose", "scorer");
610611
if (braintrustGeneration != null) {
611612
scoreSpanAttrs.put("generation", braintrustGeneration);
612613
}

src/main/java/dev/braintrust/eval/Eval.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ private void recordScores(
230230
Map<String, Object> spanAttrs = new LinkedHashMap<>();
231231
spanAttrs.put("type", "score");
232232
spanAttrs.put("name", scorer.getName());
233+
spanAttrs.put("purpose", "scorer");
233234
scoreSpan.setAttribute("braintrust.span_attributes", toJson(spanAttrs));
234235
var scoresJson = toJson(scorerScores);
235236
scoreSpan.setAttribute("braintrust.output_json", scoresJson);

src/test/java/dev/braintrust/devserver/DevserverTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ void testStreamingEval() throws Exception {
433433
assertNotNull(spanAttrsJson, "Score span should have span_attributes");
434434
JsonNode spanAttrs = JSON_MAPPER.readTree(spanAttrsJson);
435435
assertEquals("score", spanAttrs.get("type").asText());
436+
assertEquals("scorer", spanAttrs.get("purpose").asText());
436437
assertEquals("test-gen-1", spanAttrs.get("generation").asText());
437438

438439
// Scorer name should be either simple_scorer or the remote scorer

src/test/java/dev/braintrust/eval/EvalTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ public void evalOtelTraceWithProperAttributes() {
104104
numRootSpans.get() * 4,
105105
spans.size(),
106106
"each eval case should make four spans (one per scorer)");
107+
108+
// All score spans should have purpose=scorer in span_attributes
109+
var scoreSpans =
110+
spans.stream()
111+
.filter(
112+
s -> {
113+
var attrs =
114+
s.getAttributes()
115+
.get(
116+
AttributeKey.stringKey(
117+
"braintrust.span_attributes"));
118+
return attrs != null && attrs.contains("\"type\":\"score\"");
119+
})
120+
.toList();
121+
assertFalse(scoreSpans.isEmpty(), "should have score spans");
122+
for (var scoreSpan : scoreSpans) {
123+
var spanAttrsJson =
124+
scoreSpan
125+
.getAttributes()
126+
.get(AttributeKey.stringKey("braintrust.span_attributes"));
127+
assertTrue(
128+
spanAttrsJson.contains("\"purpose\":\"scorer\""),
129+
"score span should have purpose=scorer in span_attributes: " + spanAttrsJson);
130+
}
107131
}
108132

109133
boolean isFruitOrVegetable(String str) {

0 commit comments

Comments
 (0)