向宁 d3015d63f2 feat: add OpenTelemetry tracing, metrics, and logging
- Create internal/common/otel.go with InitOTel() for tracing + metrics + logs
- Add otelgin middleware for automatic Gin HTTP span creation
- Add OTelEndpoint config (default: 192.168.1.154:4316)
- Export all signals via OTLP gRPC to OTel Collector
2026-05-17 22:08:03 +08:00

56 lines
1.5 KiB
Go

package common
import (
"fmt"
"os"
)
type Config struct {
RustFSEndpoint string
RustFSAccessKeyID string
RustFSSecretAccessKey string
RustFSRegion string
ServerPort string
AuthAPIKey string
RequestTimeout int
GRPCAuthAddr string
OTelEndpoint string
}
func LoadConfig() *Config {
return &Config{
RustFSEndpoint: getEnv("RUSTFS_ENDPOINT_URL", "http://192.168.1.154:9000"),
RustFSAccessKeyID: getEnv("RUSTFS_ACCESS_KEY_ID", ""),
RustFSSecretAccessKey: getEnv("RUSTFS_SECRET_ACCESS_KEY", ""),
RustFSRegion: getEnv("RUSTFS_REGION", "us-east-1"),
ServerPort: getEnv("SERVER_PORT", "8080"),
AuthAPIKey: getEnv("AUTH_API_KEY", ""),
RequestTimeout: 30,
GRPCAuthAddr: getEnv("GRPC_AUTH_ADDR", ""),
OTelEndpoint: getEnv("OTEL_ENDPOINT", "192.168.1.154:4316"),
}
}
func (c *Config) Validate() error {
if c.AuthAPIKey == "" && c.GRPCAuthAddr == "" {
return fmt.Errorf("AUTH_API_KEY or GRPC_AUTH_ADDR is required")
}
if c.RustFSAccessKeyID == "" {
return fmt.Errorf("RUSTFS_ACCESS_KEY_ID is required")
}
if c.RustFSSecretAccessKey == "" {
return fmt.Errorf("RUSTFS_SECRET_ACCESS_KEY is required")
}
if c.RustFSEndpoint == "" {
return fmt.Errorf("RUSTFS_ENDPOINT_URL is required")
}
return nil
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}