Skip to content

Commit

Permalink
Merge branch 'main' into bug-5717-obtain-xray-sampling-rules-silent-fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedle authored Jun 27, 2024
2 parents 82112a5 + b2a21f6 commit 1d6d944
Show file tree
Hide file tree
Showing 61 changed files with 367 additions and 256 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ linters:
- misspell
- revive
- staticcheck
- tenv
- typecheck
- unconvert
- unparam
- unused

issues:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Custom attributes targeting metrics recorded by the `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` are not ignored anymore. (#5129)
- Use `c.FullPath()` method to set `http.route` attribute in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#5734)
- The double setup in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace/example` that caused duplicate traces. (#5564)
- Out-of-bounds panic in case of invalid span ID in `go.opentelemetry.io/contrib/propagators/b3`. (#5754)
- Non-200 HTTP status codes when retrieving sampling rules in `go.opentelemetry.io/contrib/samplers/aws/xray` now return an error. (#5718)

### Deprecated
Expand All @@ -44,6 +45,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Improve performance of `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664)
- Improve performance of `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664)
- Update `go.opentelemetry.io/contrib/config` to latest released configuration schema which introduces breaking changes where `Attributes` is now a `map[string]interface{}`. (#5758)

## [1.27.0/0.52.0/0.21.0/0.7.0/0.2.0] - 2024-05-21

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ update-all-otel-deps:
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_SRC_DIR=tmp/opentelememetry-configuration

# The SHA matching the current version of the opentelemetry-configuration schema to use
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=f38ac7c3a499ae5f81924ef9c455c27a56130562
OPENTELEMETRY_CONFIGURATION_JSONSCHEMA_VERSION=v0.2.0

# Cleanup temporary directory
genjsonschema-cleanup:
Expand Down
2 changes: 1 addition & 1 deletion bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (o *Core) Write(ent zapcore.Entry, fields []zapcore.Field) error {
r.SetTimestamp(ent.Time)
r.SetBody(log.StringValue(ent.Message))
r.SetSeverity(convertLevel(ent.Level))
r.SetSeverityText(ent.Level.String())

// TODO: Handle zap.Namespace.
// TODO: Handle ent.LoggerName.

r.AddAttributes(o.attr...)
Expand Down
112 changes: 109 additions & 3 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package otelzap

import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -22,6 +24,10 @@ var (
loggerName = "name"
testKey = "key"
testValue = "value"
testEntry = zapcore.Entry{
Level: zap.InfoLevel,
Message: testMessage,
}
)

func TestCore(t *testing.T) {
Expand All @@ -34,9 +40,10 @@ func TestCore(t *testing.T) {
got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, zap.InfoLevel.String(), got.SeverityText())
assert.Equal(t, 1, got.AttributesLen())
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testKey, string(kv.Key))
assert.Equal(t, testKey, kv.Key)
assert.Equal(t, testValue, value2Result(kv.Value))
return true
})
Expand All @@ -56,11 +63,12 @@ func TestCore(t *testing.T) {
got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, zap.InfoLevel.String(), got.SeverityText())
assert.Equal(t, 2, got.AttributesLen())

index := 0
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testCases[index][0], string(kv.Key))
assert.Equal(t, testCases[index][0], kv.Key)
assert.Equal(t, testCases[index][1], value2Result(kv.Value))
index++
return true
Expand All @@ -78,11 +86,12 @@ func TestCore(t *testing.T) {
got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, zap.InfoLevel.String(), got.SeverityText())
assert.Equal(t, 3, got.AttributesLen())

index := 0
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testCases[index][0], string(kv.Key))
assert.Equal(t, testCases[index][0], kv.Key)
assert.Equal(t, testCases[index][1], value2Result(kv.Value))
index++
return true
Expand Down Expand Up @@ -113,6 +122,7 @@ func TestCoreEnabled(t *testing.T) {
got := r.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, zap.InfoLevel.String(), got.SeverityText())
}

func TestNewCoreConfiguration(t *testing.T) {
Expand Down Expand Up @@ -174,3 +184,99 @@ func TestConvertLevel(t *testing.T) {
}
}
}

func BenchmarkCoreWrite(b *testing.B) {
benchmarks := []struct {
name string
fields []zapcore.Field
}{
{
name: "10 fields",
fields: []zapcore.Field{
zap.Int16("a", 1),
zap.String("k", "a"),
zap.Bool("k", true),
zap.Time("k", time.Unix(1000, 1000)),
zap.Binary("k", []byte{1, 2}),
zap.ByteString("k", []byte{1, 2}),
zap.Object("k", loggable{true}),
zap.Array("k", loggable{true}),
zap.String("k", "a"),
zap.Ints("k", []int{1, 2}),
},
},
{
name: "20 fields",
fields: []zapcore.Field{
zap.Int16("a", 1),
zap.String("k", "a"),
zap.Bool("k", true),
zap.Time("k", time.Unix(1000, 1000)),
zap.Binary("k", []byte{1, 2}),
zap.ByteString("k", []byte{1, 2}),
zap.Object("k", loggable{true}),
zap.String("k", "a"),
zap.Array("k", loggable{true}),
zap.Ints("k", []int{1, 2}),
zap.Int16("a", 1),
zap.String("k", "a"),
zap.Bool("k", true),
zap.Time("k", time.Unix(1000, 1000)),
zap.Binary("k", []byte{1, 2}),
zap.ByteString("k", []byte{1, 2}),
zap.Object("k", loggable{true}),
zap.Array("k", loggable{true}),
zap.String("k", "a"),
zap.Ints("k", []int{1, 2}),
},
},
{ // Benchmark with nested namespace
name: "Namespace",
fields: []zapcore.Field{
zap.Namespace("a"),
zap.Int16("a", 1),
zap.String("k", "a"),
zap.Bool("k", true),
zap.Time("k", time.Unix(1000, 1000)),
zap.Binary("k", []byte{1, 2}),
zap.Namespace("b"),
zap.Binary("k", []byte{1, 2}),
zap.Object("k", loggable{true}),
zap.String("k", "a"),
zap.Array("k", loggable{true}),
zap.Ints("k", []int{1, 2}),
},
},
}

for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
zc := NewCore(loggerName)
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := zc.Write(testEntry, bm.fields)
if err != nil {
b.Errorf("Unexpected error: %v", err)
}
}
})
})
}

for _, bm := range benchmarks {
b.Run(fmt.Sprint("With", bm.name), func(b *testing.B) {
zc := NewCore(loggerName)
zc1 := zc.With(bm.fields)
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := zc1.Write(testEntry, []zapcore.Field{})
if err != nil {
b.Errorf("Unexpected error: %v", err)
}
}
})
})
}
}
2 changes: 1 addition & 1 deletion bridges/otelzap/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (a *arrayEncoder) AppendDuration(v time.Duration) { a.AppendInt64(v.Nanosec
func (a *arrayEncoder) AppendInt32(v int32) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendInt16(v int16) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendInt8(v int8) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendTime(v time.Time) { a.AppendInt64(int64(v.UnixNano())) }
func (a *arrayEncoder) AppendTime(v time.Time) { a.AppendInt64(v.UnixNano()) }
func (a *arrayEncoder) AppendUint(v uint) { a.AppendUint64(uint64(v)) }
func (a *arrayEncoder) AppendUint32(v uint32) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendUint16(v uint16) { a.AppendInt64(int64(v)) }
Expand Down
3 changes: 2 additions & 1 deletion bridges/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions bridges/prometheus/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down
46 changes: 39 additions & 7 deletions config/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 1d6d944

Please sign in to comment.