improvement(logging): capture pre-execution validation errors in logging session (#1124)

* improvement(pre-exec-errors): capture pre-execution validation errors in logging session

* fix param shape for schedules

* fix naming
This commit is contained in:
Vikhyath Mondreti
2025-08-23 18:08:57 -07:00
committed by GitHub
parent bbbf1c2941
commit 6c9e0ec88b
2 changed files with 51 additions and 11 deletions

View File

@@ -474,8 +474,10 @@ export async function GET() {
})
await loggingSession.safeCompleteWithError({
message: `Schedule execution failed before workflow started: ${earlyError.message}`,
stackTrace: earlyError.stack,
error: {
message: `Schedule execution failed before workflow started: ${earlyError.message}`,
stackTrace: earlyError.stack,
},
})
} catch (loggingError) {
logger.error(
@@ -591,8 +593,10 @@ export async function GET() {
})
await failureLoggingSession.safeCompleteWithError({
message: `Schedule execution failed: ${error.message}`,
stackTrace: error.stack,
error: {
message: `Schedule execution failed: ${error.message}`,
stackTrace: error.stack,
},
})
} catch (loggingError) {
logger.error(

View File

@@ -7,7 +7,12 @@ import {
createTriggerObject,
loadWorkflowStateForExecution,
} from '@/lib/logs/execution/logging-factory'
import type { ExecutionEnvironment, ExecutionTrigger, WorkflowState } from '@/lib/logs/types'
import type {
ExecutionEnvironment,
ExecutionTrigger,
TraceSpan,
WorkflowState,
} from '@/lib/logs/types'
const logger = createLogger('LoggingSession')
@@ -25,6 +30,15 @@ export interface SessionCompleteParams {
traceSpans?: any[]
}
export interface SessionErrorCompleteParams {
endedAt?: string
totalDurationMs?: number
error?: {
message?: string
stackTrace?: string
}
}
export class LoggingSession {
private workflowId: string
private executionId: string
@@ -115,8 +129,14 @@ export class LoggingSession {
}
}
async completeWithError(error?: any): Promise<void> {
async completeWithError(params: SessionErrorCompleteParams = {}): Promise<void> {
try {
const { endedAt, totalDurationMs, error } = params
const endTime = endedAt ? new Date(endedAt) : new Date()
const durationMs = typeof totalDurationMs === 'number' ? totalDurationMs : 0
const startTime = new Date(endTime.getTime() - Math.max(1, durationMs))
const costSummary = {
totalCost: BASE_EXECUTION_CHARGE,
totalInputCost: 0,
@@ -129,13 +149,29 @@ export class LoggingSession {
models: {},
}
const message = error?.message || 'Execution failed before starting blocks'
const syntheticErrorSpan: TraceSpan[] = [
{
id: 'pre-execution-validation',
name: 'Workflow Error',
type: 'validation',
duration: Math.max(1, durationMs),
startTime: startTime.toISOString(),
endTime: endTime.toISOString(),
status: 'error',
children: [],
output: { error: message },
},
]
await executionLogger.completeWorkflowExecution({
executionId: this.executionId,
endedAt: new Date().toISOString(),
totalDurationMs: 0,
endedAt: endTime.toISOString(),
totalDurationMs: Math.max(1, durationMs),
costSummary,
finalOutput: null,
traceSpans: [],
finalOutput: { error: message },
traceSpans: syntheticErrorSpan,
})
if (this.requestId) {
@@ -170,7 +206,7 @@ export class LoggingSession {
}
}
async safeCompleteWithError(error?: any): Promise<void> {
async safeCompleteWithError(error?: SessionErrorCompleteParams): Promise<void> {
try {
await this.completeWithError(error)
} catch (enhancedError) {