Skip to content

Commit 5f2fabb

Browse files
committed
foldSpan
1 parent 247129e commit 5f2fabb

File tree

1 file changed

+7
-1
lines changed
  • http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api

1 file changed

+7
-1
lines changed

http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/http/api/AppRoutes.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,15 @@ class AppRoutes(kubernetesService: AppService[IO], userInfoDirectives: UserInfoD
185185
for {
186186
ctx <- ev.ask[AppContext]
187187
apiCall = kubernetesService.updateApp(userInfo, CloudContext.Gcp(googleProject), appName, req)
188-
_ <- ctx.span.fold(apiCall)(span => spanResource[IO](span, "updateApp").use(_ => apiCall))
188+
_ <- foldSpan(ctx, apiCall, "updateApp")
189189
} yield StatusCodes.Accepted
190190

191+
// TODO: this exact pattern is repeated over 20x, and I have no idea what it does. My intuition is that it's not
192+
// necessary for a developer of a new endpoint to have a deep understanding of this code, so I want to abstract this
193+
// implementation detail away for better ergonomics/approachability. Thoughts?
194+
private def foldSpan(ctx: AppContext, apiCall: IO[Unit], apiName: String): IO[Unit] =
195+
ctx.span.fold(apiCall)(span => spanResource[IO](span, apiName).use(_ => apiCall))
196+
191197
private[api] def deleteAppHandler(userInfo: UserInfo,
192198
googleProject: GoogleProject,
193199
appName: AppName,

0 commit comments

Comments
 (0)