mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-24 01:00:58 +00:00
Compare commits
1 Commits
main
...
fix/noz-se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3a0fe2acc |
@@ -38,6 +38,7 @@ import logEvent from 'api/common/logEvent';
|
||||
import { AIAssistantEvents, SuggestedPromptCategory } from '../../events';
|
||||
import { useAIAssistantAnalyticsContext } from '../../hooks/useAIAssistantAnalyticsContext';
|
||||
import { useAIAssistantStore } from '../../store/useAIAssistantStore';
|
||||
import { reportAssistantError } from '../../utils/reportAssistantError';
|
||||
|
||||
import { getOpenResourceTarget } from './utils/getOpenResourceTarget';
|
||||
import {
|
||||
@@ -464,6 +465,7 @@ export default function ActionsSection({
|
||||
});
|
||||
setResult(key, { state: 'success' });
|
||||
} catch (err) {
|
||||
reportAssistantError('openSavedView', err);
|
||||
const message =
|
||||
err instanceof Error ? err.message : 'Failed to open saved view';
|
||||
setResult(key, { state: 'error', error: message });
|
||||
@@ -483,6 +485,7 @@ export default function ActionsSection({
|
||||
await call(action.actionMetadataId);
|
||||
setResult(key, { state: 'success' });
|
||||
} catch (err) {
|
||||
reportAssistantError('rollbackAction', err);
|
||||
const message = err instanceof Error ? err.message : 'Failed';
|
||||
setResult(key, { state: 'error', error: message });
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Check, LoaderCircle, TriangleAlert, X, Zap } from '@signozhq/icons';
|
||||
import { PageActionRegistry } from '../../../pageActions/PageActionRegistry';
|
||||
import { AIActionBlock } from '../../../pageActions/types';
|
||||
import { useAIAssistantStore } from '../../../store/useAIAssistantStore';
|
||||
import { reportAssistantError } from '../../../utils/reportAssistantError';
|
||||
import { useMessageContext } from '../../MessageContext';
|
||||
|
||||
import blockStyles from '../Block.module.scss';
|
||||
@@ -85,6 +86,7 @@ export default function ActionBlock({
|
||||
markBlockAnswered(messageId, `applied:${result.summary}`);
|
||||
}
|
||||
} catch (err) {
|
||||
reportAssistantError('executePageAction', err);
|
||||
const msg = err instanceof Error ? err.message : 'Unknown error';
|
||||
setErrorMessage(msg);
|
||||
setLocalState('error');
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
MessageBlock,
|
||||
MessageRole,
|
||||
} from '../types';
|
||||
import { reportAssistantError } from '../utils/reportAssistantError';
|
||||
import {
|
||||
resolveAssistantError,
|
||||
type AssistantErrorResolution,
|
||||
@@ -590,7 +591,7 @@ async function streamAndFinalize(
|
||||
conversationId: string,
|
||||
start: () => Promise<string>,
|
||||
fallback: string,
|
||||
logLabel: string,
|
||||
operation: string,
|
||||
set: StoreSetter,
|
||||
get: StoreGetter,
|
||||
retry: () => Promise<void>,
|
||||
@@ -605,8 +606,7 @@ async function streamAndFinalize(
|
||||
if (err instanceof DOMException && err.name === 'AbortError') {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(logLabel, err);
|
||||
reportAssistantError(operation, err);
|
||||
const resolution = resolveAssistantError(err, fallback);
|
||||
finalizeStreamingError(conversationId, resolution, set, retry);
|
||||
}
|
||||
@@ -929,7 +929,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
void get().loadThread(activeThreadIdToLoad);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[AIAssistant] fetchThreads failed:', err);
|
||||
reportAssistantError('fetchThreads', err);
|
||||
set((s) => {
|
||||
s.isLoadingThreads = false;
|
||||
for (const conv of Object.values(s.conversations)) {
|
||||
@@ -1015,7 +1015,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
if (err instanceof DOMException && err.name === 'AbortError') {
|
||||
return;
|
||||
}
|
||||
console.error('[AIAssistant] loadThread failed:', err);
|
||||
reportAssistantError('loadThread', err);
|
||||
set((s) => {
|
||||
s.isLoadingThread = false;
|
||||
});
|
||||
@@ -1068,7 +1068,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
disconnectAndCommit(id, set, get);
|
||||
if (conv.threadId) {
|
||||
updateThread(conv.threadId, { archived: true }).catch((err) => {
|
||||
console.error('[AIAssistant] archiveThread failed:', err);
|
||||
reportAssistantError('archiveThread', err);
|
||||
});
|
||||
set((state) => {
|
||||
const c = state.conversations[id];
|
||||
@@ -1112,7 +1112,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[AIAssistant] restoreThread failed:', err);
|
||||
reportAssistantError('restoreThread', err);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1149,7 +1149,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('[AIAssistant] renameThread failed:', err);
|
||||
reportAssistantError('renameThread', err);
|
||||
set((state) => {
|
||||
if (state.conversations[id]) {
|
||||
state.conversations[id].title = previousTitle;
|
||||
@@ -1189,7 +1189,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
try {
|
||||
await cancelExecution(existingThreadId);
|
||||
} catch (err) {
|
||||
console.error('[AIAssistant] cancelExecution failed:', err);
|
||||
reportAssistantError('cancelExecution', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1261,7 +1261,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
if (err instanceof DOMException && err.name === 'AbortError') {
|
||||
return;
|
||||
}
|
||||
console.error('[AIAssistant] sendMessage failed:', err);
|
||||
reportAssistantError('sendMessage', err);
|
||||
const resolution = resolveAssistantError(
|
||||
err,
|
||||
'Something went wrong while fetching the response. Please try again.',
|
||||
@@ -1296,7 +1296,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
conversationId,
|
||||
() => approveExecution(approvalId),
|
||||
'Something went wrong while processing the approval. Please try again.',
|
||||
'[AIAssistant] approveAction failed:',
|
||||
'approveAction',
|
||||
set,
|
||||
get,
|
||||
run,
|
||||
@@ -1311,7 +1311,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
try {
|
||||
await rejectExecution(approvalId);
|
||||
} catch (err) {
|
||||
console.error('[AIAssistant] rejectAction failed:', err);
|
||||
reportAssistantError('rejectAction', err);
|
||||
}
|
||||
set((s) => {
|
||||
const st = s.streams[conversationId];
|
||||
@@ -1331,7 +1331,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
const conv = get().conversations[conversationId];
|
||||
if (conv?.threadId) {
|
||||
cancelExecution(conv.threadId).catch((err) => {
|
||||
console.error('[AIAssistant] cancelExecution failed:', err);
|
||||
reportAssistantError('cancelExecution', err);
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -1366,7 +1366,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
conversationId,
|
||||
() => regenerateMessage(messageId),
|
||||
'Something went wrong while regenerating the response. Please try again.',
|
||||
'[AIAssistant] regenerateAssistantMessage failed:',
|
||||
'regenerateAssistantMessage',
|
||||
set,
|
||||
get,
|
||||
run,
|
||||
@@ -1398,7 +1398,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
try {
|
||||
await submitFeedback(messageId, rating, comment);
|
||||
} catch (err) {
|
||||
console.error('[AIAssistant] submitMessageFeedback failed:', err);
|
||||
reportAssistantError('submitMessageFeedback', err);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1424,7 +1424,7 @@ export const useAIAssistantStore = create<AIAssistantStore>()(
|
||||
conversationId,
|
||||
() => clarifyExecution(clarificationId, answers),
|
||||
'Something went wrong while processing your answers. Please try again.',
|
||||
'[AIAssistant] submitClarification failed:',
|
||||
'submitClarification',
|
||||
set,
|
||||
get,
|
||||
run,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { AxiosError } from 'axios';
|
||||
import { ErrorCodeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
|
||||
import { reportAssistantError } from '../reportAssistantError';
|
||||
|
||||
jest.mock('@sentry/react', () => ({
|
||||
captureException: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockCaptureException = jest.mocked(Sentry.captureException);
|
||||
|
||||
function restError(status: number, code: string): AxiosError {
|
||||
const err = new AxiosError('Request failed');
|
||||
err.response = {
|
||||
status,
|
||||
data: { error: { code, message: 'backend message' } },
|
||||
} as AxiosError['response'];
|
||||
return err;
|
||||
}
|
||||
|
||||
describe('reportAssistantError', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
mockCaptureException.mockClear();
|
||||
});
|
||||
|
||||
it('reports an unexpected error tagged with the feature and operation', () => {
|
||||
const err = restError(500, ErrorCodeDTO.internal_error);
|
||||
|
||||
reportAssistantError('sendMessage', err);
|
||||
|
||||
expect(mockCaptureException).toHaveBeenCalledWith(err, {
|
||||
tags: { feature: 'noz', operation: 'sendMessage' },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a quota limit', restError(429, ErrorCodeDTO.daily_message_limit)],
|
||||
['a permission error', restError(403, ErrorCodeDTO.permission_denied)],
|
||||
['a busy thread', restError(409, ErrorCodeDTO.thread_busy)],
|
||||
])('does not report %s', (_, err) => {
|
||||
reportAssistantError('sendMessage', err);
|
||||
|
||||
expect(mockCaptureException).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { ErrorCodeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
|
||||
import { resolveAssistantError } from './resolveAssistantError';
|
||||
|
||||
// Account and thread states the UI already explains. Quota limits are skipped
|
||||
// too; aborts, 401/403 and network drops are dropped by the global Sentry filter.
|
||||
const EXPECTED_ERROR_CODES = new Set<ErrorCodeDTO>([
|
||||
ErrorCodeDTO.permission_denied,
|
||||
ErrorCodeDTO.user_disabled,
|
||||
ErrorCodeDTO.org_disabled,
|
||||
ErrorCodeDTO.thread_busy,
|
||||
ErrorCodeDTO.thread_has_active_execution,
|
||||
]);
|
||||
|
||||
function isExpectedAssistantError(err: unknown): boolean {
|
||||
const { code, isRateLimit } = resolveAssistantError(err, '');
|
||||
return isRateLimit || (code !== undefined && EXPECTED_ERROR_CODES.has(code));
|
||||
}
|
||||
|
||||
export function reportAssistantError(operation: string, err: unknown): void {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`[AIAssistant] ${operation} failed:`, err);
|
||||
if (isExpectedAssistantError(err)) {
|
||||
return;
|
||||
}
|
||||
Sentry.captureException(err, { tags: { feature: 'noz', operation } });
|
||||
}
|
||||
Reference in New Issue
Block a user