Skip to content
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

Breaking: Replace Callbacks interface by Callbacks struct (server) #326

Merged

Conversation

tigrannajaryan
Copy link
Member

This continues work start in #324 for Client.

The interface has the following downsides:

  • Impossible to define non-trivial default behavior. Here is an example where it was needed: Add CheckRedirect callback #269 (comment)
  • Adding new callbacks requires expanding the interface, which is a breaking change for existing client users.

Getting rid of the interface and keeping just a struct for callbacks solves both problems:

  • Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func.
  • Adding new callback funcs is not a braking change, existing users won't be affected.

This continues work start in open-telemetry#324 for Client.

The interface has the following downsides:
- Impossible to define non-trivial default behavior. Here is an example where it was needed: open-telemetry#269 (comment)
- Adding new callbacks requires expanding the interface, which is a breaking change for existing client users.

Getting rid of the interface and keeping just a struct
for callbacks solves both problems:
- Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func.
- Adding new callback funcs is not a braking change, existing users won't be affected.
@tigrannajaryan tigrannajaryan requested a review from a team as a code owner December 19, 2024 15:34
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 86.27451% with 7 lines in your changes missing coverage. Please review.

Project coverage is 77.81%. Comparing base (b7beae5) to head (bf2dfbb).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
server/serverimpl.go 82.14% 3 Missing and 2 partials ⚠️
server/types/callbacks.go 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #326      +/-   ##
==========================================
+ Coverage   77.29%   77.81%   +0.52%     
==========================================
  Files          25       25              
  Lines        2281     2321      +40     
==========================================
+ Hits         1763     1806      +43     
+ Misses        410      408       -2     
+ Partials      108      107       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@echlebek echlebek left a comment

Choose a reason for hiding this comment

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

Looks good to me. The change is removing a level of nesting from a lot of places in the codebase too. 👍

I do see a minor possible improvement, defaults could be defined as free standing functions and set by name in SetDefaults, which would avoid the possibility of closing over function vars by accident. But, that's really a tiny nit.

Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

minor doc comments 👍

server/types/callbacks.go Outdated Show resolved Hide resolved
server/types/callbacks.go Show resolved Hide resolved
@tigrannajaryan
Copy link
Member Author

I do see a minor possible improvement, defaults could be defined as free standing functions and set by name in SetDefaults, which would avoid the possibility of closing over function vars by accident. But, that's really a tiny nit.

Agreed. Done.

@tigrannajaryan tigrannajaryan merged commit 27e53f4 into open-telemetry:main Jan 7, 2025
11 checks passed
@tigrannajaryan tigrannajaryan deleted the tigran/servercallbacks branch January 7, 2025 14:41
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.

3 participants