Skip to content

feat(observability): Wire Observer into gateway runtime#87

Merged
rexlunae merged 1 commit intomainfrom
feature/observer-integration
Feb 27, 2026
Merged

feat(observability): Wire Observer into gateway runtime#87
rexlunae merged 1 commit intomainfrom
feature/observer-integration

Conversation

@rexlunae
Copy link
Owner

Integrates the Observer trait into the gateway's request lifecycle.

Changes

  • Add SharedObserver type alias and optional parameter to run_gateway
  • Thread observer through handle_connectiondispatch_text_message
  • Record events at key lifecycle points:
    • LlmRequest — before provider calls (provider, model, message count)
    • LlmResponse — after calls (duration, success, error message)
    • ToolCallStart — before each tool execution
    • ToolCall — after (duration, success)

Usage

Call sites currently pass None for the observer. To enable observability:

use rustyclaw_core::observability::{LogObserver, Observer};
use std::sync::Arc;

let observer: Arc<dyn Observer> = Arc::new(LogObserver);
run_gateway(..., Some(observer), cancel).await?;

Next Steps

  • Wire LogObserver by default when a config flag is set
  • Extract token counts from provider responses
  • Add ObserverMetric recording (latencies, queue depth)

Integrates the Observer trait into the gateway's request lifecycle:

- Add SharedObserver type alias and optional parameter to run_gateway
- Thread observer through handle_connection → dispatch_text_message
- Record LlmRequest event before provider calls (provider, model, message count)
- Record LlmResponse event after (duration, success, error message)
- Record ToolCallStart before each tool execution
- Record ToolCall after (duration, success)

Call sites pass None for now; actual observer backends can be wired in
by passing Arc<LogObserver> or CompositeObserver at startup.
@rexlunae
Copy link
Owner Author

LGTM! Clean integration:

  • Observer threaded through the right path (run_gateway → handle_connection → dispatch_text_message)
  • Events recorded at correct lifecycle points with timing
  • Good TODOs for token extraction

One future enhancement: consider adding ObserverEvent::Error when provider calls fail (in the Err(err) branch around line 1910). But that's minor — this gets the infrastructure in place.

Ship it! 🚢

@rexlunae rexlunae merged commit 83c5588 into main Feb 27, 2026
12 of 13 checks passed
@rexlunae rexlunae deleted the feature/observer-integration branch February 27, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant