Skip to content

Conversation

@nickamorim
Copy link
Contributor

Description

Dalli supports connecting to Memcached over a UNIX domain socket in which case the port is nil. This will raise OpenTelemetry 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.

'net.peer.name' => hostname,
'net.peer.port' => port
}
}.compact
Copy link
Contributor

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 }.

Suggested change
}.compact
}
attributes.compact!

@nickamorim nickamorim force-pushed the nickamorim/dalli-nil-attributes branch 2 times, most recently from 84f7aa8 to 1b906ed Compare May 23, 2025 20:24
Copy link
Contributor

@robertlaurin robertlaurin left a 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!
Copy link
Contributor

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:

#693 (comment)

@nickamorim nickamorim force-pushed the nickamorim/dalli-nil-attributes branch from 1b906ed to 2e07695 Compare May 24, 2025 23:27
@nickamorim nickamorim requested a review from arielvalentin May 26, 2025 13:11
@arielvalentin arielvalentin merged commit 4dbb668 into open-telemetry:main May 26, 2025
62 checks passed
@nickamorim nickamorim deleted the nickamorim/dalli-nil-attributes branch May 29, 2025 18:10
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.

4 participants