User guide
When a rule behaves unexpectedly, open its execution record. Inspect the input, matched conditions and resulting actions before editing the definition.
Execution logs provide visibility into when rules execute, what conditions were evaluated, which actions ran, and how long everything took. Use logs for debugging, auditing, and performance monitoring.
Every time a business rule evaluates (whether conditions match or not), the system creates a log entry capturing:
Execution logs list showing rule executions with result status, entity info, and execution time
# List recent logs
curl -X GET "$BASE_URL/api/business_rules/logs?limit=50" \
-H "Authorization: Bearer $API_KEY"
# Get specific log
curl -X GET "$BASE_URL/api/business_rules/logs/{logId}" \
-H "Authorization: Bearer $API_KEY"
# Filter by rule
curl -X GET "$BASE_URL/api/business_rules/logs?ruleId=MATERIAL_CHECK" \
-H "Authorization: Bearer $API_KEY"
Each log entry contains:
{
id: string // Unique log ID
timestamp: string // ISO 8601 timestamp
ruleId: string // Rule that executed
ruleName: string // Human-readable rule name
entityType: string // Entity type (WorkOrder, Order, etc.)
entityId: string // Specific entity ID
eventType: string // Event that triggered (beforeUpdate, etc.)
result: 'SUCCESS' | 'FAILURE' | 'ERROR'
executionTimeMs: number // Total execution time in milliseconds
conditionResult: boolean // Did conditions match?
actionsExecuted: number // How many actions ran
error?: string // Error message if result is ERROR
context: { // Execution context
userId?: string
tenantId: string
organizationId: string
metadata?: Record<string, any>
}
trace: { // Detailed execution trace
conditions: ConditionTrace[]
actions: ActionTrace[]
}
}
Shows how each condition was evaluated:
{
path: string // Field path evaluated
operator: string // Operator used (=, >, etc.)
expectedValue: any // What we were checking for
actualValue: any // What the field actually contained
result: boolean // Did this condition pass?
}
Shows what each action did:
{
type: string // Action type (SET_FIELD, NOTIFY, etc.)
config: Record<string, any> // Action configuration
result: 'SUCCESS' | 'FAILURE' | 'SKIPPED'
executionTimeMs: number // How long this action took
output?: any // Action output (if any)
error?: string // Error message if failed
}
Use filters to find specific executions:
GET /api/business_rules/logs?ruleId=MATERIAL_CHECK
Shows all executions of a specific rule.
GET /api/business_rules/logs?entityType=WorkOrder&entityId=wo-12345
Shows all rules that executed for a specific entity.
GET /api/business_rules/logs?result=FAILURE
Shows only failed executions (conditions matched and rule triggered).
GET /api/business_rules/logs?result=ERROR
Shows only errored executions (something went wrong).
GET /api/business_rules/logs?from=2025-01-01&to=2025-01-31
Shows executions within a specific time period.
GET /api/business_rules/logs?userId=user-abc123
Shows rules triggered by a specific user's actions.
GET /api/business_rules/logs?ruleId=MATERIAL_CHECK&result=FAILURE&from=2025-01-01
All filters can be combined for precise queries.
Problem: Rule not executing when expected
Solution: Check execution logs
Example:
# Check if rule executed for specific work order
GET /api/business_rules/logs?entityType=WorkOrder&entityId=wo-12345&ruleId=MATERIAL_CHECK
Review the trace.conditions array to see actual vs expected values.
Problem: Slow rule execution affecting user experience
Solution: Identify slow rules
executionTimeMstrace.actions to find slow actionsExample:
# Get slowest executions
GET /api/business_rules/logs?sort=executionTimeMs:desc&limit=20
Problem: Need to prove rule compliance for audit
Solution: Export execution logs
# Get all material check executions for audit period
GET /api/business_rules/logs?ruleId=MATERIAL_CHECK&from=2024-01-01&to=2024-12-31&format=csv
Logs show:
Problem: Users reporting rule errors
Solution: Filter error logs
# Get all errors in last 24 hours
GET /api/business_rules/logs?result=ERROR&from=2025-01-22
Review error field for stack traces and error messages.
Default retention: 90 days
Configuration: Set BUSINESS_RULES_LOG_RETENTION_DAYS environment variable:
BUSINESS_RULES_LOG_RETENTION_DAYS=365 # Keep logs for 1 year
Manual cleanup:
# Delete logs older than 30 days
curl -X DELETE "$BASE_URL/api/business_rules/logs?olderThan=30d" \
-H "Authorization: Bearer $API_KEY"
Execution logs are separate from application logs. Application logs use standard levels:
Configuration:
# Set log level in environment
LOG_LEVEL=debug # Show all rule engine internals
LOG_LEVEL=info # Show executions only (default)
LOG_LEVEL=warn # Show only warnings and errors
Detailed execution log showing condition evaluation trace and action results
{
"id": "log-abc123",
"timestamp": "2025-01-23T10:30:00Z",
"ruleId": "MATERIAL_CHECK",
"ruleName": "Check Material Availability",
"entityType": "WorkOrder",
"entityId": "wo-12345",
"eventType": "onStatusChange",
"result": "SUCCESS",
"conditionResult": false,
"executionTimeMs": 15,
"trace": {
"conditions": [
{
"path": "newStatus",
"operator": "=",
"expectedValue": "RELEASED",
"actualValue": "RELEASED",
"result": true
},
{
"path": "materialsAvailable",
"operator": "=",
"expectedValue": false,
"actualValue": true,
"result": false
}
],
"actions": []
}
}
Interpretation:
{
"id": "log-def456",
"timestamp": "2025-01-23T11:00:00Z",
"ruleId": "MATERIAL_CHECK",
"ruleName": "Check Material Availability",
"entityType": "WorkOrder",
"entityId": "wo-67890",
"eventType": "onStatusChange",
"result": "FAILURE",
"conditionResult": true,
"executionTimeMs": 42,
"trace": {
"conditions": [
{
"path": "newStatus",
"operator": "=",
"expectedValue": "RELEASED",
"actualValue": "RELEASED",
"result": true
},
{
"path": "materialsAvailable",
"operator": "=",
"expectedValue": false,
"actualValue": false,
"result": true
}
],
"actions": [
{
"type": "BLOCK_TRANSITION",
"config": {},
"result": "SUCCESS",
"executionTimeMs": 2
},
{
"type": "SHOW_ERROR",
"config": {
"message": "Cannot release work order. Materials not available."
},
"result": "SUCCESS",
"executionTimeMs": 1
},
{
"type": "NOTIFY",
"config": {
"recipients": ["[email protected]"],
"message": "WO wo-67890 blocked: materials unavailable"
},
"result": "SUCCESS",
"executionTimeMs": 35
}
]
}
}
Interpretation:
{
"id": "log-xyz789",
"timestamp": "2025-01-23T12:00:00Z",
"ruleId": "CALCULATE_DISCOUNT",
"ruleName": "Calculate Volume Discount",
"entityType": "Order",
"entityId": "order-555",
"eventType": "beforeSave",
"result": "ERROR",
"conditionResult": true,
"executionTimeMs": 8,
"error": "TypeError: Cannot read property 'quantity' of undefined",
"trace": {
"conditions": [
{
"path": "orderType",
"operator": "=",
"expectedValue": "WHOLESALE",
"actualValue": "WHOLESALE",
"result": true
}
],
"actions": [
{
"type": "SET_FIELD",
"config": {
"field": "discount",
"value": "{{items[0].quantity}} * 0.15"
},
"result": "FAILURE",
"executionTimeMs": 8,
"error": "TypeError: Cannot read property 'quantity' of undefined"
}
]
}
}
Interpretation:
items[0].quantityitems array was empty or undefinedFix: Add condition to check if items exist:
AND Group:
- orderType = "WHOLESALE"
- items IS_NOT_EMPTY
Target execution times:
| Rule Type | Target | Acceptable | Investigate |
|---|---|---|---|
| GUARD | < 10ms | < 50ms | >100ms |
| VALIDATION | < 20ms | < 100ms | > 200ms |
| CALCULATION | < 30ms | < 150ms | > 300ms |
| ACTION | < 100ms | < 500ms | > 1000ms |
| ASSIGNMENT | < 15ms | < 75ms | > 150ms |
Slow action types:
Optimization tips:
Track rule execution volume over time:
GET /api/business_rules/logs/stats?metric=volume&groupBy=hour&from=2025-01-20
Response:
{
"metric": "volume",
"data": [
{ "timestamp": "2025-01-20T00:00:00Z", "count": 1247 },
{ "timestamp": "2025-01-20T01:00:00Z", "count": 892 },
// ...
]
}
Monitor rule reliability:
GET /api/business_rules/logs/stats?metric=successRate&ruleId=MATERIAL_CHECK
Response:
{
"metric": "successRate",
"data": {
"total": 5000,
"success": 4850,
"failure": 100,
"error": 50,
"successRate": 0.97
}
}
Track performance trends:
GET /api/business_rules/logs/stats?metric=avgExecutionTime&groupBy=rule
Response:
{
"metric": "avgExecutionTime",
"data": [
{ "ruleId": "MATERIAL_CHECK", "avgMs": 15.3 },
{ "ruleId": "CALCULATE_DISCOUNT", "avgMs": 42.7 },
{ "ruleId": "SEND_NOTIFICATION", "avgMs": 156.2 }
]
}
Possible causes:
Check:
GET /api/business_rules/rules/{ruleId}Possible causes:
Check:
trace.conditions for actual valuesPossible causes:
Check:
result=ERRORPossible causes:
Check:
Monitor regularly: Set up dashboards to track execution volume, error rates, and performance
Alert on errors: Configure alerts for ERROR results or high failure rates
Rotate logs: Don't keep logs forever – balance compliance needs with storage costs
Analyze patterns: Look for trends in blocked operations, common failures, or slow rules
Document findings: When debugging, add notes to rule descriptions about common issues
Test thoroughly: Use execution logs to verify rules work as expected before enabling in production