Skip to content
Cloudflare Docs

Observability

Agent instances uses the observability property to emit various internal events that can be used for logging and monitoring.

The default behavior is to console.log() the event value.

{
"type": "event-type",
"timestamp": "2024-01-01T00:00:00.000Z",
"displayMessage": "Connection established",
"payload": { ... }
}

This can be configured by overriding the property with an implementation of the Observability interface. This interface has a single emit() method that takes an ObservabilityEvent.

JavaScript
import { Agent } from "agents";
const customObservability = {
async emit(event) {
// Custom logic here (e.g., send to external logging service)
console.log(`[${event.type}]`, event.displayMessage);
},
};
class MyAgent extends Agent {
observability = customObservability;
}

Or, alternatively, you can set the property to undefined to ignore all events.

JavaScript
import { Agent } from "agents";
class MyAgent extends Agent {
observability = undefined;
}