guard against unconfigured tracer
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
merrors "github.com/asim/go-micro/v3/errors"
|
||||
@@ -125,13 +127,16 @@ func (s Service) getInMemoryServiceUser() proto.Account {
|
||||
// ListAccounts implements the AccountsServiceHandler interface
|
||||
// the query contains account properties
|
||||
func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest, out *proto.ListAccountsResponse) (err error) {
|
||||
ctx, span := accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
|
||||
defer span.End()
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "page_size", Value: attribute.Int64Value(int64(in.PageSize))},
|
||||
attribute.KeyValue{Key: "page_token", Value: attribute.StringValue(in.PageToken)},
|
||||
)
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "page_size", Value: attribute.Int64Value(int64(in.PageSize))},
|
||||
attribute.KeyValue{Key: "page_token", Value: attribute.StringValue(in.PageToken)},
|
||||
)
|
||||
}
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -278,12 +283,15 @@ func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]strin
|
||||
|
||||
// GetAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, out *proto.Account) (err error) {
|
||||
ctx, span := accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
|
||||
defer span.End()
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account_id", Value: attribute.StringValue(in.Id)},
|
||||
)
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account_id", Value: attribute.StringValue(in.Id)},
|
||||
)
|
||||
}
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -333,12 +341,15 @@ func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, ou
|
||||
|
||||
// CreateAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountRequest, out *proto.Account) (err error) {
|
||||
ctx, span := accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
|
||||
defer span.End()
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
}
|
||||
|
||||
if !s.hasAccountManagementPermissions(ctx) {
|
||||
return merrors.Forbidden(s.id, "no permission for CreateAccount")
|
||||
@@ -472,12 +483,15 @@ func (s Service) rollbackCreateAccount(ctx context.Context, acc *proto.Account)
|
||||
// read only fields are ignored
|
||||
// TODO how can we unset specific values? using the update mask
|
||||
func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountRequest, out *proto.Account) (err error) {
|
||||
ctx, span := accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
|
||||
defer span.End()
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
}
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -645,8 +659,11 @@ var updatableAccountPaths = map[string]struct{}{
|
||||
|
||||
// DeleteAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountRequest, out *empty.Empty) (err error) {
|
||||
ctx, span := accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
|
||||
defer span.End()
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
|
||||
defer span.End()
|
||||
}
|
||||
|
||||
if !s.hasAccountManagementPermissions(ctx) {
|
||||
return merrors.Forbidden(s.id, "no permission for DeleteAccount")
|
||||
|
||||
Reference in New Issue
Block a user