diff --git a/idgenerator/aws/xray/aws_xray_idgenerator.go b/idgenerator/aws/xray/aws_xray_idgenerator.go index cdeb8559967..bca0f4c2692 100644 --- a/idgenerator/aws/xray/aws_xray_idgenerator.go +++ b/idgenerator/aws/xray/aws_xray_idgenerator.go @@ -18,6 +18,7 @@ import ( crand "crypto/rand" "encoding/binary" "encoding/hex" + "errors" "math/rand" "strconv" "sync" @@ -26,16 +27,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -const ( - errConvertTimeToHex errorConst = "cannot convert current timestamp to hex" -) - -type errorConst string - -func (e errorConst) Error() string { - return string(e) -} - type IDGenerator struct { sync.Mutex randSource *rand.Rand @@ -45,10 +36,7 @@ type IDGenerator struct { func NewIDGenerator() *IDGenerator { gen := &IDGenerator{} var rngSeed int64 - err := binary.Read(crand.Reader, binary.LittleEndian, &rngSeed) - if err != nil { - panic(err) - } + _ = binary.Read(crand.Reader, binary.LittleEndian, &rngSeed) gen.randSource = rand.New(rand.NewSource(rngSeed)) return gen } @@ -71,8 +59,7 @@ func (gen *IDGenerator) NewTraceID() (trace.TraceID, error) { tid := trace.TraceID{} currentTime, err := getCurrentTimeHex() if err != nil { - var nilTraceID trace.TraceID - return nilTraceID, err + return trace.TraceID{}, err } copy(tid[:4], currentTime) gen.randSource.Read(tid[4:]) @@ -84,7 +71,7 @@ func getCurrentTimeHex() ([]uint8, error) { currentTime := time.Now().Unix() currentTimeHex, err := hex.DecodeString(strconv.FormatInt(currentTime, 16)) if err != nil { - return nil, errConvertTimeToHex + return nil, errors.New("cannot convert current timestamp to hex") } return currentTimeHex, nil }