add trace starts for each object type
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"go.infratographer.com/x/gidx"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// IsUser checks the provided id has the metal user prefix.
|
||||
@@ -29,8 +31,27 @@ func (s *service) IsAssignableResource(id gidx.PrefixedID) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func stringIDs(ids []gidx.PrefixedID) []string {
|
||||
result := make([]string, len(ids))
|
||||
|
||||
for i, id := range ids {
|
||||
result[i] = id.String()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Assignuser assigns the provided users to the given resource ids.
|
||||
func (s *service) AssignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
||||
ctx, span := tracer.Start(ctx, "AssignUser",
|
||||
trace.WithAttributes(
|
||||
attribute.String("user.id", userID.String()),
|
||||
attribute.StringSlice("user.resource_assignments", stringIDs(resourceIDs)),
|
||||
),
|
||||
)
|
||||
|
||||
defer span.End()
|
||||
|
||||
var totalResources, rolesChanged, assignmentsChanged int
|
||||
|
||||
mlogger := s.logger.With("member.id", userID.String())
|
||||
@@ -74,6 +95,15 @@ func (s *service) AssignUser(ctx context.Context, userID gidx.PrefixedID, resour
|
||||
|
||||
// UnassignUser removes the assignment for the provided user id to the given resources.
|
||||
func (s *service) UnassignUser(ctx context.Context, userID gidx.PrefixedID, resourceIDs ...gidx.PrefixedID) error {
|
||||
ctx, span := tracer.Start(ctx, "UnassignUser",
|
||||
trace.WithAttributes(
|
||||
attribute.String("user.id", userID.String()),
|
||||
attribute.StringSlice("user.resource_assignments", stringIDs(resourceIDs)),
|
||||
),
|
||||
)
|
||||
|
||||
defer span.End()
|
||||
|
||||
for _, resourceID := range resourceIDs {
|
||||
rlogger := s.logger.With("user.id", userID, "resource.id", resourceID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user