Skip to content

Commit bfbcb5a

Browse files
committed
Fix observer query summaries for UNION and parenthesized SQL
Strip leading parentheses before extracting the SQL operation so queries like "(SELECT ... UNION ...)" are correctly identified as SELECT instead of "(SELECT". Append a UNION suffix to summaries when a UNION clause is detected.
1 parent 17f0e76 commit bfbcb5a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plain-models/plain/models/otel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def extract_operation_and_target(sql: str) -> tuple[str, str | None, str | None]
6464
Returns: (operation, summary, collection_name)
6565
"""
6666
sql_upper = sql.upper().strip()
67-
operation = sql_upper.split()[0] if sql_upper else "UNKNOWN"
67+
68+
# Strip leading parentheses (e.g. UNION queries: "(SELECT ... UNION ...)")
69+
operation = sql_upper.lstrip("(").split()[0] if sql_upper else "UNKNOWN"
6870

6971
# Pattern to match quoted and unquoted identifiers
7072
# Matches: "quoted", `quoted`, [quoted], unquoted.name
@@ -92,6 +94,10 @@ def extract_operation_and_target(sql: str) -> tuple[str, str | None, str | None]
9294
collection_name = _clean_identifier(match.group(1))
9395
summary = f"{operation} {collection_name}"
9496

97+
# Detect UNION queries
98+
if " UNION " in sql_upper and summary:
99+
summary = f"{summary} UNION"
100+
95101
return operation, summary, collection_name
96102

97103

0 commit comments

Comments
 (0)