Remove default parameters from Recordable interface#208
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #208 +/- ##
==========================================
+ Coverage 92.30% 92.31% +0.01%
==========================================
Files 101 102 +1
Lines 3169 3174 +5
==========================================
+ Hits 2925 2930 +5
Misses 244 244
|
pyohannes
reviewed
Jul 23, 2020
pyohannes
reviewed
Jul 23, 2020
Contributor
Author
|
@pyohannes @IlyaKobelevskiy please let me know if you have any further thoughts! |
ziqizh
pushed a commit
to ziqizh/opentelemetry-cpp
that referenced
this pull request
Jul 31, 2020
ziqizh
pushed a commit
to ziqizh/opentelemetry-cpp
that referenced
this pull request
Jul 31, 2020
GerHobbelt
pushed a commit
to GerHobbelt/opentelemetry-cpp
that referenced
this pull request
Jun 17, 2025
…onorepo Update dependency protobuf to v30.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This previous PR added support for links and event attributes in the base
Recordable. Some parameters of the virtual functions were assigned defaults (for example the default timestamp isnowand default attributes are an empty map). This was done to conform to the OpenTelemetry spec (see Add Events and Add Links).After further research, I found that many people strongly recommend against using default parameters in virtual functions, since default parameters depend on the static type of the object, whereas the virtual function dispatched depends on the dynamic type (see a discussion here). In fact, the Google C++ Style Guide goes as far as to ban default parameters on virtual functions.
This PR replaces the default parameters in the
Recordablevirtual functions with function overriding. I believe this will lead to more consistent and predictable behaviour. It will also remove the need for each derived class of the baseRecordableto re-define the default parameters.I've also added a static empty map to the base
Recordable, to avoid creating a new empty map every time the default attributes are used.