Skip to content

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

Merged
tigrannajaryan merged 2 commits into
open-telemetry:mainfrom
tigrannajaryan:tigran/servercallbacks
Jan 7, 2025
Merged

Breaking: Replace Callbacks interface by Callbacks struct (server)#326
tigrannajaryan merged 2 commits into
open-telemetry:mainfrom
tigrannajaryan:tigran/servercallbacks

Conversation

@tigrannajaryan

Copy link
Copy Markdown
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
@codecov

codecov Bot commented Dec 19, 2024

Copy link
Copy Markdown

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.

@echlebek echlebek left a comment

Copy link
Copy Markdown
Contributor

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.

@srikanthccv srikanthccv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor doc comments 👍

Comment thread server/types/callbacks.go Outdated
Comment thread server/types/callbacks.go
@tigrannajaryan

Copy link
Copy Markdown
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
@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