SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(tracedetail): format raw Anthropic and Gemini bodies, skip embeddings (#13141)
Nityananda Gohain60bc6ac96f7b
diff --git a/pkg/types/aiobservabilitytypes/message_format.go b/pkg/types/aiobservabilitytypes/message_format.goindex 37c1dff911..1a40842475 100644--- a/pkg/types/aiobservabilitytypes/message_format.go+++ b/pkg/types/aiobservabilitytypes/message_format.go@@ -16,6 +16,8 @@ const (FormatterOpenInference = "openinference"FormatterLangChain = "langchain"FormatterOpenRouter = "openrouter"+ FormatterAnthropic = "anthropic"+ FormatterGemini = "gemini"FormatterOpenAIChat = "openai.chat"FormatterOpenAIResponses = "openai.responses"FormatterText = "text"@@ -26,18 +28,21 @@ 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, 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+// status and incomplete reason, end_turn, stop_sequence, max_tokens, tool_use, refusal and+// model_context_window_exceeded Anthropic's, the upper-case ones Gemini's, tool-calls and content-filter// 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/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/stop_reason.py#L5+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L510// https://github.com/vercel/ai/blob/a5e92fe3c692f8e152fe1eb9ef50a4e734ad0ffb/packages/provider/src/language-model/v2/language-model-v2-finish-reason.tsvar finishReasonAliases = map[string]FinishReason{"tool_calls": FinishReasonToolCall, "function_call": FinishReasonToolCall, "tool-calls": FinishReasonToolCall, "tool_use": FinishReasonToolCall,- "content-filter": FinishReasonContentFilter,- "end_turn": FinishReasonStop, "stop_sequence": FinishReasonStop, "completed": FinishReasonStop,- "max_tokens": FinishReasonLength, "max_output_tokens": FinishReasonLength,- "failed": FinishReasonError, "cancelled": FinishReasonError, "incomplete": FinishReasonError,+ "end_turn": FinishReasonStop, "stop_sequence": FinishReasonStop, "completed": FinishReasonStop,+ "max_tokens": FinishReasonLength, "max_output_tokens": FinishReasonLength, "model_context_window_exceeded": FinishReasonLength,+ "content-filter": FinishReasonContentFilter, "refusal": FinishReasonContentFilter, "safety": FinishReasonContentFilter, "recitation": FinishReasonContentFilter,+ "blocklist": FinishReasonContentFilter, "prohibited_content": FinishReasonContentFilter, "spii": FinishReasonContentFilter, "image_safety": FinishReasonContentFilter,+ "failed": FinishReasonError, "cancelled": FinishReasonError, "incomplete": FinishReasonError, "malformed_function_call": FinishReasonError,}// FormattedMessages is the OTel GenAI view of one span's messages; Warnings holds what the converter could@@ -50,13 +55,17 @@ type FormattedMessages struct {// FormatMessages builds the OTel GenAI view of a span's messages from the formats SDKs write. attributes// is the span's JSON attribute document, nested by key segment, so an object value is whole. Each-// message value is a JSON string or a structured value. OpenInference's flattened messages come first,+// message value is a JSON string or a structured value. An embeddings call has no messages, whatever the+// mapper moved onto the message attributes. OpenInference's flattened messages come first,// then a tool call and its result, then the AI SDK's ai.* keys, then the message attributes, then// openllmetry's flattened prompts and completions. gen_ai.system_instructions leads the// input and gen_ai.response.finish_reasons overrides the finish reasons the converter found, whichever// converter ran.func FormatMessages(attributes map[string]any) FormattedMessages {f := &formatting{attributes: attributes, out: FormattedMessages{Input: InputMessages{}, Output: OutputMessages{}, Warnings: []string{}}}+ if isEmbeddings(attributes) {+ return f.out+ }switch {case f.openInference():case attribute(f.attributes, GenAIToolCallArguments) != nil || attribute(f.attributes, GenAIToolCallResult) != nil:@@ -71,6 +80,17 @@ func FormatMessages(attributes map[string]any) FormattedMessages {return f.out}+// isEmbeddings matches the operation name as the semconv embeddings, openllmetry's llm.request.type+// embedding and OpenInference's span kind EMBEDDING, copied by the mapper, or the AI SDK's ai.embed* ids.+// https://github.com/open-telemetry/semantic-conventions-genai/blob/06ec68e722c45a7218e23ea1bc1339fe4e21ecae/model/gen-ai/registry.yaml#L658+func isEmbeddings(attributes map[string]any) bool {+ switch strings.ToLower(stringOf(attribute(attributes, GenAIOperationName))) {+ case "embeddings", "embedding":+ return true+ }+ return strings.HasPrefix(stringOf(attribute(attributes, vercelOperation)), "ai.embed")+}+type formatting struct {attributes map[string]anyout FormattedMessages@@ -95,11 +115,13 @@ func (f *formatting) messages() {f.warnMixedFormats(inputLabel, outputLabel)}-// OpenRouter's answer object beside the OpenAI chat request it answers is one format, not a mix.+// OpenRouter's answer object or an Anthropic response beside the OpenAI chat request it answers is one+// format, not a mix: an Anthropic request without system and without Anthropic-only blocks reads as an+// OpenAI chat request.func (f *formatting) warnMixedFormats(inputLabel, outputLabel string) {switch {case inputLabel == "" || outputLabel == "" || outputLabel == inputLabel:- case inputLabel == FormatterOpenAIChat && outputLabel == FormatterOpenRouter:+ case inputLabel == FormatterOpenAIChat && (outputLabel == FormatterOpenRouter || outputLabel == FormatterAnthropic):default:f.warn("output formatted as %s, input as %s", outputLabel, inputLabel)}@@ -150,10 +172,14 @@ func (f *formatting) side(value any, role Role) (OutputMessages, string) {switch v := value.(type) {case []any:if first, ok := firstObject(v); ok {- if _, ok := first["parts"]; ok {+ switch {+ case isGeminiContent(first):+ return f.geminiContents(v), FormatterGemini+ case first["parts"] != nil:return f.semconv(v), FormatterSemconv- }- if _, ok := first["role"]; ok {+ case isAnthropicMessages(v):+ return f.anthropicMessages(v), FormatterAnthropic+ case first["role"] != nil:return f.openAIChatMessages(v), FormatterOpenAIChat}}@@ -167,6 +193,16 @@ func (f *formatting) side(value any, role Role) (OutputMessages, string) {return f.responsesResponse(v), FormatterOpenAIResponsescase isResponsesRequest(v):return f.responsesRequest(v), FormatterOpenAIResponses+ case isAnthropicResponse(v):+ return f.anthropicResponse(v), FormatterAnthropic+ case isAnthropicRequest(v):+ return f.anthropicRequest(v), FormatterAnthropic+ case isGeminiResponse(v):+ return f.geminiResponse(v), FormatterGemini+ case isGeminiRequest(v):+ return f.geminiRequest(v), FormatterGemini+ case isGeminiContent(v):+ return OutputMessages{geminiContent(v, role)}, FormatterGemini}if choices, ok := v["choices"].([]any); ok {return f.openAIChatResponse(choices), FormatterOpenAIChat@@ -365,6 +401,28 @@ func textOf(parts Parts) string {return strings.Join(texts, "\n")}+// splitToolResults moves tool_call_response parts out of a message into a tool message before it,+// for APIs that carry tool results inside the next user turn.+func splitToolResults(msg OutputMessage) OutputMessages {+ results, rest := Parts{}, Parts{}+ for _, p := range msg.Parts {+ if _, ok := p.Value.(ToolCallResponsePart); ok {+ results = append(results, p)+ } else {+ rest = append(rest, p)+ }+ }+ if len(results) == 0 {+ return OutputMessages{msg}+ }+ out := OutputMessages{{Role: RoleTool, Parts: results}}+ if len(rest) > 0 {+ msg.Parts = rest+ out = append(out, msg)+ }+ return out+}+// systemParts reads a system prompt given outside the history, a list of parts or a bare string.func systemParts(value any) Parts {switch v := value.(type) {diff --git a/pkg/types/aiobservabilitytypes/message_format_anthropic.go b/pkg/types/aiobservabilitytypes/message_format_anthropic.gonew file mode 100644index 0000000000..0de6b2e22a--- /dev/null+++ b/pkg/types/aiobservabilitytypes/message_format_anthropic.go@@ -0,0 +1,156 @@+package aiobservabilitytypes++import "strings"++// Format: Anthropic Messages, a request {system, messages} or a response {content, stop_reason}:+// https://platform.claude.com/docs/en/api/messages+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/message_create_params.py#L181+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/message_param.py#L28+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/message.py#L91+// Written by: gateways recording raw Anthropic bodies. OpenInference flattens these into+// llm.*_messages, which take precedence.+// Handled: string and block content; text, image and document sources of every type, tool_use,+// tool_result, thinking, redacted_thinking, server_tool_use and the *_tool_result blocks. A tool_result+// inside a user turn becomes a tool message before it.+// Not yet: a request without system and without Anthropic-only blocks is indistinguishable from an+// OpenAI chat request and formats as one.++// Block types only the Messages API has, which tell its message list from an OpenAI chat one:+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/tool_use_block_param.py#L23+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/thinking_block_param.py#L21+var anthropicBlockTypes = map[string]bool{+ "tool_use": true, "tool_result": true, "thinking": true, "redacted_thinking": true, "server_tool_use": true, "document": true,+}++func isAnthropicRequest(m map[string]any) bool {+ messages, ok := m["messages"].([]any)+ if !ok {+ return false+ }+ return m["system"] != nil || isAnthropicMessages(messages)+}++func isAnthropicResponse(m map[string]any) bool {+ if _, ok := m["content"].([]any); !ok {+ return false+ }+ _, hasStop := m["stop_reason"]+ return hasStop || stringOf(m["type"]) == "message"+}++func isAnthropicMessages(list []any) bool {+ for _, item := range list {+ m, _ := item.(map[string]any)+ blocks, _ := m["content"].([]any)+ for _, block := range blocks {+ b, _ := block.(map[string]any)+ typ := stringOf(b["type"])+ if anthropicBlockTypes[typ] || strings.HasSuffix(typ, "_tool_result") || (typ == "image" && b["source"] != nil) {+ return true+ }+ }+ }+ return false+}++func (f *formatting) anthropicRequest(m map[string]any) OutputMessages {+ messages, _ := m["messages"].([]any)+ msgs := f.anthropicMessages(messages)+ if parts := systemParts(m["system"]); len(parts) > 0 {+ return append(OutputMessages{{Role: RoleSystem, Parts: parts}}, msgs...)+ }+ return msgs+}++func (f *formatting) anthropicMessages(list []any) OutputMessages {+ out := make(OutputMessages, 0, len(list))+ for _, item := range list {+ m, ok := item.(map[string]any)+ if !ok {+ out = append(out, genericMessage(item))+ continue+ }+ msg := OutputMessage{Role: role(stringOf(m["role"])), Parts: anthropicContent(m["content"])}+ out = append(out, splitToolResults(msg)...)+ }+ return out+}++// anthropicResponse is one assistant message with the stop reason.+func (f *formatting) anthropicResponse(m map[string]any) OutputMessages {+ msg := OutputMessage{Role: role(stringOf(m["role"])), Parts: anthropicContent(m["content"]), FinishReason: finishReason(stringOf(m["stop_reason"]))}+ if msg.Role.IsZero() {+ msg.Role = RoleAssistant+ }+ return OutputMessages{msg}+}++func anthropicContent(content any) Parts {+ parts := Parts{}+ switch v := content.(type) {+ case string:+ if v != "" {+ parts = append(parts, part(textPart(v)))+ }+ case []any:+ for _, item := range v {+ if b, ok := item.(map[string]any); ok {+ parts = append(parts, anthropicBlock(b))+ } else {+ parts = append(parts, contentPart(item))+ }+ }+ }+ return parts+}++// anthropicBlock converts one content block:+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/tool_result_block_param.py#L29+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/redacted_thinking_block_param.py#L15+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/server_tool_use_block_param.py#L33+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/web_search_tool_result_block_param.py#L22+func anthropicBlock(b map[string]any) Part {+ typ := stringOf(b["type"])+ switch {+ case typ == "text":+ return part(textPart(stringOf(b["text"])))+ case typ == "image" || typ == "document":+ return anthropicSource(b, typ)+ case typ == "tool_use":+ return part(ToolCallRequestPart{Type: PartTypeToolCall, ID: optionalString(b["id"]), Name: stringOf(b["name"]), Arguments: b["input"]})+ case typ == "tool_result":+ return part(ToolCallResponsePart{Type: PartTypeToolCallResponse, ID: optionalString(b["tool_use_id"]), Response: toolResponse(b["content"])})+ case typ == "thinking":+ return part(ReasoningPart{Type: PartTypeReasoning, Content: stringOf(b["thinking"])})+ case typ == "redacted_thinking":+ return part(ReasoningPart{Type: PartTypeReasoning})+ case typ == "server_tool_use":+ return part(ServerToolCallPart{Type: PartTypeServerToolCall, ID: optionalString(b["id"]), Name: stringOf(b["name"]), ServerToolCall: GenericServerToolCall(b)})+ case strings.HasSuffix(typ, "_tool_result"):+ return part(ServerToolCallResponsePart{Type: PartTypeServerToolCallResponse, ID: optionalString(b["tool_use_id"]), ServerToolCallResponse: GenericServerToolCallResponse(b)})+ }+ return part(GenericPart(b))+}++// anthropicSource reads the {source: {type: base64|url|file|text, ...}} of an image or document block:+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/image_block_param.py#L14+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/document_block_param.py#L16+func anthropicSource(b map[string]any, typ string) Part {+ source, _ := b["source"].(map[string]any)+ mime := optionalString(source["media_type"])+ modality := ModalityDocument+ if typ == "image" {+ modality = ModalityImage+ }+ switch stringOf(source["type"]) {+ case "base64":+ return part(BlobPart{Type: PartTypeBlob, Modality: modality, MimeType: mime, Content: stringOf(source["data"])})+ case "url":+ return part(UriPart{Type: PartTypeURI, Modality: modality, MimeType: mime, URI: stringOf(source["url"])})+ case "file":+ return part(FilePart{Type: PartTypeFile, Modality: modality, MimeType: mime, FileID: stringOf(source["file_id"])})+ case "text":+ return part(textPart(stringOf(source["data"])))+ }+ return part(GenericPart(b))+}diff --git a/pkg/types/aiobservabilitytypes/message_format_anthropic_test.go b/pkg/types/aiobservabilitytypes/message_format_anthropic_test.gonew file mode 100644index 0000000000..dec275a721--- /dev/null+++ b/pkg/types/aiobservabilitytypes/message_format_anthropic_test.go@@ -0,0 +1,90 @@+package aiobservabilitytypes++import "testing"++// Cases follow the Anthropic Messages API shapes; no capture in SigNoz/scripts records raw Anthropic+// bodies.+// https://platform.claude.com/docs/en/api/messages+// https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/message_param.py#L28+func TestFormat_Anthropic(t *testing.T) {+ runFormatCases(t, []formatCase{+ {+ // system as a string; end_turn is stop+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/message_create_params.py#L181+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/stop_reason.py#L5+ name: "SystemStringAndText_EndTurn",+ input: `{"model":"claude-sonnet-4-5","max_tokens":1024,"system":"You are terse.","messages":[{"role":"user","content":"Hi"}]}`,+ output: `{"id":"msg_1","type":"message","role":"assistant","model":"claude-sonnet-4-5","content":[{"type":"text","text":"Hello."}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":3}}`,+ wantInput: `[+ {"role": "system", "parts": [{"type": "text", "content": "You are terse."}]},+ {"role": "user", "parts": [{"type": "text", "content": "Hi"}]}+ ]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Hello."}], "finish_reason": "stop"}]`,+ },+ {+ // tool_result sits inside the next user turn, with text beside it+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/tool_result_block_param.py#L29+ name: "ToolRound_ToolResultSplitFromUserTurn",+ input: `{"messages":[{"role":"user","content":"Weather in Oslo?"},{"role":"assistant","content":[{"type":"text","text":"Checking."},{"type":"tool_use","id":"toolu_1","name":"get_weather","input":{"city":"Oslo"}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_1","content":"{\"temp_c\":4}"},{"type":"text","text":"And Bergen?"}]}]}`,+ output: `{"type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_2","name":"get_weather","input":{"city":"Bergen"}}],"stop_reason":"tool_use"}`,+ wantInput: `[+ {"role": "user", "parts": [{"type": "text", "content": "Weather in Oslo?"}]},+ {"role": "assistant", "parts": [{"type": "text", "content": "Checking."}, {"type": "tool_call", "id": "toolu_1", "name": "get_weather", "arguments": {"city": "Oslo"}}]},+ {"role": "tool", "parts": [{"type": "tool_call_response", "id": "toolu_1", "response": {"temp_c": 4}}]},+ {"role": "user", "parts": [{"type": "text", "content": "And Bergen?"}]}+ ]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "tool_call", "id": "toolu_2", "name": "get_weather", "arguments": {"city": "Bergen"}}], "finish_reason": "tool_call"}]`,+ },+ {+ // system as text blocks; every image and document source type; thinking blocks in the history and+ // the answer+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/image_block_param.py#L14+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/document_block_param.py#L16+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/thinking_block_param.py#L21+ name: "MediaSourcesAndThinking_MaxTokens",+ input: `{"system":[{"type":"text","text":"Describe inputs.","cache_control":{"type":"ephemeral"}}],"messages":[{"role":"user","content":[{"type":"image","source":{"type":"base64","media_type":"image/png","data":"iVBORw0KGgo="}},{"type":"image","source":{"type":"url","url":"https://example.com/a.jpg"}},{"type":"document","source":{"type":"file","file_id":"file_1"}},{"type":"document","source":{"type":"text","media_type":"text/plain","data":"plain notes"},"title":"notes"},{"type":"text","text":"What are these?"}]},{"role":"assistant","content":[{"type":"thinking","thinking":"Two images and two documents.","signature":"sig"},{"type":"redacted_thinking","data":"xx"},{"type":"text","text":"Images and documents."}]}]}`,+ output: `{"type":"message","role":"assistant","content":[{"type":"thinking","thinking":"Listing them.","signature":"sig"},{"type":"text","text":"A PNG, a JPEG"}],"stop_reason":"max_tokens"}`,+ wantInput: `[+ {"role": "system", "parts": [{"type": "text", "content": "Describe inputs."}]},+ {"role": "user", "parts": [+ {"type": "blob", "modality": "image", "mime_type": "image/png", "content": "iVBORw0KGgo="},+ {"type": "uri", "modality": "image", "uri": "https://example.com/a.jpg"},+ {"type": "file", "modality": "document", "file_id": "file_1"},+ {"type": "text", "content": "plain notes"},+ {"type": "text", "content": "What are these?"}+ ]},+ {"role": "assistant", "parts": [{"type": "reasoning", "content": "Two images and two documents."}, {"type": "reasoning", "content": ""}, {"type": "text", "content": "Images and documents."}]}+ ]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "reasoning", "content": "Listing them."}, {"type": "text", "content": "A PNG, a JPEG"}], "finish_reason": "length"}]`,+ },+ {+ // server_tool_use with its web_search_tool_result in the same message; refusal is a content filter+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/server_tool_use_block_param.py#L33+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/web_search_tool_result_block_param.py#L22+ // https://github.com/anthropics/anthropic-sdk-python/blob/2a53eaa6966b04560b6a72c28d3ace4389a9ac58/src/anthropic/types/stop_reason.py#L5+ name: "ServerToolUseAndResult_Refusal",+ output: `{"type":"message","role":"assistant","content":[{"type":"server_tool_use","id":"srvtoolu_1","name":"web_search","input":{"query":"otel genai"}},{"type":"web_search_tool_result","tool_use_id":"srvtoolu_1","content":[{"type":"web_search_result","url":"https://opentelemetry.io","title":"OTel"}]},{"type":"text","text":"Found it."}],"stop_reason":"refusal"}`,+ wantInput: `[]`,+ wantOutput: `[{"role": "assistant", "parts": [+ {"type": "server_tool_call", "id": "srvtoolu_1", "name": "web_search", "server_tool_call": {"type": "server_tool_use", "id": "srvtoolu_1", "name": "web_search", "input": {"query": "otel genai"}}},+ {"type": "server_tool_call_response", "id": "srvtoolu_1", "server_tool_call_response": {"type": "web_search_tool_result", "tool_use_id": "srvtoolu_1", "content": [{"type": "web_search_result", "url": "https://opentelemetry.io", "title": "OTel"}]}},+ {"type": "text", "content": "Found it."}+ ], "finish_reason": "content_filter"}]`,+ },+ {+ // a request with neither system nor Anthropic-only blocks is an OpenAI chat request; the+ // response names the format+ name: "PlainRequest_ResponseNamesFormat",+ input: `{"model":"claude-sonnet-4-5","messages":[{"role":"user","content":"Hi"}]}`,+ output: `{"type":"message","role":"assistant","content":[{"type":"text","text":"Hello."}],"stop_reason":"end_turn"}`,+ wantInput: `[{"role": "user", "parts": [{"type": "text", "content": "Hi"}]}]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Hello."}], "finish_reason": "stop"}]`,+ },+ {+ name: "BareMessageList_ToolBlocksNameFormat",+ input: `[{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_1","content":[{"type":"text","text":"sunny"}]}]}]`,+ wantInput: `[{"role": "tool", "parts": [{"type": "tool_call_response", "id": "toolu_1", "response": "sunny"}]}]`,+ wantOutput: `[]`,+ },+ })+}diff --git a/pkg/types/aiobservabilitytypes/message_format_gemini.go b/pkg/types/aiobservabilitytypes/message_format_gemini.gonew file mode 100644index 0000000000..15fd1cce06--- /dev/null+++ b/pkg/types/aiobservabilitytypes/message_format_gemini.go@@ -0,0 +1,165 @@+package aiobservabilitytypes++// Format: Gemini generateContent, a request {contents, systemInstruction} or a response {candidates} of+// Content {role, parts} objects, in the REST camelCase or the SDK snake_case spelling:+// https://ai.google.dev/api/generate-content+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2303+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2626+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L8351+// Written by: gateways recording raw Gemini bodies. OpenInference flattens these into llm.*_messages,+// which take precedence.+// Handled: text, thought text, inlineData, fileData, functionCall, functionResponse; a functionResponse+// inside a user turn becomes a tool message before it. Any other part is kept as sent.+// Not yet: a blocked prompt, promptFeedback without candidates.++func isGeminiRequest(m map[string]any) bool {+ switch m["contents"].(type) {+ case []any, string:+ return true+ }+ return false+}++func isGeminiResponse(m map[string]any) bool {+ _, ok := m["candidates"].([]any)+ return ok+}++// isGeminiContent tells a bare Content from a semconv message: both carry parts, only semconv parts+// have a type.+func isGeminiContent(m map[string]any) bool {+ parts, ok := m["parts"].([]any)+ if !ok {+ return false+ }+ first, ok := firstObject(parts)+ return ok && first["type"] == nil+}++// geminiRequest reads contents and systemInstruction:+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L6527+func (f *formatting) geminiRequest(m map[string]any) OutputMessages {+ var msgs OutputMessages+ if system := geminiSystemInstruction(objectAt(m, "systemInstruction", "system_instruction")); system != nil {+ msgs = append(msgs, *system)+ }+ switch contents := m["contents"].(type) {+ case string:+ msgs = append(msgs, OutputMessage{Role: RoleUser, Parts: Parts{part(textPart(contents))}})+ case []any:+ msgs = append(msgs, f.geminiContents(contents)...)+ }+ return msgs+}++// geminiResponse is one message per candidate with its finish reason.+func (f *formatting) geminiResponse(m map[string]any) OutputMessages {+ candidates, _ := m["candidates"].([]any)+ out := make(OutputMessages, 0, len(candidates))+ for _, item := range candidates {+ candidate, ok := item.(map[string]any)+ if !ok {+ out = append(out, genericMessage(item))+ continue+ }+ content, _ := candidate["content"].(map[string]any)+ msg := geminiContent(content, RoleAssistant)+ msg.FinishReason = finishReason(stringOf(objectAt(candidate, "finishReason", "finish_reason")))+ out = append(out, msg)+ }+ return out+}++// geminiSystemInstruction accepts a string, a Content or a list of parts.+func geminiSystemInstruction(value any) *OutputMessage {+ var parts Parts+ switch v := value.(type) {+ case map[string]any:+ parts = geminiContent(v, RoleSystem).Parts+ case []any:+ parts = geminiParts(v)+ default:+ parts = systemParts(value)+ }+ if len(parts) == 0 {+ return nil+ }+ return &OutputMessage{Role: RoleSystem, Parts: parts}+}++func (f *formatting) geminiContents(list []any) OutputMessages {+ out := make(OutputMessages, 0, len(list))+ for _, item := range list {+ switch v := item.(type) {+ case string:+ out = append(out, OutputMessage{Role: RoleUser, Parts: Parts{part(textPart(v))}})+ case map[string]any:+ out = append(out, splitToolResults(geminiContent(v, RoleUser))...)+ default:+ out = append(out, genericMessage(item))+ }+ }+ return out+}++func geminiContent(c map[string]any, fallback Role) OutputMessage {+ msg := OutputMessage{Role: role(stringOf(c["role"])), Parts: Parts{}}+ if msg.Role.IsZero() {+ msg.Role = fallback+ }+ parts, _ := c["parts"].([]any)+ msg.Parts = geminiParts(parts)+ return msg+}++func geminiParts(list []any) Parts {+ parts := Parts{}+ for _, item := range list {+ if p, ok := item.(map[string]any); ok {+ parts = append(parts, geminiPart(p))+ } else {+ parts = append(parts, contentPart(item))+ }+ }+ return parts+}++// geminiPart converts one Part by the one field it carries:+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2324+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2112+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L1731+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L1830+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2032+func geminiPart(p map[string]any) Part {+ if text, ok := p["text"].(string); ok {+ if thought, _ := p["thought"].(bool); thought {+ return part(ReasoningPart{Type: PartTypeReasoning, Content: text})+ }+ return part(textPart(text))+ }+ if data, ok := objectAt(p, "inlineData", "inline_data").(map[string]any); ok {+ mime := stringOf(objectAt(data, "mimeType", "mime_type"))+ return part(BlobPart{Type: PartTypeBlob, Modality: modalityOf(mime), MimeType: optionalString(mime), Content: stringOf(data["data"])})+ }+ if file, ok := objectAt(p, "fileData", "file_data").(map[string]any); ok {+ mime := stringOf(objectAt(file, "mimeType", "mime_type"))+ return part(UriPart{Type: PartTypeURI, Modality: modalityOf(mime), MimeType: optionalString(mime), URI: stringOf(objectAt(file, "fileUri", "file_uri"))})+ }+ if call, ok := objectAt(p, "functionCall", "function_call").(map[string]any); ok {+ return part(ToolCallRequestPart{Type: PartTypeToolCall, ID: optionalString(call["id"]), Name: stringOf(call["name"]), Arguments: call["args"]})+ }+ if response, ok := objectAt(p, "functionResponse", "function_response").(map[string]any); ok {+ return part(ToolCallResponsePart{Type: PartTypeToolCallResponse, ID: optionalString(response["id"]), Response: response["response"]})+ }+ return part(GenericPart(p))+}++// objectAt reads the first of the key spellings that is set.+func objectAt(m map[string]any, keys ...string) any {+ for _, key := range keys {+ if v, ok := m[key]; ok && v != nil {+ return v+ }+ }+ return nil+}diff --git a/pkg/types/aiobservabilitytypes/message_format_gemini_test.go b/pkg/types/aiobservabilitytypes/message_format_gemini_test.gonew file mode 100644index 0000000000..5b579275c7--- /dev/null+++ b/pkg/types/aiobservabilitytypes/message_format_gemini_test.go@@ -0,0 +1,75 @@+package aiobservabilitytypes++import "testing"++// Cases follow the Gemini generateContent shapes, REST camelCase and SDK snake_case; no capture in+// SigNoz/scripts records raw Gemini bodies.+// https://ai.google.dev/api/generate-content+// https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2303+func TestFormat_Gemini(t *testing.T) {+ runFormatCases(t, []formatCase{+ {+ // systemInstruction as a Content; STOP is stop+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L6527+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L510+ name: "SystemInstructionContent_CandidateText_Stop",+ input: `{"contents":[{"role":"user","parts":[{"text":"Hi"}]}],"systemInstruction":{"parts":[{"text":"You are terse."}]},"generationConfig":{"temperature":0}}`,+ output: `{"candidates":[{"content":{"parts":[{"text":"Hello."}],"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":5,"candidatesTokenCount":2},"modelVersion":"gemini-2.5-flash"}`,+ wantInput: `[+ {"role": "system", "parts": [{"type": "text", "content": "You are terse."}]},+ {"role": "user", "parts": [{"type": "text", "content": "Hi"}]}+ ]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Hello."}], "finish_reason": "stop"}]`,+ },+ {+ // SDK snake_case spelling; the function response sits in the next user turn+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L1830+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2032+ name: "FunctionRoundSnakeCase_ResponseSplitFromUserTurn",+ input: `{"model":"gemini-2.5-pro","contents":[{"role":"user","parts":[{"text":"Weather in Oslo?"}]},{"role":"model","parts":[{"function_call":{"name":"get_weather","args":{"city":"Oslo"}}}]},{"role":"user","parts":[{"function_response":{"name":"get_weather","response":{"temp_c":4}}},{"text":"And Bergen?"}]}],"system_instruction":"Use tools."}`,+ output: `{"candidates":[{"content":{"role":"model","parts":[{"function_call":{"id":"fc_1","name":"get_weather","args":{"city":"Bergen"}}}]},"finish_reason":"STOP"}]}`,+ wantInput: `[+ {"role": "system", "parts": [{"type": "text", "content": "Use tools."}]},+ {"role": "user", "parts": [{"type": "text", "content": "Weather in Oslo?"}]},+ {"role": "assistant", "parts": [{"type": "tool_call", "name": "get_weather", "arguments": {"city": "Oslo"}}]},+ {"role": "tool", "parts": [{"type": "tool_call_response", "response": {"temp_c": 4}}]},+ {"role": "user", "parts": [{"type": "text", "content": "And Bergen?"}]}+ ]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "tool_call", "id": "fc_1", "name": "get_weather", "arguments": {"city": "Bergen"}}], "finish_reason": "stop"}]`,+ },+ {+ // inline and file data, a thought part, an executable code part kept as sent; two candidates, the+ // second stopped for SAFETY+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2112+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L1731+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L2344+ // https://github.com/googleapis/python-genai/blob/78f6d3412caaaed44f99ce57be2d16d0b8c407cb/google/genai/types.py#L510+ name: "MediaAndThought_TwoCandidates",+ input: `{"contents":[{"parts":[{"inlineData":{"mimeType":"image/png","data":"iVBORw0KGgo="}},{"fileData":{"mimeType":"video/mp4","fileUri":"gs://bucket/a.mp4"}},{"text":"Describe."}]}]}`,+ output: `{"candidates":[{"content":{"role":"model","parts":[{"text":"Looking.","thought":true},{"executableCode":{"language":"PYTHON","code":"print(1)"}},{"text":"A logo and a clip."}]},"finishReason":"MAX_TOKENS"},{"content":{"role":"model","parts":[]},"finishReason":"SAFETY"}]}`,+ wantInput: `[{"role": "user", "parts": [+ {"type": "blob", "modality": "image", "mime_type": "image/png", "content": "iVBORw0KGgo="},+ {"type": "uri", "modality": "video", "mime_type": "video/mp4", "uri": "gs://bucket/a.mp4"},+ {"type": "text", "content": "Describe."}+ ]}]`,+ wantOutput: `[+ {"role": "assistant", "parts": [{"type": "reasoning", "content": "Looking."}, {"executableCode": {"language": "PYTHON", "code": "print(1)"}}, {"type": "text", "content": "A logo and a clip."}], "finish_reason": "length"},+ {"role": "assistant", "parts": [], "finish_reason": "content_filter"}+ ]`,+ },+ {+ name: "StringContents_UserText",+ input: `{"model":"gemini-2.5-flash","contents":"Hi"}`,+ output: `{"role":"model","parts":[{"text":"Hello."}]}`,+ wantInput: `[{"role": "user", "parts": [{"type": "text", "content": "Hi"}]}]`,+ wantOutput: `[{"role": "assistant", "parts": [{"type": "text", "content": "Hello."}]}]`,+ },+ {+ // a bare Content list is told from semconv messages by its untyped parts+ name: "BareContentList_NotSemconv",+ input: `[{"role":"user","parts":[{"text":"Hi"}]}]`,+ wantInput: `[{"role": "user", "parts": [{"type": "text", "content": "Hi"}]}]`,+ wantOutput: `[]`,+ },+ })+}diff --git a/pkg/types/aiobservabilitytypes/message_format_openinference_test.go b/pkg/types/aiobservabilitytypes/message_format_openinference_test.goindex c90d41e6ae..156f0febd8 100644--- a/pkg/types/aiobservabilitytypes/message_format_openinference_test.go+++ b/pkg/types/aiobservabilitytypes/message_format_openinference_test.go@@ -157,7 +157,7 @@ func TestFormat_OpenInference(t *testing.T) {},{// pipecat writes the request as llm.input_messages and the streamed reply as output.value alone,- // which the mapper copies onto gen_ai.output.messages+ // which the mapper moves onto gen_ai.output.messages// https://github.com/Arize-ai/openinference/blob/12f2cc035edfb00b60b656d977f07abfb7a69900/python/instrumentation/openinference-instrumentation-pipecat/src/openinference/instrumentation/pipecat/_attributes.py#L430// https://github.com/Arize-ai/openinference/blob/12f2cc035edfb00b60b656d977f07abfb7a69900/python/instrumentation/openinference-instrumentation-pipecat/src/openinference/instrumentation/pipecat/_observer.py#L628name: "OutputKeysAbsent_RawOutputFormatted_Warns",diff --git a/pkg/types/aiobservabilitytypes/message_format_test.go b/pkg/types/aiobservabilitytypes/message_format_test.goindex a62bf8f0e8..d2329dc53e 100644--- a/pkg/types/aiobservabilitytypes/message_format_test.go+++ b/pkg/types/aiobservabilitytypes/message_format_test.go@@ -112,6 +112,16 @@ So, the ball costs 5 cents.`,wantInput: `[{"role": "", "parts": [{"type": "generic", "content": "{\"city\":\"Paris\",\"temp_c\":21}"}]}]`,wantOutput: `[]`,},+ {+ // openinference capture, CreateEmbeddings span: the mapper moved the request and the vectors onto+ // the message attributes and copied the span kind onto gen_ai.operation.name+ name: "EmbeddingsOperation_EmptyLists",+ input: `{"input": ["observability is the new monitoring"], "model": "text-embedding-3-small"}`,+ output: `{"data":[{"embedding":[-0.0039,0.0203],"index":0}],"model":"text-embedding-3-small"}`,+ attributes: map[string]any{GenAIOperationName: "EMBEDDING", GenAIRequestModel: "text-embedding-3-small"},+ wantInput: `[]`,+ wantOutput: `[]`,+ },{name: "NoMessageAttributes_EmptyLists",attributes: map[string]any{GenAIRequestModel: "gpt-4o", GenAIToolName: "get_weather"},diff --git a/pkg/types/aiobservabilitytypes/message_format_tool_test.go b/pkg/types/aiobservabilitytypes/message_format_tool_test.goindex 64432e843f..5a56f2e31e 100644--- a/pkg/types/aiobservabilitytypes/message_format_tool_test.go+++ b/pkg/types/aiobservabilitytypes/message_format_tool_test.go@@ -20,7 +20,7 @@ func TestFormat_Tool(t *testing.T) {wantOutput: `[{"role": "tool", "parts": [{"type": "tool_call_response", "response": {"city": "Bengaluru", "temp_c": 18, "summary": "Clear"}}]}]`,},{- // traceloop.entity.input and traceloop.entity.output from the @tool decorator, renamed by the mapper;+ // traceloop.entity.input and traceloop.entity.output from the @tool decorator, copied by the mapper;// the tool returned a JSON string, which json.dumps encoded again:// https://github.com/traceloop/openllmetry/blob/93429cfb9767e6b51db6cb35f6b70f758117669a/packages/traceloop-sdk/traceloop/sdk/decorators/base.py#L169name: "TraceloopDecorator_KwargsUnwrapped_ResultDecodedTwice",@@ -33,7 +33,7 @@ func TestFormat_Tool(t *testing.T) {wantOutput: `[{"role": "tool", "parts": [{"type": "tool_call_response", "response": {"city": "Bengaluru", "temp_c": 28, "summary": "Partly cloudy"}}]}]`,},{- // traceloop.entity.output of a @tool returning None, json.dumps(None), renamed by the mapper:+ // traceloop.entity.output of a @tool returning None, json.dumps(None), copied by the mapper:// https://github.com/traceloop/openllmetry/blob/93429cfb9767e6b51db6cb35f6b70f758117669a/packages/traceloop-sdk/traceloop/sdk/decorators/base.py#L185name: "TraceloopDecorator_PositionalArgsOnly_ListKept",attributes: map[string]any{@@ -54,7 +54,7 @@ func TestFormat_Tool(t *testing.T) {wantOutput: `[]`,},{- // input.value and output.value of an OpenInference TOOL span, renamed by the mapper:+ // input.value and output.value of an OpenInference TOOL span, copied by the mapper:// https://github.com/Arize-ai/openinference/blob/12f2cc035edfb00b60b656d977f07abfb7a69900/spec/traces.mdname: "OpenInferenceToolSpan_PlainJSONAndText",attributes: map[string]any{@@ -66,7 +66,7 @@ func TestFormat_Tool(t *testing.T) {wantOutput: `[{"role": "tool", "parts": [{"type": "tool_call_response", "response": "27C, partly cloudy, light breeze from the south."}]}]`,},{- // ai.toolCall.{id,name,args,result} of a Vercel ai.toolCall span, renamed by the mapper:+ // ai.toolCall.{id,name,args,result} of a Vercel ai.toolCall span, copied by the mapper:// https://ai-sdk.dev/docs/ai-sdk-core/telemetryname: "VercelToolCall_IDOnBothParts",attributes: map[string]any{diff --git a/tests/integration/tests/tracedetail/02_thread.py b/tests/integration/tests/tracedetail/02_thread.pyindex 25bf338c02..ab2c1bc6da 100644--- a/tests/integration/tests/tracedetail/02_thread.py+++ b/tests/integration/tests/tracedetail/02_thread.py@@ -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, responses_llm_id, langchain_llm_id, openrouter_llm_id, vercel_llm_id = (TraceIdGenerator.span_id() for _ in range(12))+ root_id, first_llm_id, tool_id, agent_id, second_llm_id, legacy_llm_id, third_llm_id, flattened_llm_id, responses_llm_id, langchain_llm_id, openrouter_llm_id, vercel_llm_id, anthropic_llm_id, gemini_llm_id = (TraceIdGenerator.span_id() for _ in range(14))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"}}]}])@@ -141,6 +141,34 @@ def test_thread_returns_gen_ai_spans_in_order(},attribute_write_mode="json_only",),+ Traces(+ timestamp=now + timedelta(seconds=4),+ trace_id=trace_id,+ span_id=anthropic_llm_id,+ parent_span_id=root_id,+ name="messages claude-sonnet-4-5",+ resources=resources,+ attributes={+ "gen_ai.request.model": "claude-sonnet-4-5",+ "gen_ai.input.messages": json.dumps({"system": "Be terse.", "messages": [{"role": "user", "content": "ping"}]}),+ "gen_ai.output.messages": json.dumps({"type": "message", "role": "assistant", "content": [{"type": "text", "text": "pong"}], "stop_reason": "end_turn"}),+ },+ attribute_write_mode="json_only",+ ),+ Traces(+ timestamp=now + timedelta(seconds=5),+ trace_id=trace_id,+ span_id=gemini_llm_id,+ parent_span_id=root_id,+ name="generateContent gemini-2.5-flash",+ resources=resources,+ attributes={+ "gen_ai.request.model": "gemini-2.5-flash",+ "gen_ai.input.messages": json.dumps({"contents": [{"role": "user", "parts": [{"text": "ping"}]}]}),+ "gen_ai.output.messages": json.dumps({"candidates": [{"content": {"role": "model", "parts": [{"text": "pong"}]}, "finishReason": "STOP"}]}),+ },+ attribute_write_mode="json_only",+ ),])@@ -149,10 +177,10 @@ def test_thread_returns_gen_ai_spans_in_order(assert response.status_code == HTTPStatus.OK, response.textthread = 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, responses_llm_id, langchain_llm_id, openrouter_llm_id, vercel_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, langchain_llm_id, openrouter_llm_id, vercel_llm_id, anthropic_llm_id, gemini_llm_id]assert "nextCursor" not in thread- first, tool, agent, input_only, legacy, output_only, flattened, responses, langchain, openrouter, vercel = thread["spans"]+ first, tool, agent, input_only, legacy, output_only, flattened, responses, langchain, openrouter, vercel, anthropic, gemini = thread["spans"]assert agent["attributes"]["gen_ai.agent.name"] == "planner"assert agent["formattedInput"] == []assert agent["formattedOutput"] == []@@ -192,6 +220,10 @@ def test_thread_returns_gen_ai_spans_in_order(assert openrouter["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "Yes."}]}]assert vercel["formattedInput"] == [{"role": "user", "parts": [{"type": "text", "content": "last one"}]}]assert vercel["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "Done."}], "finish_reason": "stop"}]+ assert anthropic["formattedInput"] == [{"role": "system", "parts": [{"type": "text", "content": "Be terse."}]}, {"role": "user", "parts": [{"type": "text", "content": "ping"}]}]+ assert anthropic["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "pong"}], "finish_reason": "stop"}]+ assert gemini["formattedInput"] == [{"role": "user", "parts": [{"type": "text", "content": "ping"}]}]+ assert gemini["formattedOutput"] == [{"role": "assistant", "parts": [{"type": "text", "content": "pong"}], "finish_reason": "stop"}]def test_thread_paginates_with_cursors(