Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function POST(request: Request) {

if (!messages || !Array.isArray(messages)) {
Sentry.logger.warn('Chat request received with invalid messages payload')
Sentry.metrics.increment('chat.requests', 1, { tags: { status: 'invalid' } })
Sentry.metrics.count('chat.requests', 1, { attributes: { status: 'invalid' } })
return new Response(
JSON.stringify({ error: 'Messages array is required' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
Expand All @@ -39,15 +39,15 @@ export async function POST(request: Request) {
const lastUserMessage = messages.filter(m => m.role === 'user').pop()
if (!lastUserMessage) {
Sentry.logger.warn('Chat request received with no user message')
Sentry.metrics.increment('chat.requests', 1, { tags: { status: 'invalid' } })
Sentry.metrics.count('chat.requests', 1, { attributes: { status: 'invalid' } })
return new Response(
JSON.stringify({ error: 'No user message found' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
)
}

Sentry.logger.info('Chat request received with %d messages', [messages.length])
Sentry.metrics.increment('chat.requests', 1, { tags: { status: 'started' } })
Sentry.metrics.count('chat.requests', 1, { attributes: { status: 'started' } })
Sentry.metrics.distribution('chat.messages_per_request', messages.length)

// Build conversation context
Expand Down Expand Up @@ -99,7 +99,7 @@ export async function POST(request: Request) {
for (const block of content) {
if (block.type === 'tool_use') {
Sentry.logger.info('Agent tool invoked: %s', [block.name])
Sentry.metrics.increment('chat.tool_invocations', 1, { tags: { tool: block.name } })
Sentry.metrics.count('chat.tool_invocations', 1, { attributes: { tool: block.name } })
controller.enqueue(encoder.encode(
`data: ${JSON.stringify({ type: 'tool_start', tool: block.name })}\n\n`
))
Expand All @@ -118,7 +118,7 @@ export async function POST(request: Request) {
// Signal completion
if (message.type === 'result' && message.subtype === 'success') {
Sentry.logger.info('Chat stream completed successfully')
Sentry.metrics.increment('chat.requests', 1, { tags: { status: 'success' } })
Sentry.metrics.count('chat.requests', 1, { attributes: { status: 'success' } })
controller.enqueue(encoder.encode(
`data: ${JSON.stringify({ type: 'done' })}\n\n`
))
Expand All @@ -127,7 +127,7 @@ export async function POST(request: Request) {
// Handle errors
if (message.type === 'result' && message.subtype !== 'success') {
Sentry.logger.error('Chat query did not complete successfully, subtype: %s', [message.subtype])
Sentry.metrics.increment('chat.requests', 1, { tags: { status: 'query_failure' } })
Sentry.metrics.count('chat.requests', 1, { attributes: { status: 'query_failure' } })
controller.enqueue(encoder.encode(
`data: ${JSON.stringify({ type: 'error', message: 'Query did not complete successfully' })}\n\n`
))
Expand All @@ -138,7 +138,7 @@ export async function POST(request: Request) {
controller.close()
} catch (error) {
Sentry.logger.error('Chat stream error: %s', [error instanceof Error ? error.message : String(error)])
Sentry.metrics.increment('chat.errors', 1, { tags: { phase: 'stream' } })
Sentry.metrics.count('chat.errors', 1, { attributes: { phase: 'stream' } })
Sentry.captureException(error)
controller.enqueue(encoder.encode(
`data: ${JSON.stringify({ type: 'error', message: 'Stream error occurred' })}\n\n`
Expand All @@ -157,7 +157,7 @@ export async function POST(request: Request) {
})
} catch (error) {
Sentry.logger.error('Chat API error: %s', [error instanceof Error ? error.message : String(error)])
Sentry.metrics.increment('chat.errors', 1, { tags: { phase: 'request' } })
Sentry.metrics.count('chat.errors', 1, { attributes: { phase: 'request' } })
Sentry.captureException(error)

return new Response(
Expand Down
6 changes: 3 additions & 3 deletions src/components/desktop/Desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function DesktopContent() {

const openInstallGuide = () => {
Sentry.logger.info('App launched: %s', ['Install Guide'])
Sentry.metrics.increment('app.launched', 1, { tags: { app: 'install-guide' } })
Sentry.metrics.count('app.launched', 1, { attributes: { app: 'install-guide' } })
openWindow({
id: 'install-guide',
title: 'Install Guide.md',
Expand All @@ -80,7 +80,7 @@ function DesktopContent() {

const openChatWindow = () => {
Sentry.logger.info('App launched: %s', ['Chat'])
Sentry.metrics.increment('app.launched', 1, { tags: { app: 'chat' } })
Sentry.metrics.count('app.launched', 1, { attributes: { app: 'chat' } })
openWindow({
id: 'chat',
title: 'SentryOS Chat',
Expand All @@ -99,7 +99,7 @@ function DesktopContent() {

const openAgentsFolder = () => {
Sentry.logger.info('App launched: %s', ['Agents Folder'])
Sentry.metrics.increment('app.launched', 1, { tags: { app: 'agents-folder' } })
Sentry.metrics.count('app.launched', 1, { attributes: { app: 'agents-folder' } })
const agentsFolderItems: FolderItem[] = []

openWindow({
Expand Down
8 changes: 4 additions & 4 deletions src/components/desktop/WindowManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function WindowManagerProvider({ children }: { children: ReactNode }) {

const openWindow = useCallback((window: Omit<WindowState, 'zIndex' | 'isFocused'>) => {
Sentry.logger.info('Window opened: %s', [window.title])
Sentry.metrics.increment('window.opened', 1, { tags: { window_id: window.id } })
Sentry.metrics.count('window.opened', 1, { attributes: { window_id: window.id } })
setTopZIndex(currentZ => {
const newZ = currentZ + 1
setWindows(prev => {
Expand Down Expand Up @@ -63,13 +63,13 @@ export function WindowManagerProvider({ children }: { children: ReactNode }) {

const closeWindow = useCallback((id: string) => {
Sentry.logger.info('Window closed: %s', [id])
Sentry.metrics.increment('window.closed', 1, { tags: { window_id: id } })
Sentry.metrics.count('window.closed', 1, { attributes: { window_id: id } })
setWindows(prev => prev.filter(w => w.id !== id))
}, [])

const minimizeWindow = useCallback((id: string) => {
Sentry.logger.info('Window minimized: %s', [id])
Sentry.metrics.increment('window.minimized', 1, { tags: { window_id: id } })
Sentry.metrics.count('window.minimized', 1, { attributes: { window_id: id } })
setWindows(prev => prev.map(w =>
w.id === id ? { ...w, isMinimized: true, isFocused: false } : w
))
Expand All @@ -80,7 +80,7 @@ export function WindowManagerProvider({ children }: { children: ReactNode }) {
const win = prev.find(w => w.id === id)
const action = win?.isMaximized ? 'restored' : 'maximized'
Sentry.logger.info('Window %s: %s', [action, id])
Sentry.metrics.increment(`window.${action}`, 1, { tags: { window_id: id } })
Sentry.metrics.count(`window.${action}`, 1, { attributes: { window_id: id } })
return prev.map(w =>
w.id === id ? { ...w, isMaximized: !w.isMaximized } : w
)
Expand Down
8 changes: 4 additions & 4 deletions src/components/desktop/apps/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function Chat() {
setCurrentTool(null)

Sentry.logger.info('User sent chat message, conversation length: %d', [messages.length + 1])
Sentry.metrics.increment('chat.client.message_sent', 1)
Sentry.metrics.count('chat.client.message_sent', 1)

try {
const response = await fetch('/api/chat', {
Expand Down Expand Up @@ -150,7 +150,7 @@ export function Chat() {
))
} else if (parsed.type === 'tool_start') {
Sentry.logger.info('Tool execution started: %s', [parsed.tool])
Sentry.metrics.increment('chat.client.tool_execution', 1, { tags: { tool: parsed.tool } })
Sentry.metrics.count('chat.client.tool_execution', 1, { attributes: { tool: parsed.tool } })
setCurrentTool({
name: parsed.tool,
status: 'running'
Expand All @@ -162,7 +162,7 @@ export function Chat() {
} : null)
} else if (parsed.type === 'done') {
Sentry.logger.info('Chat response stream completed')
Sentry.metrics.increment('chat.client.response_received', 1)
Sentry.metrics.count('chat.client.response_received', 1)
setCurrentTool(null)
} else if (parsed.type === 'error') {
Sentry.logger.error('Chat stream returned error: %s', [parsed.message])
Expand All @@ -187,7 +187,7 @@ export function Chat() {
}
} catch (error) {
Sentry.logger.error('Chat fetch error: %s', [error instanceof Error ? error.message : String(error)])
Sentry.metrics.increment('chat.client.errors', 1)
Sentry.metrics.count('chat.client.errors', 1)
Sentry.captureException(error)
const errorMessage: Message = {
id: crypto.randomUUID(),
Expand Down