mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
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:
committed by
GitHub
parent
bbbf1c2941
commit
6c9e0ec88b
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user