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

Unprotect ZClient methods #2031

Merged
merged 1 commit into from
Mar 9, 2023
Merged

Unprotect ZClient methods #2031

merged 1 commit into from
Mar 9, 2023

Conversation

zeal18
Copy link
Contributor

@zeal18 zeal18 commented Mar 8, 2023

The use case: measure request duration and push it to a metrics service

Possible solution: define a middleware using ZClientAspect and wrap a client like

def apply[Env, In,  Err, Out](client: ZClient[Env, In, Err, Out]): ZClient[Env, In, Err, Out] = 
  new ZClient[Env, In, Err, Out] {
    def request(...) =
       client.request(...).timed.flatMap { case (duration, response) =>  metrics.report(duration).as(response) }
  }

The issue: because of the ZClient defines two protected methods, it's impossible to call them on the wrapped client which forces to make a hack. Using mapZIO and contramapZIO methods complicates the simple task a lot.

The suggested solution is to unprotect the methods, wdyt?

UPD: another use case is to catch request failures and report them somewhere, it's impossible to achieve that with the mapZIO method because it's not called in case of an error

@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2023

Codecov Report

Patch coverage: 16.66% and no project coverage change

Comparison is base (87c6601) 62.50% compared to head (95907b5) 62.50%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2031   +/-   ##
=======================================
  Coverage   62.50%   62.50%           
=======================================
  Files         206      206           
  Lines        6027     6027           
  Branches      231      231           
=======================================
  Hits         3767     3767           
  Misses       2260     2260           
Impacted Files Coverage Δ
zio-http/src/main/scala/zio/http/ZClient.scala 26.08% <16.66%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jdegoes jdegoes merged commit e26e901 into zio:main Mar 9, 2023
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.

None yet

3 participants