client.observability reads what an instance produced. Stream logs while an instance runs, fetch logs for a time range after the fact, or read the DNS egress records collected for an instance.
Resource metrics and instance state notifications are served by the Compute service rather than the Observability service, so they are called on client.compute. They are documented here because they answer the same kind of question. See Compute observability for what the platform collects.
The examples on this page use a Compute client:
observability.streamInstanceLogs()
Stream the logs of one instance. With follow set, the call waits for additional logs and terminates when the instance shuts down.
Example
API reference
Arguments and options
When
true, keeps the stream open and waits for new logs. The stream terminates when the instance shuts down.Cancellation, timeout, and header options. See Shared call options.
Return value
Returns an async iterable ofLogBlock. Each block batches lines from the same container to reduce bytes on the wire, so blocks from different containers can interleave.
Labels shared by every line in the block, such as the container the lines came from.
The batched lines. Each has a
timestamp, the line content, and the stream it came from, such as stdout or stderr.InvalidArgument. An unknown instance ID fails with NotFound.
observability.fetchInstanceLogs()
Fetch logs for one or more instances over a time range. The instances can still be running.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aFetchInstanceLogsResponse.
The matching lines. Each has a
timestamp, content, the stream it came from, its labels, and a source such as containers, kubernetes, or kmsg.compute.getInstanceMetrics()
Return resource usage metrics for an instance. Metrics can be queried while the instance is still running.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aGetInstanceMetricsResponse with timeSeries, one or more series carrying the requested metrics. Each series holds a shared timestamps array with named doubles, integers, and strings series aligned to it.
If the instance does not exist, the call fails with NotFound.
observability.fetchInstanceEgress()
Fetch the egress records collected for an instance. Each record captures a resolved domain and the action that the egress policy applied.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aFetchInstanceEgressResponse with records and a paginationCursor. Each EgressRecord carries:
compute.listInstanceNotifications()
List instance notification events. Each instance appears at most once, carrying its most recent state change.
Example
API reference
Arguments and options
Only return events for matching instances. When omitted, events for all instances are returned.
The maximum number of events to return. The response is always capped to an internal maximum as well.
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aListInstanceNotificationsResponse with events, ordered by emitted time with the most recent first. Each InstanceEventMetadata carries emittedAt, instanceId, tenantId, the instance status, and its labels.
Related documentation
Compute observability
Logs, metrics, and instance debugging on the platform.
Egress policy
Control and audit outbound traffic from instances.
Run commands
Execute commands in a container on an instance.