Skip to content

Commit ef20349

Browse files
authored
API Logs improvements FDBK-29499 (supabase#36479)
add search, improve event message
1 parent b914d10 commit ef20349

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const LogSelection = ({ log, onClose, queryType, isLoading, error }: LogSelectio
4747
const status = log?.metadata?.[0]?.response?.[0]?.status_code
4848
const method = log?.metadata?.[0]?.request?.[0]?.method
4949
const path = log?.metadata?.[0]?.request?.[0]?.path
50+
const search = log?.metadata?.[0]?.request?.[0]?.search
5051
const user_agent = log?.metadata?.[0]?.request?.[0]?.headers[0].user_agent
5152
const error_code = log?.metadata?.[0]?.response?.[0]?.headers?.[0]?.x_sb_error_code
5253
const apikey = jwtAPIKey(log?.metadata) ?? apiKey(log?.metadata)
@@ -59,6 +60,7 @@ const LogSelection = ({ log, onClose, queryType, isLoading, error }: LogSelectio
5960
status,
6061
method,
6162
path,
63+
search,
6264
user_agent,
6365
timestamp,
6466
event_message,

apps/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DefaultPreviewSelectionRenderer.tsx

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ResponseCodeFormatter } from '../LogsFormatters'
1818
const LogRowCodeBlock = ({ value, className }: { value: string; className?: string }) => (
1919
<pre
2020
className={cn(
21-
'px-1 bg-surface-300 w-full pt-1 max-w-full border-none text-xs prose-sm transition-all overflow-auto rounded-md',
21+
'px-1 bg-surface-300 w-full pt-1 max-w-full border-none text-xs prose-sm transition-all overflow-auto rounded-md whitespace-pre-wrap',
2222
className
2323
)}
2424
>
@@ -47,8 +47,18 @@ const PropertyRow = ({
4747
const isObject = typeof value === 'object' && value !== null
4848
const isStatus = keyName === 'status' || keyName === 'status_code'
4949
const isMethod = keyName === 'method'
50-
const isPath = keyName === 'path'
50+
const isSearch = keyName === 'search'
5151
const isUserAgent = keyName === 'user_agent'
52+
const isEventMessage = keyName === 'event_message'
53+
const isPath = keyName === 'path'
54+
55+
function getSearchPairs() {
56+
if (isSearch && typeof value === 'string') {
57+
const str = value.startsWith('?') ? value.slice(1) : value
58+
return str.split('&').filter(Boolean)
59+
}
60+
return []
61+
}
5262

5363
const storageKey = `log-viewer-expanded-${keyName}`
5464
const [isExpanded, setIsExpanded] = useState(() => {
@@ -76,7 +86,7 @@ const PropertyRow = ({
7686
}, 1000)
7787
}
7888

79-
if (isObject) {
89+
if (isObject || isEventMessage) {
8090
return (
8191
<>
8292
<div className="flex flex-col gap-1">
@@ -86,17 +96,20 @@ const PropertyRow = ({
8696
className={cn('px-2.5', {
8797
'max-h-[80px]': !isExpanded,
8898
'max-h-[400px]': isExpanded,
99+
'py-2': isEventMessage,
89100
})}
90101
value={value}
91102
/>
92-
<Button
93-
className="mt-1 w-full"
94-
size="tiny"
95-
type="outline"
96-
onClick={() => setIsExpanded(!isExpanded)}
97-
>
98-
{isExpanded ? 'Collapse' : 'Expand'}
99-
</Button>
103+
{!isEventMessage && (
104+
<Button
105+
className="mt-1 w-full"
106+
size="tiny"
107+
type="outline"
108+
onClick={() => setIsExpanded(!isExpanded)}
109+
>
110+
{isExpanded ? 'Collapse' : 'Expand'}
111+
</Button>
112+
)}
100113
</div>
101114
</div>
102115
<LogRowSeparator />
@@ -141,7 +154,7 @@ const PropertyRow = ({
141154
<ResponseCodeFormatter value={value} />
142155
</div>
143156
) : (
144-
<div className="truncate">{JSON.stringify(value)}</div>
157+
<div className="truncate">{value}</div>
145158
)}
146159
</div>
147160
</div>
@@ -158,7 +171,7 @@ const PropertyRow = ({
158171
{isExpanded ? 'Collapse' : 'Expand'} value
159172
</DropdownMenuItem>
160173
)}
161-
{(isPath || isMethod || isUserAgent || isStatus) && (
174+
{(isMethod || isUserAgent || isStatus || isPath) && (
162175
<DropdownMenuItem
163176
onClick={() => {
164177
handleSearch('search-input-change', { query: value })
@@ -167,6 +180,18 @@ const PropertyRow = ({
167180
Search by {keyName}
168181
</DropdownMenuItem>
169182
)}
183+
{isSearch
184+
? getSearchPairs().map((pair) => (
185+
<DropdownMenuItem
186+
key={pair}
187+
onClick={() => {
188+
handleSearch('search-input-change', { query: pair })
189+
}}
190+
>
191+
Search by {pair}
192+
</DropdownMenuItem>
193+
))
194+
: null}
170195
</DropdownMenuContent>
171196
<LogRowSeparator />
172197
</DropdownMenu>

apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ export const genDefaultQuery = (table: LogsTableName, filters: Filters, limit: n
145145
if (IS_PLATFORM === false) {
146146
return `
147147
-- local dev edge_logs query
148-
select id, edge_logs.timestamp, event_message, request.method, request.path, response.status_code
148+
select id, edge_logs.timestamp, event_message, request.method, request.path, request.search, response.status_code
149149
from edge_logs
150150
${joins}
151151
${where}
152152
${orderBy}
153153
limit ${limit};
154154
`
155155
}
156-
return `select id, identifier, timestamp, event_message, request.method, request.path, response.status_code
156+
return `select id, identifier, timestamp, event_message, request.method, request.path, request.search, response.status_code
157157
from ${table}
158158
${joins}
159159
${where}

0 commit comments

Comments
 (0)