Skip to content

Commit faef263

Browse files
committed
Remove FormatAsJsonList and replace with individual JsonSerializer calls
1 parent 017ff79 commit faef263

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/Sentry.Extensions.AI/SentryAISpanEnricher.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ private static void PopulateToolCallsInfo(IList<AIContent> contents, ISpan span)
145145

146146
private static string FormatAvailableTools(IList<AITool> tools)
147147
{
148-
return FormatAsJsonList(tools, tool => new
148+
return JsonSerializer.Serialize(tools.Select(tool => new
149149
{
150150
name = tool.Name,
151151
description = tool.Description
152-
});
152+
}));
153153
}
154154

155155
private static string FormatRequestMessage(ChatMessage[] messages)
156156
{
157-
return FormatAsJsonList(messages, message =>
157+
return JsonSerializer.Serialize(messages.Select(message =>
158158
{
159159
var content = message.Role == ChatRole.Tool ? FunctionResultToObject(message.Contents) : message.Text;
160160

@@ -163,7 +163,7 @@ private static string FormatRequestMessage(ChatMessage[] messages)
163163
role = message.Role,
164164
content
165165
};
166-
});
166+
}));
167167

168168
object FunctionResultToObject(IList<AIContent> toolContents)
169169
{
@@ -189,7 +189,7 @@ object FunctionResultToObject(IList<AIContent> toolContents)
189189

190190
private static string FormatFunctionCallContent(FunctionCallContent[] content)
191191
{
192-
return FormatAsJsonList(content, c =>
192+
return JsonSerializer.Serialize(content.Select(c =>
193193
{
194194
string argumentsJson;
195195
try
@@ -207,11 +207,6 @@ private static string FormatFunctionCallContent(FunctionCallContent[] content)
207207
type = "function_call",
208208
arguments = argumentsJson
209209
};
210-
});
211-
}
212-
213-
private static string FormatAsJsonList<T>(IEnumerable<T> items, Func<T, object> selector)
214-
{
215-
return JsonSerializer.Serialize(items.Select(selector));
210+
}));
216211
}
217212
}

0 commit comments

Comments
 (0)