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
string
required
The instance to stream logs from.
boolean
When
true, keeps the stream open and waits for new logs. The stream terminates when the instance shuts down.StringMatcher
Only stream logs from matching containers.
CallOptions
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.
Record<string, string>
Labels shared by every line in the block, such as the container the lines came from.
LogBlock_Line[]
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
StringMatcher
The instances to fetch logs for.
TimestampRange
The time range to read, as
after and before timestamps.StringMatcher
Only return logs from matching containers.
number
The maximum number of lines to return per page.
Uint8Array
The
paginationCursor from a previous response, to read the next page.CallOptions
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aFetchInstanceLogsResponse.
LogLine[]
The matching lines. Each has a
timestamp, content, the stream it came from, its labels, and a source such as containers, kubernetes, or kmsg.Uint8Array
Pass this cursor to a subsequent call to read the next page.
number
How long logs are retained for the workspace, in days.
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
string
required
The instance to read metrics for.
Timestamp
Only return metrics on or after this timestamp.
Timestamp
Only return metrics up to this timestamp.
MetricResource[]
Which metrics to return:
CPU, CPU_BREAKDOWN, IO_WAIT, MEMORY, or STORAGE.CallOptions
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
string
required
The instance to read egress records for.
TimestampRange
Restricts the records to a time range, as
after and before timestamps.number
default:"20000"
The maximum number of records to return.
Uint8Array
The
paginationCursor from a previous response, to read the next page.CallOptions
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aFetchInstanceEgressResponse with records and a paginationCursor. Each EgressRecord carries:
Timestamp
When the request was observed.
string
The domain that was resolved.
EgressAction
The action applied:
ALLOW, DENY, ADVISORY_DENY, or ACTION_UNKNOWN.string
The rule matcher that led to the action, when one applied.
string[]
The IP addresses the domain resolved to.
compute.listInstanceNotifications()
List instance notification events. Each instance appears at most once, carrying its most recent state change.
Example
API reference
Arguments and options
StringMatcher
Only return events for matching instances. When omitted, events for all instances are returned.
bigint
The maximum number of events to return. The response is always capped to an internal maximum as well.
boolean
When
true, only returns pending events that have not yet been delivered.CallOptions
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.