Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public abstract class AbstractTelemetryBuilder {

private static final int MAX_PROPERTY_KEY_LENGTH = 150;
private static final int MAX_PROPERTY_VALUE_LENGTH = 8192;
private static final int MAX_GENAI_PROPERTY_VALUE_LENGTH = 256 * 1024; // 256 KB

// gen_ai properties can contain large payloads (e.g. full conversation messages,
// tool definitions) that should not be truncated
private static final Set<String> TRUNCATION_EXEMPT_PROPERTY_KEYS = new HashSet<>(asList("gen_ai.input.messages",
// tool definitions) that are truncated at a higher limit (256 KB)
private static final Set<String> GENAI_PROPERTY_KEYS = new HashSet<>(asList("gen_ai.input.messages",
Comment on lines +26 to +30
"gen_ai.output.messages", "gen_ai.system_instructions", "gen_ai.tool.definitions", "gen_ai.tool.call.arguments",
"gen_ai.tool.call.result", "gen_ai.evaluation.explanation"));

Expand Down Expand Up @@ -89,8 +90,9 @@ public void addProperty(@Nullable String key, @Nullable String value) {
// TODO (trask) log
return;
}
if (TRUNCATION_EXEMPT_PROPERTY_KEYS.contains(key)) {
getProperties().put(key, value);
if (GENAI_PROPERTY_KEYS.contains(key)) {
getProperties().put(key,
TelemetryTruncation.truncatePropertyValue(value, MAX_GENAI_PROPERTY_VALUE_LENGTH, key));
} else {
getProperties().put(key, TelemetryTruncation.truncatePropertyValue(value, MAX_PROPERTY_VALUE_LENGTH, key));
Comment on lines +93 to 97
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,28 @@ public void regularPropertyIsTruncatedAt8192() {
"gen_ai.tool.call.arguments",
"gen_ai.tool.call.result",
"gen_ai.evaluation.explanation" })
public void genAiPropertyIsNotTruncated(String key) {
public void genAiPropertyIsTruncatedAt256KB(String key) {
MessageTelemetryBuilder builder = MessageTelemetryBuilder.create();
int size256KB = 256 * 1024;
String longValue = repeat("a", size256KB + 10000);
builder.addProperty(key, longValue);

TelemetryItem item = builder.build();
Map<String, String> properties = getProperties(item);
assertEquals(size256KB, properties.get(key).length());
Comment on lines +40 to +46
}

@ParameterizedTest
@ValueSource(
strings = {
"gen_ai.input.messages",
"gen_ai.output.messages",
"gen_ai.system_instructions",
"gen_ai.tool.definitions",
"gen_ai.tool.call.arguments",
"gen_ai.tool.call.result",
"gen_ai.evaluation.explanation" })
public void genAiPropertyUnder256KBIsNotTruncated(String key) {
MessageTelemetryBuilder builder = MessageTelemetryBuilder.create();
String longValue = repeat("a", 50000);
builder.addProperty(key, longValue);
Expand Down
Loading