# ExecutionTrackerService

Import it from `@grafloria/angular`.

ExecutionTracker Service

Tracks workflow/process execution with history. Useful for debugging, replay, and analytics.

Features:
- Execution session tracking
- Step-by-step execution history
- Current execution state
- Performance metrics
- Replay capability

```ts
@Injectable({ providedIn: 'root' })
export class ExecutionTrackerService
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `currentSession$` |  |  | Observable of current execution session. Emits null when no session is active. |
| `executionState$` |  |  | Observable of current execution state. |

**Methods**

- `startSession(metadata?: Record<string, any>): string` — Start new execution session.
- `completeSession(sessionId: string): void` — Complete execution session.
- `pauseSession(sessionId: string): void` — Pause execution session.
- `resumeSession(sessionId: string): void` — Resume execution session.
- `failSession(sessionId: string, error: { message: string; code?: string; stack?: string }): void` — Fail execution session with error.
- `getSession(sessionId: string): ExecutionSession | null` — Get execution session by ID.
- `getCurrentSession(): ExecutionSession | null` — Get current execution session.
- `getAllSessions(): ExecutionSession[]` — Get all execution sessions.
- `clearSessions(): void` — Clear all execution sessions.
- `startStep(sessionId: string, nodeId: string, nodeType: string, input?: any): string` — Start execution step.
- `completeStep(stepId: string, output?: any): void` — Complete execution step.
- `failStep(stepId: string, error: { message: string; code?: string; stack?: string }): void` — Fail execution step with error.
- `skipStep(stepId: string): void` — Skip execution step.
- `getStep(stepId: string): ExecutionStep | null` — Get execution step by ID.
- `getSteps(sessionId: string): ExecutionStep[]` — Get all steps for session.
- `getSessionStats(sessionId: string): { totalSteps: number; completedSteps: number; errorSteps: number; skippedSteps: number; avgStepDuration: number; totalDuration: number; } | null` — Get execution statistics for session.

**Example**

```typescript
constructor(private executionTracker: ExecutionTrackerService) {}

startWorkflow() {
  const sessionId = this.executionTracker.startSession();

  // Track each step
  const stepId = this.executionTracker.startStep(sessionId, 'node-1', 'task');
  // ... execute node logic ...
  this.executionTracker.completeStep(stepId, { result: 'success' });

  // Complete session
  this.executionTracker.completeSession(sessionId);
}
```
