mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-05 22:52:46 +00:00
fix(tracing): parsing of fraction (#3705)
* fix(tracing): parsing of fraction * log id
This commit is contained in:
parent
f32e69e5f1
commit
cf6f4d6894
@ -29,7 +29,9 @@ type TokenVerifierRepo struct {
|
|||||||
Query *query.Queries
|
Query *query.Queries
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *TokenVerifierRepo) tokenByID(ctx context.Context, tokenID, userID string) (*usr_model.TokenView, error) {
|
func (repo *TokenVerifierRepo) tokenByID(ctx context.Context, tokenID, userID string) (_ *usr_model.TokenView, err error) {
|
||||||
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
|
defer func() { span.EndWithError(err) }()
|
||||||
token, viewErr := repo.View.TokenByID(tokenID, authz.GetInstance(ctx).InstanceID())
|
token, viewErr := repo.View.TokenByID(tokenID, authz.GetInstance(ctx).InstanceID())
|
||||||
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
||||||
return nil, viewErr
|
return nil, viewErr
|
||||||
@ -78,7 +80,9 @@ func (repo *TokenVerifierRepo) VerifyAccessToken(ctx context.Context, tokenStrin
|
|||||||
if len(splittedToken) != 2 {
|
if len(splittedToken) != 2 {
|
||||||
return "", "", "", "", "", caos_errs.ThrowUnauthenticated(nil, "APP-GDg3a", "invalid token")
|
return "", "", "", "", "", caos_errs.ThrowUnauthenticated(nil, "APP-GDg3a", "invalid token")
|
||||||
}
|
}
|
||||||
|
_, tokenSpan := tracing.NewNamedSpan(ctx, "token")
|
||||||
token, err := repo.tokenByID(ctx, splittedToken[0], splittedToken[1])
|
token, err := repo.tokenByID(ctx, splittedToken[0], splittedToken[1])
|
||||||
|
tokenSpan.EndWithError(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", "", "", caos_errs.ThrowUnauthenticated(err, "APP-BxUSiL", "invalid token")
|
return "", "", "", "", "", caos_errs.ThrowUnauthenticated(err, "APP-BxUSiL", "invalid token")
|
||||||
}
|
}
|
||||||
@ -120,7 +124,9 @@ func (repo *TokenVerifierRepo) VerifierClientID(ctx context.Context, appName str
|
|||||||
return clientID, app.ProjectID, nil
|
return clientID, app.ProjectID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *TokenVerifierRepo) getUserEvents(ctx context.Context, userID, instanceID string, sequence uint64) ([]*models.Event, error) {
|
func (r *TokenVerifierRepo) getUserEvents(ctx context.Context, userID, instanceID string, sequence uint64) (_ []*models.Event, err error) {
|
||||||
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
|
defer func() { span.EndWithError(err) }()
|
||||||
query, err := usr_view.UserByIDQuery(userID, instanceID, sequence)
|
query, err := usr_view.UserByIDQuery(userID, instanceID, sequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||||||
"github.com/zitadel/zitadel/internal/authz/repository/eventsourcing/view"
|
"github.com/zitadel/zitadel/internal/authz/repository/eventsourcing/view"
|
||||||
"github.com/zitadel/zitadel/internal/domain"
|
"github.com/zitadel/zitadel/internal/domain"
|
||||||
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||||
user_model "github.com/zitadel/zitadel/internal/user/model"
|
user_model "github.com/zitadel/zitadel/internal/user/model"
|
||||||
user_view_model "github.com/zitadel/zitadel/internal/user/repository/view/model"
|
user_view_model "github.com/zitadel/zitadel/internal/user/repository/view/model"
|
||||||
)
|
)
|
||||||
@ -18,7 +19,9 @@ func (repo *UserMembershipRepo) Health() error {
|
|||||||
return repo.View.Health()
|
return repo.View.Health()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *UserMembershipRepo) SearchMyMemberships(ctx context.Context) ([]*authz.Membership, error) {
|
func (repo *UserMembershipRepo) SearchMyMemberships(ctx context.Context) (_ []*authz.Membership, err error) {
|
||||||
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
|
defer func() { span.EndWithError(err) }()
|
||||||
memberships, err := repo.searchUserMemberships(ctx)
|
memberships, err := repo.searchUserMemberships(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -26,9 +29,12 @@ func (repo *UserMembershipRepo) SearchMyMemberships(ctx context.Context) ([]*aut
|
|||||||
return userMembershipsToMemberships(memberships), nil
|
return userMembershipsToMemberships(memberships), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *UserMembershipRepo) searchUserMemberships(ctx context.Context) ([]*user_view_model.UserMembershipView, error) {
|
func (repo *UserMembershipRepo) searchUserMemberships(ctx context.Context) (_ []*user_view_model.UserMembershipView, err error) {
|
||||||
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
|
defer func() { span.EndWithError(err) }()
|
||||||
ctxData := authz.GetCtxData(ctx)
|
ctxData := authz.GetCtxData(ctx)
|
||||||
instance := authz.GetInstance(ctx)
|
instance := authz.GetInstance(ctx)
|
||||||
|
ctx, orgSpan := tracing.NewSpan(ctx)
|
||||||
orgMemberships, orgCount, err := repo.View.SearchUserMemberships(&user_model.UserMembershipSearchRequest{
|
orgMemberships, orgCount, err := repo.View.SearchUserMemberships(&user_model.UserMembershipSearchRequest{
|
||||||
Queries: []*user_model.UserMembershipSearchQuery{
|
Queries: []*user_model.UserMembershipSearchQuery{
|
||||||
{
|
{
|
||||||
@ -48,9 +54,11 @@ func (repo *UserMembershipRepo) searchUserMemberships(ctx context.Context) ([]*u
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
orgSpan.EndWithError(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ctx, iamSpan := tracing.NewSpan(ctx)
|
||||||
iamMemberships, iamCount, err := repo.View.SearchUserMemberships(&user_model.UserMembershipSearchRequest{
|
iamMemberships, iamCount, err := repo.View.SearchUserMemberships(&user_model.UserMembershipSearchRequest{
|
||||||
Queries: []*user_model.UserMembershipSearchQuery{
|
Queries: []*user_model.UserMembershipSearchQuery{
|
||||||
{
|
{
|
||||||
@ -70,6 +78,7 @@ func (repo *UserMembershipRepo) searchUserMemberships(ctx context.Context) ([]*u
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
iamSpan.EndWithError(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
|
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
|
||||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
|
||||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
||||||
)
|
)
|
||||||
@ -19,14 +16,10 @@ type Config struct {
|
|||||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
c.ProjectID, _ = rawConfig["projectid"].(string)
|
c.ProjectID, _ = rawConfig["projectid"].(string)
|
||||||
fraction, ok := rawConfig["fraction"].(string)
|
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
||||||
if ok {
|
if err != nil {
|
||||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
return err
|
||||||
if err != nil {
|
|
||||||
return errors.ThrowInternal(err, "GOOGLE-Dsag3", "could not map fraction")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.NewTracer()
|
return c.NewTracer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
|
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
|
||||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
|
||||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||||
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
"github.com/zitadel/zitadel/internal/telemetry/tracing/otel"
|
||||||
)
|
)
|
||||||
@ -17,14 +14,10 @@ type Config struct {
|
|||||||
|
|
||||||
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
func NewTracer(rawConfig map[string]interface{}) (err error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
fraction, ok := rawConfig["fraction"].(string)
|
c.Fraction, err = otel.FractionFromConfig(rawConfig["fraction"])
|
||||||
if ok {
|
if err != nil {
|
||||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
return err
|
||||||
if err != nil {
|
|
||||||
return errors.ThrowInternal(err, "LOG-Dsag3", "could not map fraction")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.NewTracer()
|
return c.NewTracer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,17 +19,33 @@ type Config struct {
|
|||||||
func NewTracerFromConfig(rawConfig map[string]interface{}) (err error) {
|
func NewTracerFromConfig(rawConfig map[string]interface{}) (err error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
c.Endpoint, _ = rawConfig["endpoint"].(string)
|
c.Endpoint, _ = rawConfig["endpoint"].(string)
|
||||||
fraction, ok := rawConfig["fraction"].(string)
|
c.Fraction, err = FractionFromConfig(rawConfig["fraction"])
|
||||||
if ok {
|
if err != nil {
|
||||||
c.Fraction, err = strconv.ParseFloat(fraction, 32)
|
return err
|
||||||
if err != nil {
|
|
||||||
return errors.ThrowInternal(err, "OTEL-Dd2s", "could not map fraction")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.NewTracer()
|
return c.NewTracer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FractionFromConfig(i interface{}) (float64, error) {
|
||||||
|
if i == nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
switch fraction := i.(type) {
|
||||||
|
case float64:
|
||||||
|
return fraction, nil
|
||||||
|
case int:
|
||||||
|
return float64(fraction), nil
|
||||||
|
case string:
|
||||||
|
f, err := strconv.ParseFloat(fraction, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.ThrowInternal(err, "OTEL-SAfe1", "could not map fraction")
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
default:
|
||||||
|
return 0, errors.ThrowInternal(nil, "OTEL-Dd2s", "could not map fraction, unknown type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) NewTracer() error {
|
func (c *Config) NewTracer() error {
|
||||||
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
||||||
exporter, err := otlpgrpc.New(context.Background(), otlpgrpc.WithEndpoint(c.Endpoint), otlpgrpc.WithInsecure())
|
exporter, err := otlpgrpc.New(context.Background(), otlpgrpc.WithEndpoint(c.Endpoint), otlpgrpc.WithInsecure())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user