Class GoogleCloudRunMetadata
- Namespace
- Temporalio.Extensions.Gcp.CloudRun.Id
- Assembly
- Temporalio.Extensions.Gcp.CloudRun.Id.dll
Reads Google Cloud Run instance metadata to derive a Temporal worker identity on both Cloud Run worker pools and services.
public sealed class GoogleCloudRunMetadata
- Inheritance
-
GoogleCloudRunMetadata
- Inherited Members
Remarks
Most callers should register a CloudRunIdPlugin on Plugins, which fetches this metadata once at connect time and applies the worker identity automatically. This type is exposed for advanced use, for example reading Identity directly. WARNING: Google Cloud Run support is experimental.
Properties
Identity
Gets the worker identity derived from the metadata. This is
{InstanceId}@{Revision}, falling back to {InstanceId}@{Name} when the
revision is empty, or just {InstanceId} when both are empty.
public string Identity { get; }
Property Value
InstanceId
Gets the Cloud Run instance id read from the metadata server.
public string InstanceId { get; }
Property Value
Name
Gets the Cloud Run worker pool or service name, resolved from the
CLOUD_RUN_WORKER_POOL environment variable and then the K_SERVICE
environment variable, or an empty string if neither is set.
public string Name { get; }
Property Value
Revision
Gets the Cloud Run revision name, resolved from the CLOUD_RUN_REVISION environment
variable and then the K_REVISION environment variable, or an empty string if
neither is set.
public string Revision { get; }
Property Value
Methods
FetchAsync(Uri?, TimeSpan?, CancellationToken)
Fetch Cloud Run metadata. The metadata server URI and request timeout default when null.
public static Task<GoogleCloudRunMetadata> FetchAsync(Uri? metadataUri = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
metadataUriUriMetadata server URI for the instance id, or null for the default.
timeoutTimeSpan?Timeout for the metadata request, or null for the default.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<GoogleCloudRunMetadata>
The resolved Cloud Run metadata.
Remarks
The name and revision are read from environment variables that Cloud Run injects:
CLOUD_RUN_WORKER_POOL then K_SERVICE for the name, and
CLOUD_RUN_REVISION then K_REVISION for the revision. Worker pools receive
the CLOUD_RUN_ variables and services receive the K_ variables. The
instance id is read from the metadata server, which is available on both and requires the
Metadata-Flavor: Google request header.
Exceptions
- InvalidOperationException
Thrown when the instance id cannot be read from the metadata server (it is unreachable, times out, or returns an empty id), which usually means the process is not running on a Google Cloud Run worker pool or service.