feat: add X-Instance-Id header and instance_id log field
This commit is contained in:
@@ -32,6 +32,7 @@ type ServerConfig struct {
|
||||
Port string
|
||||
MaxInflightRequests int
|
||||
SessionTTL time.Duration
|
||||
InstanceID string
|
||||
}
|
||||
|
||||
type LoggingConfig struct {
|
||||
@@ -61,6 +62,7 @@ func Load() Config {
|
||||
Port: getEnv("APP_PORT", "8080"),
|
||||
MaxInflightRequests: getEnvNonNegativeInt("MAX_INFLIGHT_REQUESTS", 0),
|
||||
SessionTTL: time.Duration(getEnvPositiveInt("SESSION_TTL_SECONDS", 3600)) * time.Second,
|
||||
InstanceID: getInstanceID("INSTANCE_ID"),
|
||||
},
|
||||
|
||||
Logging: LoggingConfig{
|
||||
@@ -165,3 +167,17 @@ func getEnvSessionStore(key, def string) string {
|
||||
return def
|
||||
}
|
||||
}
|
||||
|
||||
func getInstanceID(key string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
|
||||
host, err := os.Hostname()
|
||||
if err != nil || host == "" {
|
||||
log.Printf("cannot determine hostname, using \"unknown\" for %s: %v", key, err)
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user