fix: improve mutation telemetry error logging and diagnostics

Changes:
- Upgrade error logging from debug to warn level for better visibility
- Add diagnostic logging to track mutation processing
- Log telemetry disabled state explicitly
- Add context info (sessionId, intent, operationCount) to error logs
- Remove 'await' from telemetry calls to make them truly non-blocking

This will help identify why mutations aren't being persisted to the
workflow_mutations table despite successful workflow operations.

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en
This commit is contained in:
czlonkowski
2025-11-12 17:52:52 +01:00
parent 00a2e77643
commit 6719628350
4 changed files with 31 additions and 9 deletions

Binary file not shown.

View File

@@ -762,7 +762,7 @@ export async function handleUpdateWorkflow(
// Track successful mutation
if (workflowBefore) {
await trackWorkflowMutationForFullUpdate({
trackWorkflowMutationForFullUpdate({
sessionId,
toolName: 'n8n_update_full_workflow',
userIntent,
@@ -771,7 +771,9 @@ export async function handleUpdateWorkflow(
workflowAfter: workflow,
mutationSuccess: true,
durationMs: Date.now() - startTime,
}).catch(err => logger.debug('Failed to track mutation telemetry:', err));
}).catch(err => {
logger.warn('Failed to track mutation telemetry:', err);
});
}
return {
@@ -782,7 +784,7 @@ export async function handleUpdateWorkflow(
} catch (error) {
// Track failed mutation
if (workflowBefore) {
await trackWorkflowMutationForFullUpdate({
trackWorkflowMutationForFullUpdate({
sessionId,
toolName: 'n8n_update_full_workflow',
userIntent,
@@ -792,7 +794,9 @@ export async function handleUpdateWorkflow(
mutationSuccess: false,
mutationError: error instanceof Error ? error.message : 'Unknown error',
durationMs: Date.now() - startTime,
}).catch(err => logger.debug('Failed to track mutation telemetry:', err));
}).catch(err => {
logger.warn('Failed to track mutation telemetry for failed operation:', err);
});
}
if (error instanceof z.ZodError) {

View File

@@ -291,7 +291,7 @@ export async function handleUpdatePartialWorkflow(
// Track successful mutation
if (workflowBefore && !input.validateOnly) {
await trackWorkflowMutation({
trackWorkflowMutation({
sessionId,
toolName: 'n8n_update_partial_workflow',
userIntent: input.intent || 'Partial workflow update',
@@ -300,7 +300,14 @@ export async function handleUpdatePartialWorkflow(
workflowAfter: finalWorkflow,
mutationSuccess: true,
durationMs: Date.now() - startTime,
}).catch(err => logger.debug('Failed to track mutation telemetry:', err));
}).catch(err => {
logger.warn('Failed to track mutation telemetry:', err);
logger.debug('Mutation data that failed:', {
sessionId,
intent: input.intent,
operationCount: input.operations.length
});
});
}
return {
@@ -321,7 +328,7 @@ export async function handleUpdatePartialWorkflow(
} catch (error) {
// Track failed mutation
if (workflowBefore && !input.validateOnly) {
await trackWorkflowMutation({
trackWorkflowMutation({
sessionId,
toolName: 'n8n_update_partial_workflow',
userIntent: input.intent || 'Partial workflow update',
@@ -331,7 +338,9 @@ export async function handleUpdatePartialWorkflow(
mutationSuccess: false,
mutationError: error instanceof Error ? error.message : 'Unknown error',
durationMs: Date.now() - startTime,
}).catch(err => logger.debug('Failed to track mutation telemetry:', err));
}).catch(err => {
logger.warn('Failed to track mutation telemetry for failed operation:', err);
});
}
if (error instanceof N8nApiError) {

View File

@@ -153,13 +153,22 @@ export class TelemetryManager {
*/
async trackWorkflowMutation(data: any): Promise<void> {
this.ensureInitialized();
if (!this.isEnabled()) return;
if (!this.isEnabled()) {
logger.debug('Telemetry disabled, skipping mutation tracking');
return;
}
this.performanceMonitor.startOperation('trackWorkflowMutation');
try {
const { mutationTracker } = await import('./mutation-tracker.js');
const userId = this.configManager.getUserId();
logger.debug('Tracking workflow mutation', {
userId,
intent: data.userIntent?.substring(0, 50),
operationCount: data.operations?.length
});
const mutationRecord = await mutationTracker.processMutation(data, userId);
if (mutationRecord) {