1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-03-29 21:47:00 +02:00

[chore]: enable int-conversion rule of perfsprint ()

[perfsprint](https://github.com/catenacyber/perfsprint) is a linter for
performance, aiming at usages of fmt.Sprintf which have faster
alternatives.

This PR enables int-conversion rule

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2024-11-14 19:17:37 +01:00 committed by GitHub
parent 0678ffac68
commit 61e9b35139
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 7 deletions
.golangci.yml
bridge/opentracing
exporters/zipkin/internal/internaltest
internal
internaltest
shared/internaltest
sdk/internal/internaltest

@ -22,6 +22,7 @@ linters:
- govet - govet
- ineffassign - ineffassign
- misspell - misspell
- perfsprint
- revive - revive
- staticcheck - staticcheck
- tenv - tenv
@ -61,10 +62,11 @@ issues:
text: "calls to (.+) only in main[(][)] or init[(][)] functions" text: "calls to (.+) only in main[(][)] or init[(][)] functions"
linters: linters:
- revive - revive
# It's okay to not run gosec in a test. # It's okay to not run gosec and perfsprint in a test.
- path: _test\.go - path: _test\.go
linters: linters:
- gosec - gosec
- perfsprint
# Ignoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand) # Ignoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand)
# as we commonly use it in tests and examples. # as we commonly use it in tests and examples.
- text: "G404:" - text: "G404:"
@ -154,6 +156,12 @@ linters-settings:
locale: US locale: US
ignore-words: ignore-words:
- cancelled - cancelled
perfsprint:
err-error: false
errorf: false
int-conversion: true
sprintf1: false
strconcat: false
revive: revive:
# Sets the default failure confidence. # Sets the default failure confidence.
# This means that linting errors with less than 0.8 confidence will be ignored. # This means that linting errors with less than 0.8 confidence will be ignored.

@ -6,6 +6,7 @@ package opentracing // import "go.opentelemetry.io/otel/bridge/opentracing"
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"strings" "strings"
"sync" "sync"
@ -532,7 +533,7 @@ func otTagToOTelAttr(k string, v interface{}) attribute.KeyValue {
case int64: case int64:
return key.Int64(val) return key.Int64(val)
case uint64: case uint64:
return key.String(fmt.Sprintf("%d", val)) return key.String(strconv.FormatUint(val, 10))
case float64: case float64:
return key.Float64(val) return key.Float64(val)
case int8: case int8:
@ -552,7 +553,7 @@ func otTagToOTelAttr(k string, v interface{}) attribute.KeyValue {
case int: case int:
return key.Int(val) return key.Int(val)
case uint: case uint:
return key.String(fmt.Sprintf("%d", val)) return key.String(strconv.FormatUint(uint64(val), 10))
case string: case string:
return key.String(val) return key.String(val)
default: default:

@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/exporters/zipkin/intern
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) { go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) _ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done() wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) }(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
} }
wg.Wait() wg.Wait()
done <- struct{}{} done <- struct{}{}

@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/internal/internaltest"
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) { go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) _ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done() wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) }(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
} }
wg.Wait() wg.Wait()
done <- struct{}{} done <- struct{}{}

@ -9,6 +9,7 @@ package internaltest
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) { go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) _ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done() wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) }(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
} }
wg.Wait() wg.Wait()
done <- struct{}{} done <- struct{}{}

@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/sdk/internal/internalte
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) { go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version)) _ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done() wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i)) }(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
} }
wg.Wait() wg.Wait()
done <- struct{}{} done <- struct{}{}