> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/go-and-rust-guide/guides/observe-events.md).

# Observe events

Subscribe to lifecycle, wallet, and progress notifications in Go and Rust.

Subscribe to SDK events before starting operations on your SDK context. Log safe event metadata to correlate your application's requests with SDK activity.

## Attach an event subscriber

These subscribers log event kinds without printing results, decrypted values, or error payloads.

{% tabs %}
{% tab title="Go" %}

```go
subscription, err := sdk.SubscribeEvents(ctx, zama.EventHandlers{
	OnEvent: func(_ context.Context, correlation zama.EventCorrelation, event zama.SDKEvent) error {
		log.Printf("SDK event %s (operation %s)", event.Kind, correlation.OperationID)
		return nil
	},
	OnWalletAccountChanged: func(context.Context, zama.EventCorrelation, zama.WalletAccountChanged) error {
		log.Print("SDK wallet account changed")
		return nil
	},
	OnProgress: func(_ context.Context, _ zama.EventCorrelation, progress zama.OperationProgress) error {
		log.Printf("SDK progress %s", progress.Kind)
		return nil
	},
})
if err != nil {
	return err
}
defer subscription.Close()
```

To subscribe when the context is created, set `config.Events` before `CreateContext` instead. `correlation.OperationID` identifies the RPC operation; the event's `SDKOperationID` identifies the SDK's multi-step operation.
{% endtab %}

{% tab title="Rust" %}

```rust
use zama_sdk::{EventContext, EventHandler, Notification, async_trait};

pub struct Diagnostics;

#[async_trait]
impl EventHandler for Diagnostics {
    async fn on_notification(
        &self,
        context: EventContext,
        notification: Notification,
    ) -> anyhow::Result<()> {
        match notification {
            Notification::Lifecycle(event) => {
                eprintln!("SDK event {} (sequence {})", event.kind, context.sequence);
            }
            Notification::WalletAccountChanged { .. } => eprintln!("SDK wallet account changed"),
            Notification::Progress(progress) => eprintln!("SDK progress {}", progress.kind),
            _ => {}
        }
        Ok(())
    }
}
```

Pass the handler to the builder with `client.sdk(config).events(Diagnostics).build().await?`. The subscription is active when `build()` returns. Handle unknown notification variants without failing.
{% endtab %}
{% endtabs %}

## Keep delivery responsive

Return promptly from event callbacks. If your log sink fails, return an error: the SDK operation continues. A callback panic is reported as `CALLBACK_FAILED`, and the subscription keeps delivering events.

The daemon holds at most 256 unacknowledged events per subscription. A subscriber that falls further behind loses its event channel with `EVENT_BACKPRESSURE`. Do not use events as a durable audit log or as the only record of a transaction outcome.

A replacement subscription receives future events only. Watch for a closed event channel as described in [Recover from disconnections](https://docs.zama.org/protocol/sdk/go-and-rust-guide/guides/recover-from-disconnections.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/go-and-rust-guide/guides/observe-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
