mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(telemetry): implement request tracing identifier
Introduce a middleware layer to attach a unique identifier to each HTTP request for observability purposes. The identifier is propagated via the X-Request-ID header, allowing for correlation of logs and events across distributed system components.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/ez-api/ez-api/internal/dto"
|
||||
"github.com/ez-api/ez-api/internal/model"
|
||||
"github.com/ez-api/ez-api/internal/service"
|
||||
"github.com/ez-api/foundation/provider"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -43,6 +44,9 @@ func (h *Handler) CreateProvider(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
providerType := provider.NormalizeType(req.Type)
|
||||
googleLocation := provider.DefaultGoogleLocation(providerType, req.GoogleLocation)
|
||||
|
||||
group := strings.TrimSpace(req.Group)
|
||||
if group == "" {
|
||||
group = "default"
|
||||
@@ -59,11 +63,11 @@ func (h *Handler) CreateProvider(c *gin.Context) {
|
||||
|
||||
provider := model.Provider{
|
||||
Name: req.Name,
|
||||
Type: req.Type,
|
||||
Type: strings.TrimSpace(req.Type),
|
||||
BaseURL: req.BaseURL,
|
||||
APIKey: req.APIKey,
|
||||
GoogleProject: strings.TrimSpace(req.GoogleProject),
|
||||
GoogleLocation: strings.TrimSpace(req.GoogleLocation),
|
||||
GoogleLocation: googleLocation,
|
||||
Group: group,
|
||||
Models: strings.Join(req.Models, ","),
|
||||
Status: status,
|
||||
@@ -122,12 +126,18 @@ func (h *Handler) UpdateProvider(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
nextType := strings.TrimSpace(existing.Type)
|
||||
if t := strings.TrimSpace(req.Type); t != "" {
|
||||
nextType = t
|
||||
}
|
||||
nextTypeLower := provider.NormalizeType(nextType)
|
||||
|
||||
update := map[string]any{}
|
||||
if strings.TrimSpace(req.Name) != "" {
|
||||
update["name"] = req.Name
|
||||
}
|
||||
if strings.TrimSpace(req.Type) != "" {
|
||||
update["type"] = req.Type
|
||||
update["type"] = strings.TrimSpace(req.Type)
|
||||
}
|
||||
if strings.TrimSpace(req.BaseURL) != "" {
|
||||
update["base_url"] = req.BaseURL
|
||||
@@ -140,6 +150,8 @@ func (h *Handler) UpdateProvider(c *gin.Context) {
|
||||
}
|
||||
if strings.TrimSpace(req.GoogleLocation) != "" {
|
||||
update["google_location"] = strings.TrimSpace(req.GoogleLocation)
|
||||
} else if provider.IsVertexFamily(nextTypeLower) && strings.TrimSpace(existing.GoogleLocation) == "" {
|
||||
update["google_location"] = provider.DefaultGoogleLocation(nextTypeLower, "")
|
||||
}
|
||||
if req.Models != nil {
|
||||
update["models"] = strings.Join(req.Models, ",")
|
||||
|
||||
Reference in New Issue
Block a user