mirror of
https://github.com/SigNoz/signoz.git
synced 2026-10-15 14:40:41 +01:00
Compare commits
1 Commits
feat/ai-tr
...
feat/ai-tr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48dabdd9ab |
@@ -12,25 +12,29 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FormatterSemconv = "semconv"
|
||||
FormatterOpenInference = "openinference"
|
||||
FormatterOpenAIChat = "openai.chat"
|
||||
FormatterText = "text"
|
||||
FormatterGeneric = "generic"
|
||||
FormatterSemconv = "semconv"
|
||||
FormatterOpenInference = "openinference"
|
||||
FormatterOpenAIChat = "openai.chat"
|
||||
FormatterOpenAIResponses = "openai.responses"
|
||||
FormatterText = "text"
|
||||
FormatterGeneric = "generic"
|
||||
)
|
||||
|
||||
var dataURL = regexp.MustCompile(`^data:([^;,]+);base64,(.+)$`)
|
||||
|
||||
// Provider spellings of the finish reasons; the enum values themselves pass through. tool_calls and
|
||||
// function_call are OpenAI's, end_turn, stop_sequence, max_tokens and tool_use Anthropic's, tool-calls the
|
||||
// Vercel AI SDK's:
|
||||
// function_call are OpenAI's, completed, failed, cancelled, incomplete and max_output_tokens the Responses
|
||||
// status and incomplete reason, end_turn, stop_sequence, max_tokens and tool_use Anthropic's, tool-calls
|
||||
// the Vercel AI SDK's:
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L44782
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69691
|
||||
// https://platform.claude.com/docs/en/api/messages
|
||||
// https://github.com/vercel/ai/blob/a5e92fe3c692f8e152fe1eb9ef50a4e734ad0ffb/packages/provider/src/language-model/v2/language-model-v2-finish-reason.ts
|
||||
var finishReasonAliases = map[string]FinishReason{
|
||||
"tool_calls": FinishReasonToolCall, "function_call": FinishReasonToolCall, "tool-calls": FinishReasonToolCall, "tool_use": FinishReasonToolCall,
|
||||
"end_turn": FinishReasonStop, "stop_sequence": FinishReasonStop,
|
||||
"max_tokens": FinishReasonLength,
|
||||
"end_turn": FinishReasonStop, "stop_sequence": FinishReasonStop, "completed": FinishReasonStop,
|
||||
"max_tokens": FinishReasonLength, "max_output_tokens": FinishReasonLength,
|
||||
"failed": FinishReasonError, "cancelled": FinishReasonError, "incomplete": FinishReasonError,
|
||||
}
|
||||
|
||||
// FormattedMessages is the OTel GenAI view of one span's messages; Warnings holds what the converter could
|
||||
@@ -146,6 +150,12 @@ func (f *formatting) side(value any, role Role) (OutputMessages, string) {
|
||||
}
|
||||
}
|
||||
case map[string]any:
|
||||
switch {
|
||||
case isResponsesResponse(v):
|
||||
return f.responsesResponse(v), FormatterOpenAIResponses
|
||||
case isResponsesRequest(v):
|
||||
return f.responsesRequest(v), FormatterOpenAIResponses
|
||||
}
|
||||
if choices, ok := v["choices"].([]any); ok {
|
||||
return f.openAIChatResponse(choices), FormatterOpenAIChat
|
||||
}
|
||||
@@ -360,9 +370,11 @@ func systemParts(value any) Parts {
|
||||
return nil
|
||||
}
|
||||
|
||||
// contentPart converts one OpenAI content block, which semconv parts may also carry; a text part
|
||||
// in the semconv spelling has content where OpenAI has text. A block of any other type is kept
|
||||
// as sent.
|
||||
// contentPart converts one content block in the OpenAI Chat Completions or Responses spelling, which
|
||||
// semconv parts may also carry; a text part in the semconv spelling has content where OpenAI has text.
|
||||
// A block of any other type is kept as sent.
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L53827
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L57589
|
||||
func contentPart(item any) Part {
|
||||
p, ok := item.(map[string]any)
|
||||
if !ok {
|
||||
@@ -372,14 +384,14 @@ func contentPart(item any) Part {
|
||||
return part(GenericPart{"type": FormatterGeneric, "content": stringOf(item)})
|
||||
}
|
||||
switch stringOf(p["type"]) {
|
||||
case "text":
|
||||
case "text", "input_text", "output_text", "summary_text":
|
||||
if p["text"] == nil {
|
||||
return part(textPart(stringOf(p["content"])))
|
||||
}
|
||||
return part(textPart(stringOf(p["text"])))
|
||||
case "refusal":
|
||||
return part(textPart(stringOf(p["refusal"])))
|
||||
case "image_url":
|
||||
case "image_url", "input_image":
|
||||
url := stringOf(p["image_url"])
|
||||
if ref, ok := p["image_url"].(map[string]any); ok {
|
||||
url = stringOf(ref["url"])
|
||||
@@ -387,10 +399,20 @@ func contentPart(item any) Part {
|
||||
if url != "" {
|
||||
return part(mediaPart(url, ModalityImage))
|
||||
}
|
||||
if id := stringOf(p["file_id"]); id != "" {
|
||||
return part(FilePart{Type: PartTypeFile, Modality: ModalityImage, FileID: id})
|
||||
}
|
||||
case "file":
|
||||
if f, ok := filePart(p); ok {
|
||||
return f
|
||||
}
|
||||
case "input_file":
|
||||
if f, ok := filePart(map[string]any{"file": p}); ok {
|
||||
return f
|
||||
}
|
||||
if url := stringOf(p["file_url"]); url != "" {
|
||||
return part(mediaPart(url, ModalityDocument))
|
||||
}
|
||||
}
|
||||
return part(GenericPart(p))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package aiobservabilitytypes
|
||||
|
||||
import "strings"
|
||||
|
||||
// Format: OpenAI Responses, a request {input, instructions} or a response {output, status} of items:
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L47597
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69691
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L53834
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L57596
|
||||
// Written by: gateways recording raw Responses bodies, and the raw calls OpenInference records for the
|
||||
// Responses API and the OpenAI Agents SDK when its flattened messages are absent.
|
||||
// Handled: message items with input_text, output_text, refusal, input_image and input_file content;
|
||||
// function_call and custom_tool_call with their outputs; reasoning summaries; compaction; every other
|
||||
// *_call item as a server tool call and *_output item as its response; the status and incomplete_details
|
||||
// of a response.
|
||||
// Dropped: reasoning encrypted_content, item ids. Not yet: input_audio content.
|
||||
|
||||
// isResponsesRequest tells a Responses request from an embeddings one, which also carries input and
|
||||
// model: items are objects, and only Responses takes instructions or tools.
|
||||
func isResponsesRequest(m map[string]any) bool {
|
||||
if m["input"] == nil {
|
||||
return false
|
||||
}
|
||||
if m["instructions"] != nil || m["tools"] != nil || m["previous_response_id"] != nil {
|
||||
return true
|
||||
}
|
||||
items, ok := m["input"].([]any)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
_, isItem := firstObject(items)
|
||||
return isItem
|
||||
}
|
||||
|
||||
func isResponsesResponse(m map[string]any) bool {
|
||||
if _, ok := m["output"].([]any); !ok {
|
||||
return false
|
||||
}
|
||||
return stringOf(m["object"]) == "response" || m["status"] != nil
|
||||
}
|
||||
|
||||
func (f *formatting) responsesRequest(m map[string]any) OutputMessages {
|
||||
var msgs OutputMessages
|
||||
if parts := systemParts(m["instructions"]); len(parts) > 0 {
|
||||
msgs = append(msgs, OutputMessage{Role: RoleSystem, Parts: parts})
|
||||
}
|
||||
switch input := m["input"].(type) {
|
||||
case string:
|
||||
msgs = append(msgs, OutputMessage{Role: RoleUser, Parts: Parts{part(textPart(input))}})
|
||||
case []any:
|
||||
msgs = append(msgs, foldAssistant(f.responsesItems(input))...)
|
||||
}
|
||||
return msgs
|
||||
}
|
||||
|
||||
// responsesResponse folds the output items into one message: the API returns a single choice. The
|
||||
// finish reason is the incomplete_details reason, else the status:
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69763
|
||||
func (f *formatting) responsesResponse(m map[string]any) OutputMessages {
|
||||
output, _ := m["output"].([]any)
|
||||
msgs := foldAssistant(f.responsesItems(output))
|
||||
if len(msgs) == 0 {
|
||||
return msgs
|
||||
}
|
||||
last := &msgs[len(msgs)-1]
|
||||
if details, ok := m["incomplete_details"].(map[string]any); ok {
|
||||
last.FinishReason = finishReason(stringOf(details["reason"]))
|
||||
} else if status := stringOf(m["status"]); status != "" {
|
||||
last.FinishReason = finishReason(status)
|
||||
}
|
||||
return msgs
|
||||
}
|
||||
|
||||
// responsesItems converts items one message each; the caller folds assistant runs.
|
||||
func (f *formatting) responsesItems(items []any) OutputMessages {
|
||||
msgs := make(OutputMessages, 0, len(items))
|
||||
for _, item := range items {
|
||||
m, ok := item.(map[string]any)
|
||||
if !ok {
|
||||
if s, ok := item.(string); ok {
|
||||
msgs = append(msgs, OutputMessage{Role: RoleUser, Parts: Parts{part(textPart(s))}})
|
||||
continue
|
||||
}
|
||||
msgs = append(msgs, genericMessage(item))
|
||||
continue
|
||||
}
|
||||
typ := stringOf(m["type"])
|
||||
switch {
|
||||
case typ == "" || typ == "message":
|
||||
msgs = append(msgs, f.openAIChatMessage(m))
|
||||
case typ == "function_call" || typ == "custom_tool_call":
|
||||
args := m["arguments"]
|
||||
if args == nil {
|
||||
args = m["input"]
|
||||
}
|
||||
call := ToolCallRequestPart{Type: PartTypeToolCall, Name: stringOf(m["name"]), ID: optionalString(m["call_id"]), Arguments: decode(args)}
|
||||
msgs = append(msgs, OutputMessage{Role: RoleAssistant, Parts: Parts{part(call)}})
|
||||
case typ == "function_call_output" || typ == "custom_tool_call_output":
|
||||
result := ToolCallResponsePart{Type: PartTypeToolCallResponse, ID: optionalString(m["call_id"]), Response: toolResponse(m["output"])}
|
||||
msgs = append(msgs, OutputMessage{Role: RoleTool, Parts: Parts{part(result)}})
|
||||
case typ == "reasoning":
|
||||
if p, ok := reasoningItem(m); ok {
|
||||
msgs = append(msgs, OutputMessage{Role: RoleAssistant, Parts: Parts{p}})
|
||||
}
|
||||
case typ == "compaction":
|
||||
msgs = append(msgs, OutputMessage{Role: RoleAssistant, Parts: Parts{part(CompactionPart{Type: PartTypeCompaction, ID: optionalString(m["id"]), Content: optionalString(m["content"])})}})
|
||||
case strings.HasSuffix(typ, "_call"):
|
||||
call := ServerToolCallPart{Type: PartTypeServerToolCall, Name: strings.TrimSuffix(typ, "_call"), ID: optionalString(m["call_id"]), ServerToolCall: GenericServerToolCall(m)}
|
||||
msgs = append(msgs, OutputMessage{Role: RoleAssistant, Parts: Parts{part(call)}})
|
||||
case strings.HasSuffix(typ, "_output") || typ == "mcp_approval_response":
|
||||
result := ServerToolCallResponsePart{Type: PartTypeServerToolCallResponse, ID: optionalString(m["call_id"]), ServerToolCallResponse: GenericServerToolCallResponse(m)}
|
||||
msgs = append(msgs, OutputMessage{Role: RoleTool, Parts: Parts{part(result)}})
|
||||
default:
|
||||
msgs = append(msgs, OutputMessage{Role: RoleAssistant, Parts: Parts{part(GenericPart(m))}})
|
||||
}
|
||||
}
|
||||
return msgs
|
||||
}
|
||||
|
||||
// reasoningItem joins the summary texts. An item with neither a summary nor encrypted content
|
||||
// carries nothing to show:
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69620
|
||||
func reasoningItem(m map[string]any) (Part, bool) {
|
||||
var texts []string
|
||||
if summary, ok := m["summary"].([]any); ok {
|
||||
for _, item := range summary {
|
||||
if s, ok := item.(map[string]any); ok && stringOf(s["text"]) != "" {
|
||||
texts = append(texts, stringOf(s["text"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(texts) == 0 && stringOf(m["encrypted_content"]) == "" {
|
||||
return Part{}, false
|
||||
}
|
||||
return part(ReasoningPart{Type: PartTypeReasoning, Content: strings.Join(texts, "\n")}), true
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package aiobservabilitytypes
|
||||
|
||||
import "testing"
|
||||
|
||||
// Cases follow the OpenAI Responses schemas; the first mirrors the raw bodies in the SigNoz/scripts
|
||||
// openinference-openai-agents capture, which OpenInference's flattened messages otherwise cover.
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L47597
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69691
|
||||
func TestFormat_OpenAIResponses(t *testing.T) {
|
||||
runFormatCases(t, []formatCase{
|
||||
{
|
||||
// openinference-openai-agents capture, Response span: instructions outside the history, a reasoning
|
||||
// item without a summary, then the message
|
||||
name: "InstructionsAndStringInput_ReasoningWithoutSummaryDropped",
|
||||
input: `{"include": [], "input": [{"content": "A bat and a ball cost $1.10. How much is the ball?", "role": "user"}], "instructions": "You solve problems step by step and give a final answer.", "model": "o3-mini", "tools": []}`,
|
||||
output: `{"id":"resp_1","object":"response","status":"completed","model":"o3-mini-2025-01-31","output":[{"id":"rs_1","summary":[],"type":"reasoning"},{"id":"msg_1","content":[{"annotations":[],"text":"Final Answer: The ball costs $0.05.","type":"output_text","logprobs":[]}],"role":"assistant","status":"completed","type":"message"}],"usage":{"input_tokens":49,"output_tokens":431}}`,
|
||||
wantInput: `[
|
||||
{"role": "system", "parts": [{"type": "text", "content": "You solve problems step by step and give a final answer."}]},
|
||||
{"role": "user", "parts": [{"type": "text", "content": "A bat and a ball cost $1.10. How much is the ball?"}]}
|
||||
]`,
|
||||
wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Final Answer: The ball costs $0.05."}], "finish_reason": "stop"}]`,
|
||||
},
|
||||
{
|
||||
// an InputMessage with every InputContent type, then function and custom tool calls with their
|
||||
// outputs, a compaction item and a computer_call_output
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L53827
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L54142
|
||||
name: "InputItems_EveryContentType_FunctionCallRound",
|
||||
input: `{"model":"gpt-4o-mini","input":[{"role":"user","content":[{"type":"input_text","text":"What is in this image and these files?"},{"type":"input_image","image_url":"https://example.com/duck.jpg","detail":"auto"},{"type":"input_image","file_id":"file-img","detail":"low"},{"type":"input_file","file_id":"file-abc"},{"type":"input_file","filename":"a.pdf","file_data":"data:application/pdf;base64,JVBERi0="},{"type":"input_file","file_url":"https://example.com/a.pdf"}]},{"type":"function_call","call_id":"call_1","name":"get_weather","arguments":"{\"city\":\"Paris\"}"},{"type":"function_call_output","call_id":"call_1","output":"{\"temp_c\":18}"},{"type":"custom_tool_call","call_id":"c1","name":"shell","input":"ls"},{"type":"custom_tool_call_output","call_id":"c1","output":"a.txt"},{"type":"compaction","id":"cmp_1","encrypted_content":"x"},{"type":"computer_call_output","call_id":"cc_1","output":{"type":"computer_screenshot","image_url":"data:image/png;base64,iVBORw0KGgo="}}]}`,
|
||||
wantInput: `[
|
||||
{"role": "user", "parts": [
|
||||
{"type": "text", "content": "What is in this image and these files?"},
|
||||
{"type": "uri", "modality": "image", "uri": "https://example.com/duck.jpg"},
|
||||
{"type": "file", "modality": "image", "file_id": "file-img"},
|
||||
{"type": "file", "modality": "document", "file_id": "file-abc", "mime_type": "application/pdf"},
|
||||
{"type": "blob", "modality": "document", "mime_type": "application/pdf", "content": "JVBERi0="},
|
||||
{"type": "uri", "modality": "document", "uri": "https://example.com/a.pdf"}
|
||||
]},
|
||||
{"role": "assistant", "parts": [{"type": "tool_call", "name": "get_weather", "id": "call_1", "arguments": {"city": "Paris"}}]},
|
||||
{"role": "tool", "parts": [{"type": "tool_call_response", "id": "call_1", "response": {"temp_c": 18}}]},
|
||||
{"role": "assistant", "parts": [{"type": "tool_call", "name": "shell", "id": "c1", "arguments": "ls"}]},
|
||||
{"role": "tool", "parts": [{"type": "tool_call_response", "id": "c1", "response": "a.txt"}]},
|
||||
{"role": "assistant", "parts": [{"type": "compaction", "id": "cmp_1"}]},
|
||||
{"role": "tool", "parts": [{"type": "server_tool_call_response", "id": "cc_1", "server_tool_call_response": {"type": "computer_call_output", "call_id": "cc_1", "output": {"type": "computer_screenshot", "image_url": "data:image/png;base64,iVBORw0KGgo="}}}]}
|
||||
]`,
|
||||
wantOutput: `[]`,
|
||||
},
|
||||
{
|
||||
// output items folded into the single choice: a ReasoningItem summary, a WebSearchToolCall, the
|
||||
// OutputMessage with output_text and refusal, then a FunctionToolCall
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L57596
|
||||
name: "OutputItems_FoldedIntoOneMessage_StatusCompleted",
|
||||
output: `{"id":"resp_2","object":"response","status":"completed","output":[{"id":"rs_1","type":"reasoning","summary":[{"type":"summary_text","text":"Need the weather first."}],"encrypted_content":"gAAA"},{"id":"ws_1","type":"web_search_call","status":"completed","action":{"type":"search","query":"weather Paris"}},{"id":"msg_1","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"Checking.","annotations":[]},{"type":"refusal","refusal":"I cannot do that."}]},{"type":"function_call","call_id":"call_1","name":"get_weather","arguments":"{\"city\":\"Paris\"}","id":"fc_1","status":"completed"}]}`,
|
||||
wantInput: `[]`,
|
||||
wantOutput: `[{"role": "assistant", "parts": [
|
||||
{"type": "reasoning", "content": "Need the weather first."},
|
||||
{"type": "server_tool_call", "name": "web_search", "server_tool_call": {"id": "ws_1", "type": "web_search_call", "status": "completed", "action": {"type": "search", "query": "weather Paris"}}},
|
||||
{"type": "text", "content": "Checking."},
|
||||
{"type": "text", "content": "I cannot do that."},
|
||||
{"type": "tool_call", "name": "get_weather", "id": "call_1", "arguments": {"city": "Paris"}}
|
||||
], "finish_reason": "stop"}]`,
|
||||
},
|
||||
{
|
||||
// https://github.com/openai/openai-openapi/blob/aeb6a041dc56c011ca9f12127ec898f911100aa0/openapi.yaml#L69763
|
||||
name: "IncompleteResponse_FinishFromIncompleteDetails",
|
||||
output: `{"object":"response","status":"incomplete","incomplete_details":{"reason":"max_output_tokens"},"output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Partial"}]}]}`,
|
||||
wantInput: `[]`,
|
||||
wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Partial"}], "finish_reason": "length"}]`,
|
||||
},
|
||||
{
|
||||
name: "StringInput_UserMessage",
|
||||
input: `{"model":"gpt-4o-mini","input":"Say hi","instructions":"Be brief."}`,
|
||||
wantInput: `[{"role": "system", "parts": [{"type": "text", "content": "Be brief."}]}, {"role": "user", "parts": [{"type": "text", "content": "Say hi"}]}]`,
|
||||
wantOutput: `[]`,
|
||||
},
|
||||
{
|
||||
// openinference capture, CreateEmbeddings span: an embeddings request also has input and model
|
||||
name: "EmbeddingsRequest_NotResponses_KeptAsGeneric",
|
||||
input: `{"input": ["observability is the new monitoring"], "model": "text-embedding-3-small", "encoding_format": "base64"}`,
|
||||
warnings: []string{"message format not recognised, kept as generic"},
|
||||
wantInput: `[{"role": "", "parts": [{"type": "generic", "content": "{\"encoding_format\":\"base64\",\"input\":[\"observability is the new monitoring\"],\"model\":\"text-embedding-3-small\"}"}]}]`,
|
||||
wantOutput: `[]`,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -21,7 +21,7 @@ def test_thread_returns_gen_ai_spans_in_order(
|
||||
seed_attribute_evolution("traces", ATTRIBUTE_JSON_ROLLOUT_TIME)
|
||||
now = datetime.now(tz=UTC).replace(microsecond=0)
|
||||
trace_id = TraceIdGenerator.trace_id()
|
||||
root_id, first_llm_id, tool_id, agent_id, second_llm_id, legacy_llm_id, third_llm_id, flattened_llm_id = (TraceIdGenerator.span_id() for _ in range(8))
|
||||
root_id, first_llm_id, tool_id, agent_id, second_llm_id, legacy_llm_id, third_llm_id, flattened_llm_id, responses_llm_id = (TraceIdGenerator.span_id() for _ in range(9))
|
||||
resources = {"service.name": "tracedetail-thread"}
|
||||
first_input = json.dumps([{"role": "user", "parts": [{"type": "text", "content": "weather in Bangalore?"}]}])
|
||||
first_output = json.dumps([{"role": "assistant", "parts": [{"type": "tool_call", "id": "call_1", "name": "get_weather", "arguments": {"city": "Bangalore"}}]}])
|
||||
@@ -81,6 +81,20 @@ def test_thread_returns_gen_ai_spans_in_order(
|
||||
},
|
||||
attribute_write_mode="json_only",
|
||||
),
|
||||
Traces(
|
||||
timestamp=now,
|
||||
trace_id=trace_id,
|
||||
span_id=responses_llm_id,
|
||||
parent_span_id=root_id,
|
||||
name="responses gpt-4o",
|
||||
resources=resources,
|
||||
attributes={
|
||||
"gen_ai.request.model": "gpt-4o",
|
||||
"gen_ai.input.messages": json.dumps({"model": "gpt-4o", "instructions": "Be brief.", "input": [{"role": "user", "content": "bye"}]}),
|
||||
"gen_ai.output.messages": json.dumps({"object": "response", "status": "completed", "output": [{"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "Bye!"}]}]}),
|
||||
},
|
||||
attribute_write_mode="json_only",
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -89,10 +103,10 @@ def test_thread_returns_gen_ai_spans_in_order(
|
||||
assert response.status_code == HTTPStatus.OK, response.text
|
||||
|
||||
thread = response.json()["data"]
|
||||
assert [span["span_id"] for span in thread["spans"]] == [first_llm_id, tool_id, agent_id, second_llm_id, legacy_llm_id, third_llm_id, flattened_llm_id]
|
||||
assert [span["span_id"] for span in thread["spans"]] == [first_llm_id, tool_id, agent_id, second_llm_id, legacy_llm_id, third_llm_id, flattened_llm_id, responses_llm_id]
|
||||
assert "nextCursor" not in thread
|
||||
|
||||
first, tool, agent, input_only, legacy, output_only, flattened = thread["spans"]
|
||||
first, tool, agent, input_only, legacy, output_only, flattened, responses = thread["spans"]
|
||||
assert agent["attributes"]["gen_ai.agent.name"] == "planner"
|
||||
assert agent["formattedInput"] == []
|
||||
assert agent["formattedOutput"] == []
|
||||
@@ -124,6 +138,8 @@ def test_thread_returns_gen_ai_spans_in_order(
|
||||
assert flattened["attributes"]["llm.input_messages.0.message.content"] == "thanks"
|
||||
assert flattened["formattedInput"] == [{"role": "user", "parts": [{"type": "text", "content": "thanks"}]}]
|
||||
assert flattened["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "You're welcome."}], "finish_reason": "stop"}]
|
||||
assert responses["formattedInput"] == [{"role": "system", "parts": [{"type": "text", "content": "Be brief."}]}, {"role": "user", "parts": [{"type": "text", "content": "bye"}]}]
|
||||
assert responses["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "Bye!"}], "finish_reason": "stop"}]
|
||||
|
||||
|
||||
def test_thread_paginates_with_cursors(
|
||||
|
||||
Reference in New Issue
Block a user