Documentation
¶
Index ¶
- Variables
- func GetAWSEnvironmentVariables() map[string]string
- func GetAllEnvironmentVariables() map[string]map[string]string
- func GetAzureEnvironmentVariables() map[string]string
- func GetGCPEnvironmentVariables() map[string]string
- func LogCloudDetection(logger *slog.Logger)
- type AWSContainerInfo
- type AWSPlatform
- type AzureContainerInfo
- type AzurePlatform
- type CloudProvider
- type ContainerInfo
- type ECSTaskMetadata
- type GCPContainerInfo
- type GCPMetadata
- type GCPPlatform
Constants ¶
This section is empty.
Variables ¶
var ( // BuildRevision holds the vcs commit id information of the program's build. // Available at go version 1.18+ BuildRevision string // BuildTime holds the vcs commit time information of the program's build. // Available at go version 1.18+ BuildTime string // ModuleName holds the module name of the program's build. ModuleName string )
Functions ¶
func GetAWSEnvironmentVariables ¶
GetAWSEnvironmentVariables returns relevant AWS environment variables.
func GetAllEnvironmentVariables ¶
GetAllEnvironmentVariables returns all cloud-related environment variables.
func GetAzureEnvironmentVariables ¶
GetAzureEnvironmentVariables returns a map of relevant Azure environment variables.
func GetGCPEnvironmentVariables ¶
GetGCPEnvironmentVariables returns relevant GCP environment variables.
func LogCloudDetection ¶
LogCloudDetection logs the detected cloud container environment using the provided logger.
Types ¶
type AWSContainerInfo ¶
type AWSContainerInfo struct {
Platform AWSPlatform `json:"platform"`
IsAWSContainer bool `json:"is_aws_container"`
TaskARN string `json:"task_arn,omitempty"` // ECS Task ARN
TaskID string `json:"task_id,omitempty"` // ECS Task ID
TaskFamily string `json:"task_family,omitempty"` // ECS Task Family
TaskRevision string `json:"task_revision,omitempty"` // ECS Task Revision
ContainerName string `json:"container_name,omitempty"` // Name of the container
ContainerID string `json:"container_id,omitempty"` // ID of the container
ClusterName string `json:"cluster_name,omitempty"` // Name of the ECS/EKS cluster
ServiceName string `json:"service_name,omitempty"` // Name of the service (ECS, App Runner, etc.)
Region string `json:"region,omitempty"` // AWS region
AvailabilityZone string `json:"availability_zone,omitempty"` // Availability Zone (for EC2)
AccountID string `json:"account_id,omitempty"` // AWS Account ID
ImageURI string `json:"image_uri,omitempty"` // URI of the container image
LogGroup string `json:"log_group,omitempty"` // Log group for the container
LogStream string `json:"log_stream,omitempty"` // Log stream for the container
CPU string `json:"cpu,omitempty"` // CPU allocated to the container
Memory string `json:"memory,omitempty"` // Memory allocated to the container
LaunchType string `json:"launch_type,omitempty"` // Launch type (EC2 or Fargate)
PodName string `json:"pod_name,omitempty"` // Pod name (for EKS)
Namespace string `json:"namespace,omitempty"` // Namespace (for EKS)
NodeName string `json:"node_name,omitempty"` // Node name (for EKS)
FunctionName string `json:"function_name,omitempty"` // Lambda function name
FunctionVersion string `json:"function_version,omitempty"` // Lambda function version
Hostname string `json:"hostname,omitempty"` // Hostname of the container
}
AWSContainerInfo provides detailed information about the AWS container environment.
func DetectAWSContainer ¶
func DetectAWSContainer() *AWSContainerInfo
DetectAWSContainer detects and returns AWS container information.
func (*AWSContainerInfo) FormatContainerInfo ¶
func (c *AWSContainerInfo) FormatContainerInfo() string
FormatContainerInfo formats container info for logging.
type AWSPlatform ¶
type AWSPlatform string
AWSPlatform represents the type of AWS container platform.
const ( AWSPlatformUnknown AWSPlatform = "Unknown" AWSPlatformECS AWSPlatform = "ECS" AWSPlatformEKS AWSPlatform = "EKS" AWSPlatformFargate AWSPlatform = "Fargate" AWSPlatformLambda AWSPlatform = "Lambda" AWSPlatformEC2 AWSPlatform = "EC2" AWSPlatformAppRunner AWSPlatform = "AppRunner" AWSPlatformBatch AWSPlatform = "Batch" AWSPlatformLightsail AWSPlatform = "Lightsail" )
type AzureContainerInfo ¶
type AzureContainerInfo struct {
Platform AzurePlatform `json:"platform"`
IsAzureContainer bool `json:"is_azure_container"`
ContainerAppName string `json:"container_app_name,omitempty"` // Name of the Azure Container App
Revision string `json:"revision,omitempty"` // Revision of the Azure Container App
Replica string `json:"replica,omitempty"` // Replica name or ID
Region string `json:"region,omitempty"` // Azure region
ResourceGroup string `json:"resource_group,omitempty"` // Resource group name
SubscriptionID string `json:"subscription_id,omitempty"` // Azure subscription ID
Environment string `json:"environment,omitempty"` // Environment name (for Container Apps)
AppName string `json:"app_name,omitempty"` // Application name (if applicable)
PodName string `json:"pod_name,omitempty"` // Pod name (for AKS)
Namespace string `json:"namespace,omitempty"` // Namespace (for AKS)
}
AzureContainerInfo holds information about the Azure container environment.
func DetectAzureContainer ¶
func DetectAzureContainer() *AzureContainerInfo
DetectAzureContainer detects and returns Azure container information.
func (*AzureContainerInfo) FormatContainerInfo ¶
func (c *AzureContainerInfo) FormatContainerInfo() string
FormatContainerInfo formats container info similar to Azure logs.
type AzurePlatform ¶
type AzurePlatform string
AzurePlatform represents the type of Azure container platform.
const ( AzurePlatformUnknown AzurePlatform = "Unknown" AzurePlatformContainerApps AzurePlatform = "ContainerApps" AzurePlatformAppService AzurePlatform = "AppService" AzurePlatformContainerInstance AzurePlatform = "ContainerInstance" AzurePlatformKubernetes AzurePlatform = "AKS" )
type CloudProvider ¶
type CloudProvider string
CloudProvider represents the cloud provider.
const ( ProviderUnknown CloudProvider = "Unknown" ProviderAWS CloudProvider = "AWS" ProviderAzure CloudProvider = "Azure" ProviderGCP CloudProvider = "GCP" )
func (CloudProvider) String ¶
func (p CloudProvider) String() string
String returns the string representation of the CloudProvider.
type ContainerInfo ¶
type ContainerInfo struct {
Provider CloudProvider `json:"provider"`
Platform string `json:"platform"` // Specific platform (ECS, AKS, GKE, etc.)
IsContainer bool `json:"is_container"` // Indicates if running in a container
AppName string `json:"app_name,omitempty"` // Application name (if applicable)
ContainerID string `json:"container_id,omitempty"` // Container ID
ContainerName string `json:"container_name,omitempty"` // Container name
Revision string `json:"revision,omitempty"` // Revision or version of the container
Replica string `json:"replica,omitempty"` // Replica name or ID
Cluster string `json:"cluster,omitempty"` // Cluster name (if applicable)
Region string `json:"region,omitempty"` // Cloud region
AccountID string `json:"account_id,omitempty"` // Account ID (if applicable)
ProjectID string `json:"project_id,omitempty"` // For GCP
Hostname string `json:"hostname,omitempty"` // Hostname of the container
Environment string `json:"environment,omitempty"` // Environment (e.g., production, staging)
LogGroup string `json:"log_group,omitempty"` // Log group (if applicable)
LogStream string `json:"log_stream,omitempty"` // Log stream (if applicable)
// Provider-specific info.
AWS *AWSContainerInfo `json:"aws,omitempty"`
Azure *AzureContainerInfo `json:"azure,omitempty"`
GCP *GCPContainerInfo `json:"gcp,omitempty"`
}
ContainerInfo provides unified container information across cloud providers.
func DetectCloudContainer ¶
func DetectCloudContainer() *ContainerInfo
DetectCloudContainer detects which cloud provider and container platform is being used.
func (*ContainerInfo) FormatInfo ¶
func (c *ContainerInfo) FormatInfo() string
FormatInfo returns a formatted string of container information.
type ECSTaskMetadata ¶
type ECSTaskMetadata struct {
Cluster string `json:"Cluster"`
TaskARN string `json:"TaskARN"`
Family string `json:"Family"`
Revision string `json:"Revision"`
DesiredStatus string `json:"DesiredStatus"`
KnownStatus string `json:"KnownStatus"`
LaunchType string `json:"LaunchType"`
AvailabilityZone string `json:"AvailabilityZone"`
Containers []struct {
Name string `json:"Name"`
ContainerID string `json:"ContainerID"`
Image string `json:"Image"`
ImageID string `json:"ImageID"`
LogOptions struct {
LogGroup string `json:"awslogs-group"`
LogStream string `json:"awslogs-stream"`
Region string `json:"awslogs-region"`
} `json:"LogOptions"`
} `json:"Containers"`
}
ECSTaskMetadata represents ECS task metadata from the metadata endpoint.
type GCPContainerInfo ¶
type GCPContainerInfo struct {
Platform GCPPlatform `json:"platform"`
IsGCPContainer bool `json:"is_gcp_container"`
ProjectID string `json:"project_id,omitempty"` // GCP Project ID
ServiceName string `json:"service_name,omitempty"` // Service name (for Cloud Run)
ServiceVersion string `json:"service_version,omitempty"` // Service version (for Cloud Run)
ServiceRevision string `json:"service_revision,omitempty"` // Service revision (for Cloud Run)
InstanceID string `json:"instance_id,omitempty"` // Instance ID (for Cloud Run, Functions)
InstanceName string `json:"instance_name,omitempty"` // Instance name (for Compute Engine)
Region string `json:"region,omitempty"` // GCP region
Zone string `json:"zone,omitempty"` // GCP zone (for Compute Engine)
ClusterName string `json:"cluster_name,omitempty"` // GKE cluster name
PodName string `json:"pod_name,omitempty"` // Pod name (for GKE)
Namespace string `json:"namespace,omitempty"` // Namespace (for GKE)
NodeName string `json:"node_name,omitempty"` // Node name (for GKE)
ContainerName string `json:"container_name,omitempty"` // Container name (for GKE)
FunctionName string `json:"function_name,omitempty"` // Cloud Function name
FunctionRegion string `json:"function_region,omitempty"` // Cloud Function region
FunctionEntryPoint string `json:"function_entry_point,omitempty"` // Cloud Function entry point
LogName string `json:"log_name,omitempty"` // Log name for the service
TraceID string `json:"trace_id,omitempty"` // Trace ID for Cloud Functions
Hostname string `json:"hostname,omitempty"` // Hostname of the container
ServiceAccount string `json:"service_account,omitempty"` // Service account email (for Cloud Run, Functions)
NumericProjectID string `json:"numeric_project_id,omitempty"` // Numeric project ID (for GCP)
}
GCPContainerInfo provides detailed information about the GCP container environment.
func DetectGCPContainer ¶
func DetectGCPContainer() *GCPContainerInfo
DetectGCPContainer detects and returns GCP container information
func (*GCPContainerInfo) FormatContainerInfo ¶
func (c *GCPContainerInfo) FormatContainerInfo() string
FormatContainerInfo formats GCP container info for logging.
type GCPMetadata ¶
type GCPMetadata struct {
ProjectID string `json:"project-id"`
NumericProjectID int64 `json:"numeric-project-id"`
InstanceID string `json:"instance-id"`
InstanceName string `json:"instance-name"`
Zone string `json:"zone"`
}
GCPMetadata represents metadata from GCP metadata server.
type GCPPlatform ¶
type GCPPlatform string
GCPPlatform represents the type of GCP container platform.
const ( GCPPlatformUnknown GCPPlatform = "Unknown" GCPPlatformGKE GCPPlatform = "GKE" // Google Kubernetes Engine GCPPlatformCloudRun GCPPlatform = "CloudRun" // Cloud Run GCPPlatformAppEngine GCPPlatform = "AppEngine" // App Engine GCPPlatformComputeEngine GCPPlatform = "ComputeEngine" // Compute Engine GCPPlatformCloudFunction GCPPlatform = "CloudFunction" // Cloud Functions )