diff --git a/logotel/.golangci.yaml b/logotel/.golangci.yaml new file mode 100644 index 0000000..d884b2f --- /dev/null +++ b/logotel/.golangci.yaml @@ -0,0 +1,141 @@ +## 基于 golangci-lint@v1.52.2 +run: + timeout: 1m + build-tags: [ ] + skip-dirs: [ ] + skip-files: [ ] +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + - asasalint + - asciicheck + - bidichk + - bodyclose + - containedctx + - cyclop + - dupl + - durationcheck + - errname + - errorlint + - exhaustive + - exportloopref + - funlen + - gocheckcompilerdirectives + - gochecknoinits + - goconst + - gocritic + - gocyclo + - goimports + - gomnd + - goprintffuncname + - gosec + - lll + - loggercheck + - makezero + - nakedret + - nestif + - nilnil + - noctx + - nolintlint + - prealloc + - predeclared + - promlinter + - reassign + - revive + - rowserrcheck + - stylecheck + - tenv + - testableexamples + - testpackage + - tparallel + - unconvert + - unparam + - usestdlibvars + - wastedassign + - whitespace +linters-settings: + errcheck: + check-type-assertions: true + exclude-functions: [ ] + govet: + enable-all: true + disable: [ ] + cyclop: + max-complexity: 10 + package-average: 0.0 + dupl: + threshold: 150 + exhaustive: + check: + - switch + - map + funlen: + lines: 100 + statements: 60 + gocritic: + disabled-checks: + - commentFormatting + settings: + captLocal: + paramsOnly: false + underef: + skipRecvDeref: false + gocyclo: + min-complexity: 20 + gomnd: + ignored-functions: + - os.Chmod + - os.Mkdir + - os.MkdirAll + - os.OpenFile + - os.WriteFile + - prometheus.ExponentialBuckets + - prometheus.ExponentialBucketsRange + - prometheus.LinearBuckets + lll: + line-length: 240 + nakedret: + max-func-lines: 10 + nestif: + min-complexity: 5 + predeclared: + ignore: "" + q: false + reassign: + patterns: + - ".*" + rowserrcheck: + packages: + - github.com/jmoiron/sqlx + tenv: + all: true + usestdlibvars: + time-month: true + time-layout: true + crypto-hash: true + default-rpc-path: true + os-dev-null: true + sql-isolation-level: true + tls-signature-scheme: true + constant-kind: true + syslog-priority: true +issues: + max-same-issues: 10 + exclude-rules: + - source: "//noinspection" + linters: [ gocritic ] + - path: "_test\\.go" + linters: + - bodyclose + - dupl + - funlen + - goconst + - gosec + - noctx diff --git a/logotel/go.mod b/logotel/go.mod index f7f2f50..432754c 100644 --- a/logotel/go.mod +++ b/logotel/go.mod @@ -3,7 +3,7 @@ module git.blauwelle.com/go/crate/logotel go 1.20 require ( - git.blauwelle.com/go/crate/log v0.8.0 + git.blauwelle.com/go/crate/log v0.9.0 go.opentelemetry.io/otel v1.13.0 go.opentelemetry.io/otel/trace v1.13.0 ) diff --git a/logotel/go.sum b/logotel/go.sum index 3eb48ac..6f418a7 100644 --- a/logotel/go.sum +++ b/logotel/go.sum @@ -1,5 +1,5 @@ -git.blauwelle.com/go/crate/log v0.8.0 h1:TINzuFo330MZIagzdULouwBoLCcLIB4yjI/G1IH0I+0= -git.blauwelle.com/go/crate/log v0.8.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0= +git.blauwelle.com/go/crate/log v0.9.0 h1:H01AQIKcYybeCZGdReBzMoWhkXPQJAoY1t+K0J1asEk= +git.blauwelle.com/go/crate/log v0.9.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/logotel/option.go b/logotel/option.go index b7de4c0..bd762ef 100644 --- a/logotel/option.go +++ b/logotel/option.go @@ -4,13 +4,18 @@ import ( "git.blauwelle.com/go/crate/log/logsdk/logjson" ) +const ( + bytesBufferInitialSize = 512 + bytesBufferMaximumSize = 4096 +) + func newConfig(opts ...Option) *config { cfg := defaultConfig() for _, opt := range opts { opt.apply(cfg) } if !cfg.hasPool { - cfg.bytesBufferPool = logjson.NewBytesBufferPool(512, 4096) + cfg.bytesBufferPool = logjson.NewBytesBufferPool(bytesBufferInitialSize, bytesBufferMaximumSize) } return cfg } diff --git a/logotel/processor.go b/logotel/processor.go index 079c8b2..8f9f89c 100644 --- a/logotel/processor.go +++ b/logotel/processor.go @@ -36,7 +36,8 @@ func (processor *Processor) Process(ctx context.Context, entry logsdk.ReadonlyEn return } - attrs := make([]attribute.KeyValue, 0, len(entry.Fields)+6) + const entryInitSize = 6 + attrs := make([]attribute.KeyValue, 0, len(entry.Fields)+entryInitSize) attrs = append(attrs, attribute.String("log.severity", entry.Level.String())) attrs = append(attrs, attribute.String("log.message", entry.Message)) if entry.Caller.IsValid() {