Skip to content

Conversation

steved
Copy link
Contributor

@steved steved commented Apr 11, 2025

We would find it useful to track aggregated metrics outside of the spans emitted.

Copy link
Collaborator

@rueian rueian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a benchmark to compare WithAttributeSet and WithAttributes.

func BenchmarkWithAttributes(b *testing.B) {
	b.Run("WithAttributeSet", func(b *testing.B) {
		b.ReportAllocs()
		for i := 0; i < b.N; i++ {
			metric.WithAttributeSet(attribute.NewSet(attribute.String("operation", "GET")))
		}
	})
	b.Run("WithAttributes", func(b *testing.B) {
		b.ReportAllocs()
		for i := 0; i < b.N; i++ {
			metric.WithAttributes(attribute.String("operation", "GET"))
		}
	})
}

here is the result:

goarch: arm64
pkg: github.com/redis/rueidis/rueidisotel
cpu: Apple M1 Pro
BenchmarkWithAttributes
BenchmarkWithAttributes/WithAttributeSet
BenchmarkWithAttributes/WithAttributeSet-10         	32767585	        34.79 ns/op	      64 B/op	       1 allocs/op
BenchmarkWithAttributes/WithAttributes
BenchmarkWithAttributes/WithAttributes-10           	14976411	        79.85 ns/op	     144 B/op	       3 allocs/op
PASS

We should avoid WithAttributes.

@rueian rueian merged commit 6f93229 into redis:main Apr 11, 2025
34 checks passed
@rueian
Copy link
Collaborator

rueian commented Apr 11, 2025

Thanks @steved !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants