@@ -3,6 +3,7 @@ package datadog.trace.llmobs.domain
3
3
import datadog.trace.agent.tooling.TracerInstaller
4
4
import datadog.trace.api.DDTags
5
5
import datadog.trace.api.IdGenerationStrategy
6
+ import datadog.trace.api.llmobs.LLMObs
6
7
import datadog.trace.api.llmobs.LLMObsSpan
7
8
import datadog.trace.api.llmobs.LLMObsTags
8
9
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
@@ -199,11 +200,65 @@ class DDLLMObsSpanTest extends DDSpecification{
199
200
assert Tags . LLMOBS_LLM_SPAN_KIND . equals(innerSpan. getTag(LLMOBS_TAG_PREFIX + " span.kind" ))
200
201
201
202
assert null == innerSpan. getTag(" input" )
202
- def expectedInput = Arrays . asList(Maps . of(" content" , input))
203
- assert expectedInput. equals(innerSpan. getTag(INPUT ))
203
+ def spanInput = innerSpan. getTag(INPUT )
204
+ assert spanInput instanceof List
205
+ assert ((List )spanInput). size() == 1
206
+ assert spanInput. get(0 ) instanceof LLMObs.LLMMessage
207
+ def expectedInputMsg = LLMObs.LLMMessage . from(" unknown" , input)
208
+ assert expectedInputMsg. getContent(). equals(input)
209
+ assert expectedInputMsg. getRole(). equals(" unknown" )
210
+ assert expectedInputMsg. getToolCalls(). equals(null )
211
+
204
212
assert null == innerSpan. getTag(" output" )
205
- def expectedOutput = Arrays . asList(Maps . of(" content" , output))
206
- assert expectedOutput. equals(innerSpan. getTag(OUTPUT ))
213
+ def spanOutput = innerSpan. getTag(OUTPUT )
214
+ assert spanOutput instanceof List
215
+ assert ((List )spanOutput). size() == 1
216
+ assert spanOutput. get(0 ) instanceof LLMObs.LLMMessage
217
+ def expectedOutputMsg = LLMObs.LLMMessage . from(" unknown" , output)
218
+ assert expectedOutputMsg. getContent(). equals(output)
219
+ assert expectedOutputMsg. getRole(). equals(" unknown" )
220
+ assert expectedOutputMsg. getToolCalls(). equals(null )
221
+ }
222
+
223
+ def " test llm span with messages" () {
224
+ setup :
225
+ def test = givenALLMObsSpan(Tags . LLMOBS_LLM_SPAN_KIND , " test-span" )
226
+
227
+ when :
228
+ def inputMsg = LLMObs.LLMMessage . from(" user" , " input" )
229
+ def outputMsg = LLMObs.LLMMessage . from(" assistant" , " output" , Arrays . asList(LLMObs.ToolCall . from(" weather-tool" , " function" , " 6176241000" , Maps . of(" location" , " paris" ))))
230
+ // initial set
231
+ test. annotateIO(Arrays . asList(inputMsg), Arrays . asList(outputMsg))
232
+
233
+ then :
234
+ def innerSpan = (AgentSpan )test. span
235
+ assert Tags . LLMOBS_LLM_SPAN_KIND . equals(innerSpan. getTag(LLMOBS_TAG_PREFIX + " span.kind" ))
236
+
237
+ assert null == innerSpan. getTag(" input" )
238
+ def spanInput = innerSpan. getTag(INPUT )
239
+ assert spanInput instanceof List
240
+ assert ((List )spanInput). size() == 1
241
+ def spanInputMsg = spanInput. get(0 )
242
+ assert spanInputMsg instanceof LLMObs.LLMMessage
243
+ assert spanInputMsg. getContent(). equals(inputMsg. getContent())
244
+ assert spanInputMsg. getRole(). equals(" user" )
245
+ assert spanInputMsg. getToolCalls(). equals(null )
246
+
247
+ assert null == innerSpan. getTag(" output" )
248
+ def spanOutput = innerSpan. getTag(OUTPUT )
249
+ assert spanOutput instanceof List
250
+ assert ((List )spanOutput). size() == 1
251
+ def spanOutputMsg = spanOutput. get(0 )
252
+ assert spanOutputMsg instanceof LLMObs.LLMMessage
253
+ assert spanOutputMsg. getContent(). equals(outputMsg. getContent())
254
+ assert spanOutputMsg. getRole(). equals(" assistant" )
255
+ assert spanOutputMsg. getToolCalls(). size() == 1
256
+ def toolCall = spanOutputMsg. getToolCalls(). get(0 )
257
+ assert toolCall. getName(). equals(" weather-tool" )
258
+ assert toolCall. getType(). equals(" function" )
259
+ assert toolCall. getToolID(). equals(" 6176241000" )
260
+ def expectedToolArgs = Maps . of(" location" , " paris" )
261
+ assert toolCall. getArguments(). equals(expectedToolArgs)
207
262
}
208
263
209
264
private LLMObsSpan givenALLMObsSpan (String kind , name ){
0 commit comments