Skip to content

Commit

Permalink
Move trace ID generation into a single function
Browse files Browse the repository at this point in the history
In the future, we might optimize this to use a less-intensive method to generate IDs
  • Loading branch information
josephschorr committed Jan 10, 2025
1 parent 45be0b3 commit e9079aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions internal/graph/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"time"

"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/samber/lo"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -128,7 +127,7 @@ func (cc *ConcurrentChecker) Check(ctx context.Context, req ValidatedCheckReques
if debugInfo == nil {
debugInfo = &v1.DebugInformation{
Check: &v1.CheckDebugTrace{
TraceId: uuid.NewString(),
TraceId: NewTraceID(),
SourceId: nodeID,
},
}
Expand Down Expand Up @@ -1328,7 +1327,7 @@ func combineResponseMetadata(ctx context.Context, existing *v1.ResponseMeta, res

debugInfo := &v1.DebugInformation{
Check: &v1.CheckDebugTrace{
TraceId: uuid.NewString(),
TraceId: NewTraceID(),
SourceId: nodeID,
},
}
Expand Down
13 changes: 13 additions & 0 deletions internal/graph/traceid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package graph

import (
"github.com/google/uuid"
)

// NewTraceID generates a new trace ID. The trace IDs will only be unique with
// a single dispatch request tree and should not be used for any other purpose.
// This function currently uses the UUID library to generate a new trace ID,
// which means it should not be invoked from performance-critical code paths.
func NewTraceID() string {
return uuid.NewString()
}
3 changes: 1 addition & 2 deletions internal/services/v1/bulkcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/google/uuid"
"github.com/jzelinskie/stringz"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -199,7 +198,7 @@ func (bc *bulkChecker) checkBulkPermissions(ctx context.Context, req *v1.CheckBu
},
Results: localResults,
Duration: durationpb.New(time.Duration(0)),
TraceId: uuid.New().String(),
TraceId: graph.NewTraceID(),
SourceId: debugInfo.Check.SourceId,
},
}
Expand Down

0 comments on commit e9079aa

Please sign in to comment.