diff --git a/cmd/create/environment.go b/cmd/create/environment.go index 0248cfec..401eca11 100644 --- a/cmd/create/environment.go +++ b/cmd/create/environment.go @@ -62,6 +62,7 @@ func init() { func execute(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() // Validate accounts parameter if err := validateAccounts(accounts); err != nil { log.Fatal("Invalid accounts parameter: ", err) @@ -70,9 +71,10 @@ func execute(cmd *cobra.Command) { EnvName: envName, Accounts: util.SplitProviderAccount(accounts), ProvisioningType: provisioningType, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to create environment ", err) } } diff --git a/cmd/delete/environment.go b/cmd/delete/environment.go index c7ec94cf..edd25617 100644 --- a/cmd/delete/environment.go +++ b/cmd/delete/environment.go @@ -2,6 +2,7 @@ package delete import ( "github.com/dream11/odin/internal/service" + "github.com/dream11/odin/pkg/util" environment "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -34,11 +35,13 @@ func init() { func execute(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() err := environmentClient.DeleteEnvironment(&ctx, &environment.DeleteEnvironmentRequest{ EnvName: name, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to delete environment ", err) } } diff --git a/cmd/deploy/service-set.go b/cmd/deploy/service-set.go index 59a106cf..ef624ae9 100644 --- a/cmd/deploy/service-set.go +++ b/cmd/deploy/service-set.go @@ -2,6 +2,7 @@ package deploy import ( "encoding/json" + "github.com/dream11/odin/pkg/util" "os" "github.com/dream11/odin/pkg/config" @@ -36,6 +37,7 @@ func executeDeployServiceSet(cmd *cobra.Command) { env = config.EnsureEnvPresent(env) ctx := cmd.Context() + traceId := util.GenerateTraceId() if serviceSetName == "" && provisioningFile == "" { log.Fatal("Please provide either --name or --file.") } @@ -61,7 +63,7 @@ func executeDeployServiceSet(cmd *cobra.Command) { deployServiceSetRequest.Name = serviceSetName } - err := serviceClient.DeployServiceSet(&ctx, &deployServiceSetRequest) + err := serviceClient.DeployServiceSet(&ctx, &deployServiceSetRequest, traceId) if err != nil { log.Fatal("Failed to deploy service ", err) } diff --git a/cmd/deploy/service.go b/cmd/deploy/service.go index 3a201218..c7eb0be9 100644 --- a/cmd/deploy/service.go +++ b/cmd/deploy/service.go @@ -2,6 +2,7 @@ package deploy import ( "encoding/json" + "github.com/dream11/odin/pkg/util" "os" "github.com/dream11/odin/internal/service" @@ -43,6 +44,7 @@ func init() { func execute(cmd *cobra.Command) { env = config.EnsureEnvPresent(env) ctx := cmd.Context() + traceId := util.GenerateTraceId() if (serviceName == "" && serviceVersion == "") && (definitionFile != "" && provisioningFile != "") { definitionData, err := os.ReadFile(definitionFile) if err != nil { @@ -69,9 +71,10 @@ func execute(cmd *cobra.Command) { EnvName: env, ServiceDefinition: &definitionProto, ProvisioningConfig: provisioningProto, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to deploy service ", err) } } else if (serviceName != "" && serviceVersion != "") && (definitionFile == "" && provisioningFile == "") { @@ -82,9 +85,10 @@ func execute(cmd *cobra.Command) { ServiceName: serviceName, ServiceVersion: serviceVersion, }, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to deploy service ", err) } } else { diff --git a/cmd/describe/component.go b/cmd/describe/component.go index fdc9b678..c7611115 100644 --- a/cmd/describe/component.go +++ b/cmd/describe/component.go @@ -3,6 +3,7 @@ package describe import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" serviceBackend "github.com/dream11/odin/internal/service" comp "github.com/dream11/odin/proto/gen/go/dream11/od/component/v1" @@ -45,12 +46,14 @@ func executeDescribeComponentType(cmd *cobra.Command) { "version": componentVersion, } ctx := cmd.Context() + traceId := util.GenerateTraceId() response, err := componentClient.DescribeComponentType(&ctx, &comp.DescribeComponentTypeRequest{ ComponentType: componentName, Params: params, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to describe service: ", err) } diff --git a/cmd/describe/environment.go b/cmd/describe/environment.go index f8545055..ab2380bf 100644 --- a/cmd/describe/environment.go +++ b/cmd/describe/environment.go @@ -3,6 +3,7 @@ package describe import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/constant" @@ -36,6 +37,7 @@ func init() { func executeEnv(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() params := map[string]string{} if serviceName != "" { @@ -47,9 +49,10 @@ func executeEnv(cmd *cobra.Command) { response, err := environmentClient.DescribeEnvironment(&ctx, &environment.DescribeEnvironmentRequest{ Params: params, EnvName: name, - }) + }, traceId) if err != nil { + log.Info("TraceId: ", traceId) log.Fatal("Failed to describe environment ", err) } diff --git a/cmd/describe/service.go b/cmd/describe/service.go index 0afcd4b3..a254f4f0 100644 --- a/cmd/describe/service.go +++ b/cmd/describe/service.go @@ -3,6 +3,7 @@ package describe import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" "strconv" serviceBackend "github.com/dream11/odin/internal/service" @@ -57,11 +58,12 @@ func execute(cmd *cobra.Command) { } ctx := cmd.Context() + traceId := util.GenerateTraceId() response, err := serviceClient.DescribeService(&ctx, &service.DescribeServiceRequest{ ServiceName: serviceName, Version: serviceVersion, Params: params, - }) + }, traceId) if err != nil { log.Fatal("Failed to describe service: ", err) diff --git a/cmd/list/componentType.go b/cmd/list/componentType.go index 72b65333..eaa6be4a 100644 --- a/cmd/list/componentType.go +++ b/cmd/list/componentType.go @@ -3,6 +3,7 @@ package list import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/constant" @@ -36,6 +37,7 @@ func init() { func componentExecute(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() params := make(map[string]string) // Add non-empty parameters to the map @@ -49,7 +51,7 @@ func componentExecute(cmd *cobra.Command) { // Make the API call with the populated parameters response, err := componentTypeClient.ListComponentType(&ctx, &component.ListComponentTypeRequest{ Params: params, - }) + }, traceId) if err != nil { log.Fatal("Failed to list component types ", err) diff --git a/cmd/list/environment.go b/cmd/list/environment.go index f3ddda2c..6e4b2570 100644 --- a/cmd/list/environment.go +++ b/cmd/list/environment.go @@ -3,6 +3,7 @@ package list import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" "strconv" "github.com/dream11/odin/internal/service" @@ -41,13 +42,14 @@ func init() { func execute(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() response, err := environmentClient.ListEnvironments(&ctx, &environment.ListEnvironmentRequest{ Params: map[string]string{ "name": name, "account": account, "provisioningType": provisioningType, "displayAll": strconv.FormatBool(displayAll)}, - }) + }, traceId) if err != nil { log.Fatal("Failed to list environments ", err) diff --git a/cmd/list/service.go b/cmd/list/service.go index 9339be3f..56853574 100644 --- a/cmd/list/service.go +++ b/cmd/list/service.go @@ -3,6 +3,7 @@ package list import ( "encoding/json" "fmt" + "github.com/dream11/odin/pkg/util" "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/constant" @@ -36,11 +37,12 @@ func init() { func listService(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() response, err := serviceClient.ListService(&ctx, &serviceProto.ListServiceRequest{ Name: serviceName, Version: version, Tags: tags, - }) + }, traceId) if err != nil { log.Fatal("Failed to list services ", err) diff --git a/cmd/operate/component.go b/cmd/operate/component.go index 87c36bde..4ca31622 100644 --- a/cmd/operate/component.go +++ b/cmd/operate/component.go @@ -2,6 +2,7 @@ package operate import ( "encoding/json" + "github.com/dream11/odin/pkg/util" "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/config" @@ -54,6 +55,7 @@ func execute(cmd *cobra.Command) { env = config.EnsureEnvPresent(env) ctx := cmd.Context() + traceId := util.GenerateTraceId() //validate the variables var optionsData map[string]interface{} @@ -89,7 +91,7 @@ func execute(cmd *cobra.Command) { IsComponentOperation: true, Operation: operation, Config: config, - }) + }, traceId) if err != nil { log.Fatal("Failed to operate on component", err) diff --git a/cmd/operate/service.go b/cmd/operate/service.go index a1fe1ea9..df733b54 100644 --- a/cmd/operate/service.go +++ b/cmd/operate/service.go @@ -2,6 +2,7 @@ package operate import ( "encoding/json" + "github.com/dream11/odin/pkg/util" "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/config" @@ -44,6 +45,7 @@ func executeOperateService(cmd *cobra.Command) { env = config.EnsureEnvPresent(env) ctx := cmd.Context() + traceId := util.GenerateTraceId() //validate the variables var optionsData map[string]interface{} @@ -78,7 +80,7 @@ func executeOperateService(cmd *cobra.Command) { IsComponentOperation: false, Operation: operation, Config: config, - }) + }, traceId) if err != nil { log.Fatal("Failed to operate on service", err) diff --git a/cmd/release/service.go b/cmd/release/service.go index 1229b7f8..bccd2f4d 100644 --- a/cmd/release/service.go +++ b/cmd/release/service.go @@ -2,6 +2,7 @@ package release import ( "encoding/json" + "github.com/dream11/odin/pkg/util" "os" "path/filepath" "strings" @@ -38,6 +39,7 @@ func init() { func execute(cmd *cobra.Command) { ctx := cmd.Context() + traceId := util.GenerateTraceId() var err error @@ -102,7 +104,7 @@ func execute(cmd *cobra.Command) { } serviceReleaseRequest.ProvisioningConfigs = provisioningConfigMap serviceReleaseRequest.ServiceDefinition = &definitionProto - err = serviceClient.ReleaseService(&ctx, &serviceReleaseRequest) + err = serviceClient.ReleaseService(&ctx, &serviceReleaseRequest, traceId) if err != nil { log.Fatal("Failed to release service ", err) } diff --git a/cmd/undeploy/service.go b/cmd/undeploy/service.go index f909977c..39e60e0d 100644 --- a/cmd/undeploy/service.go +++ b/cmd/undeploy/service.go @@ -3,6 +3,7 @@ package undeploy import ( "github.com/dream11/odin/internal/service" "github.com/dream11/odin/pkg/config" + "github.com/dream11/odin/pkg/util" serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -39,11 +40,12 @@ func execute(cmd *cobra.Command) { envName = config.EnsureEnvPresent(envName) ctx := cmd.Context() + traceId := util.GenerateTraceId() err := serviceClient.UndeployService(&ctx, &serviceProto.UndeployServiceRequest{ EnvName: envName, ServiceName: name, - }) + }, traceId) if err != nil { log.Fatal("Failed to undeploy service ", err) diff --git a/go.mod b/go.mod index f8a7bb38..005888c6 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.17 require ( github.com/briandowns/spinner v1.23.0 + github.com/google/uuid v1.3.0 github.com/olekukonko/tablewriter v0.0.5 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index a005099a..5fafd1d8 100644 --- a/go.sum +++ b/go.sum @@ -955,6 +955,7 @@ github.com/google/s2a-go v0.1.0/go.mod h1:OJpEgntRZo8ugHpF9hkoLJbS5dSI20XZeXJ9JV github.com/google/s2a-go v0.1.3/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A= github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= diff --git a/internal/service/client.go b/internal/service/client.go index 2ab3f4bf..63d6c641 100644 --- a/internal/service/client.go +++ b/internal/service/client.go @@ -15,8 +15,14 @@ import ( "google.golang.org/grpc/metadata" ) -func grpcClient(ctx *context.Context) (*grpc.ClientConn, *context.Context, error) { +func grpcClient(ctx *context.Context, traceIdOptional ...string) (*grpc.ClientConn, *context.Context, error) { appConfig := config.GetConfig() + + traceId := "" + if len(traceIdOptional) > 0 { + traceId = traceIdOptional[0] + } + if appConfig.BackendAddress == "" { log.Fatal("Cannot create grpc client: Backend address is empty in config! Run `odin configure` to set backend address") } @@ -43,6 +49,6 @@ func grpcClient(ctx *context.Context) (*grpc.ClientConn, *context.Context, error return nil, nil, err } // Enrich context with authorisation metadata - requestCtx := metadata.AppendToOutgoingContext(*ctx, "Authorization", fmt.Sprintf("Bearer %s", appConfig.AccessToken)) + requestCtx := metadata.AppendToOutgoingContext(*ctx, "Authorization", fmt.Sprintf("Bearer %s", appConfig.AccessToken), "TraceId", traceId) return conn, &requestCtx, nil } diff --git a/internal/service/component.go b/internal/service/component.go index c573f559..39e275bf 100644 --- a/internal/service/component.go +++ b/internal/service/component.go @@ -18,8 +18,8 @@ import ( type Component struct{} // OperateComponent operate Component -func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto.OperateServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto.OperateServiceRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -56,8 +56,8 @@ func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto } // ListComponentType List component types -func (e *Component) ListComponentType(ctx *context.Context, request *component.ListComponentTypeRequest) (*component.ListComponentTypeResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Component) ListComponentType(ctx *context.Context, request *component.ListComponentTypeRequest, traceId string) (*component.ListComponentTypeResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return nil, err } @@ -71,8 +71,8 @@ func (e *Component) ListComponentType(ctx *context.Context, request *component.L } // DescribeComponentType List component types -func (e *Component) DescribeComponentType(ctx *context.Context, request *component.DescribeComponentTypeRequest) (*component.DescribeComponentTypeResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Component) DescribeComponentType(ctx *context.Context, request *component.DescribeComponentTypeRequest, traceId string) (*component.DescribeComponentTypeResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return nil, err } diff --git a/internal/service/environment.go b/internal/service/environment.go index a779333b..48f499cc 100644 --- a/internal/service/environment.go +++ b/internal/service/environment.go @@ -16,8 +16,8 @@ import ( type Environment struct{} // ListEnvironments List environments -func (e *Environment) ListEnvironments(ctx *context.Context, request *environment.ListEnvironmentRequest) (*environment.ListEnvironmentResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Environment) ListEnvironments(ctx *context.Context, request *environment.ListEnvironmentRequest, traceId string) (*environment.ListEnvironmentResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return nil, err } @@ -31,8 +31,8 @@ func (e *Environment) ListEnvironments(ctx *context.Context, request *environmen } // CreateEnvironment creates environment -func (e *Environment) CreateEnvironment(ctx *context.Context, request *environment.CreateEnvironmentRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Environment) CreateEnvironment(ctx *context.Context, request *environment.CreateEnvironmentRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -69,8 +69,8 @@ func (e *Environment) CreateEnvironment(ctx *context.Context, request *environme } // DeleteEnvironment deletes environment -func (e *Environment) DeleteEnvironment(ctx *context.Context, request *environment.DeleteEnvironmentRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Environment) DeleteEnvironment(ctx *context.Context, request *environment.DeleteEnvironmentRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -126,8 +126,8 @@ func (e *Environment) UpdateEnvironment(ctx *context.Context, request *environme } // DescribeEnvironment shows environment details including services and resources in it -func (e *Environment) DescribeEnvironment(ctx *context.Context, request *environment.DescribeEnvironmentRequest) (*environment.DescribeEnvironmentResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Environment) DescribeEnvironment(ctx *context.Context, request *environment.DescribeEnvironmentRequest, traceId string) (*environment.DescribeEnvironmentResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return nil, err } diff --git a/internal/service/service.go b/internal/service/service.go index 74045fa3..03ee5121 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -18,8 +18,9 @@ import ( type Service struct{} // DeployService deploys service -func (e *Service) DeployService(ctx *context.Context, request *serviceProto.DeployServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) DeployService(ctx *context.Context, request *serviceProto.DeployServiceRequest, traceId string) error { + + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -59,8 +60,8 @@ func (e *Service) DeployService(ctx *context.Context, request *serviceProto.Depl } // DeployServiceSet deploys service-set -func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.DeployServiceSetRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.DeployServiceSetRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -103,8 +104,8 @@ func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.D } // DeployReleasedService deploys service -func (e *Service) DeployReleasedService(ctx *context.Context, request *serviceProto.DeployReleasedServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) DeployReleasedService(ctx *context.Context, request *serviceProto.DeployReleasedServiceRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -148,8 +149,8 @@ func (e *Service) DeployReleasedService(ctx *context.Context, request *servicePr } // UndeployService undeploy service -func (e *Service) UndeployService(ctx *context.Context, request *serviceProto.UndeployServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) UndeployService(ctx *context.Context, request *serviceProto.UndeployServiceRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -191,9 +192,9 @@ func (e *Service) UndeployService(ctx *context.Context, request *serviceProto.Un return err } -// OperateService :service operatioms -func (e *Service) OperateService(ctx *context.Context, request *serviceProto.OperateServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +// OperateService :service operations +func (e *Service) OperateService(ctx *context.Context, request *serviceProto.OperateServiceRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -234,8 +235,8 @@ func (e *Service) OperateService(ctx *context.Context, request *serviceProto.Ope } // ListService deploys service -func (e *Service) ListService(ctx *context.Context, request *serviceProto.ListServiceRequest) (*serviceProto.ListServiceResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) ListService(ctx *context.Context, request *serviceProto.ListServiceRequest, traceId string) (*serviceProto.ListServiceResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return &serviceProto.ListServiceResponse{}, err } @@ -245,8 +246,8 @@ func (e *Service) ListService(ctx *context.Context, request *serviceProto.ListSe } // ReleaseService :service operatioms -func (e *Service) ReleaseService(ctx *context.Context, request *serviceProto.ReleaseServiceRequest) error { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) ReleaseService(ctx *context.Context, request *serviceProto.ReleaseServiceRequest, traceId string) error { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return err } @@ -308,8 +309,8 @@ func (e *Service) ConvertToDeployServiceSetRequest(serviceSet *serviceDto.Servic } // DescribeService describe service -func (e *Service) DescribeService(ctx *context.Context, request *serviceProto.DescribeServiceRequest) (*serviceProto.DescribeServiceResponse, error) { - conn, requestCtx, err := grpcClient(ctx) +func (e *Service) DescribeService(ctx *context.Context, request *serviceProto.DescribeServiceRequest, traceId string) (*serviceProto.DescribeServiceResponse, error) { + conn, requestCtx, err := grpcClient(ctx, traceId) if err != nil { return nil, err } diff --git a/main.go b/main.go index 3dc8bbe9..4c265627 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,14 @@ import ( _ "github.com/dream11/odin/cmd/undeploy" _ "github.com/dream11/odin/cmd/update" _ "github.com/dream11/odin/internal/ui" + "github.com/sirupsen/logrus" ) func main() { + // Configure Logrus to disable timestamps + logrus.SetFormatter(&logrus.TextFormatter{ + TimestampFormat: "2006-01-02 15:04:05", // Custom format + FullTimestamp: true, + }) cmd.Execute() } diff --git a/pkg/util/util.go b/pkg/util/util.go index 4f764aca..70259936 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -2,8 +2,10 @@ package util import ( "fmt" + "github.com/google/uuid" "net" "strings" + "time" v1 "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1" ) @@ -51,3 +53,8 @@ func GenerateResponseMessageComponentSpecific(response *v1.ServiceResponse, comp } return message } + +// GenerateTraceId generates a trace id +func GenerateTraceId() string { + return fmt.Sprintf("%d-%s", time.Now().Unix(), strings.Split(uuid.New().String(), "-")[0]) +}