Skip to content

Commit b1fcdc4

Browse files
committed
fix(genai): tighten containsGenerateContent path matching
Require a delimiter (: or /) before the method name in containsGenerateContent to avoid potential false positives on hypothetical endpoints like deleteGenerateContentCache. Also document the single-candidate limitation in postprocessStreamingResults.
1 parent ba38905 commit b1fcdc4

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

trace/contrib/genai/generatecontent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ func (gt *generateContentTracer) postprocessStreamingResults(allResults []map[st
205205
return nil
206206
}
207207

208-
// Aggregate text parts from all candidates across chunks
208+
// Aggregate text parts from all candidates across chunks.
209+
// NOTE: We only aggregate candidate index 0 from each chunk. If the API
210+
// ever returns multiple candidate indices in a streaming response, their
211+
// content will be silently dropped. The non-streaming path passes through
212+
// all candidates as-is.
209213
var textParts []string
210214
var finishReason any
211215
var role string

trace/contrib/genai/tracegenai.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ func genaiRouter(cfg *config, path string) internal.MiddlewareTracer {
152152
return nil
153153
}
154154

155-
// containsGenerateContent checks if the path is for a generateContent or streamGenerateContent endpoint
155+
// containsGenerateContent checks if the path is for a generateContent or streamGenerateContent endpoint.
156+
// We require a delimiter (: or /) before the method name to avoid matching unrelated endpoints.
156157
func containsGenerateContent(path string) bool {
157-
return strings.Contains(path, "generateContent") ||
158-
strings.Contains(path, "GenerateContent")
158+
return strings.Contains(path, ":generateContent") ||
159+
strings.Contains(path, "/generateContent") ||
160+
strings.Contains(path, ":streamGenerateContent") ||
161+
strings.Contains(path, "/streamGenerateContent")
159162
}
160163

161164
// isStreamingPath checks if the path is for the streaming endpoint

0 commit comments

Comments
 (0)