-
Notifications
You must be signed in to change notification settings - Fork 228
fix: compact Dalli attributes #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: compact Dalli attributes #1548
Conversation
8c876e2 to
b6c47b1
Compare
| 'net.peer.name' => hostname, | ||
| 'net.peer.port' => port | ||
| } | ||
| }.compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.compact! means one less hash allocation, it can return nil so don't call it on the closing }.
| }.compact | |
| } | |
| attributes.compact! |
84f7aa8 to
1b906ed
Compare
robertlaurin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will merge on CI completion
| end | ||
|
|
||
| attributes['peer.service'] = config[:peer_service] if config[:peer_service] | ||
| attributes.compact! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically want to avoid using compact! whenever possilbe since it is a bit slower than conditional assigments.
You can see a benchmark here someone shared:
1b906ed to
2e07695
Compare
Description
Dalli supports connecting to Memcached over a UNIX domain socket in which case the
portis nil. This will raiseOpenTelemetry error: invalid span attribute value type NilClass for key 'net.peer.port' on span 'set' (OpenTelemetry::Error)(source).This PR attempts to address this by compacting the
attributes. I'm curious if folks think the test is digging too deep into Dalli internals. I just mainly wanted to avoid spinning up a separate Memcached server that is listening over a UNIX domain socket to test this. I'm all ears for other approaches too.