# Session 12: Events, Monitoring & Message Tracing

## Summary

Server-side event system (system events, advisory messages), HTTP monitoring endpoints (varz, connz, routez, etc.), and message tracing infrastructure.

## Scope

| Go File | Features | Feature IDs | Go LOC |
|---------|----------|-------------|--------|
| server/events.go | 97 | 854–950 | 2,445 |
| server/monitor.go | 70 | 2166–2235 | 3,257 |
| server/monitor_sort_opts.go | 16 | 2236–2251 | 48 |
| server/msgtrace.go | 35 | 2405–2439 | 569 |
| **Total** | **218** | | **6,319** |

## .NET Classes

- `EventsHandler` — system event publishing
- `MonitoringHandler` — HTTP monitoring endpoints
- `ConnInfo`, `ClosedState` — connection monitoring types
- `HealthZErrorType` — health check error types
- `MsgTrace`, `MsgTraceEvent`, `MsgTraceEvents` — message tracing
- `MessageTracer` — tracing engine
- Various sort option types (16 types)

## Test Files

| Test File | Tests | Test IDs |
|-----------|-------|----------|
| server/events_test.go | 52 | 299–350 |
| server/monitor_test.go | 103 | 2064–2166 |
| server/msgtrace_test.go | 33 | 2329–2361 |
| **Total** | **188** | |

## Dependencies

- Session 01 (Foundation Types)
- Session 08 (Client Connection)
- Session 09 (Server Core Part 1)
- Session 11 (Accounts)

## .NET Target Location

- `dotnet/src/ZB.MOM.NatsNet.Server/Monitoring/`
- `dotnet/src/ZB.MOM.NatsNet.Server/Events/`

## Notes

- Monitor endpoints map to ASP.NET Core minimal API or controller endpoints
- Events system uses internal pub/sub — publishes to `$SYS.*` subjects
- This is a larger session (~6.3K LOC) but the code is relatively straightforward
- Monitor has 103 tests — allocate time accordingly
