-
Notifications
You must be signed in to change notification settings - Fork 791
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
Expunge all unsafe logging [resolve conflicts] #7122
Changes from 10 commits
a67269d
8ee8295
ee51278
fddec28
8a19f6d
ba8c107
e444c83
e98e061
2c3dd92
2693a1d
7adeaad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,31 +18,31 @@ package org.http4s.circe.middleware | |
|
||
import cats.data._ | ||
import cats.effect._ | ||
import cats.syntax.all._ | ||
import io.circe._ | ||
import io.circe.syntax._ | ||
import org.http4s._ | ||
import org.http4s.circe._ | ||
import org.http4s.headers.Connection | ||
import org.typelevel.ci._ | ||
import org.typelevel.log4cats.LoggerFactory | ||
|
||
object JsonDebugErrorHandler { | ||
private[this] val messageFailureLogger = | ||
Platform.loggerFactory.getLoggerFromName( | ||
private[this] def messageFailureLogger[F[_]: LoggerFactory] = | ||
LoggerFactory[F].getLoggerFromName( | ||
"org.http4s.circe.middleware.jsondebugerrorhandler.message-failures" | ||
) | ||
private[this] val serviceErrorLogger = | ||
Platform.loggerFactory.getLoggerFromName( | ||
private[this] def serviceErrorLogger[F[_]: LoggerFactory] = | ||
LoggerFactory[F].getLoggerFromName( | ||
"org.http4s.circe.middleware.jsondebugerrorhandler.service-errors" | ||
) | ||
|
||
// Can be parametric on my other PR is merged. | ||
def apply[F[_]: Concurrent, G[_]]( | ||
def apply[F[_]: Concurrent: LoggerFactory, G[_]]( | ||
service: Kleisli[F, Request[G], Response[G]], | ||
redactWhen: CIString => Boolean = Headers.SensitiveHeaders.contains, | ||
): Kleisli[F, Request[G], Response[G]] = | ||
Kleisli { req => | ||
import cats.syntax.applicative._ | ||
import cats.syntax.applicativeError._ | ||
implicit def entEnc[M[_]]: EntityEncoder.Pure[JsonErrorHandlerResponse[M]] = | ||
JsonErrorHandlerResponse.entEnc[M](redactWhen) | ||
|
||
|
@@ -55,27 +55,28 @@ object JsonDebugErrorHandler { | |
s"""Message failure handling request: ${req.method} ${req.pathInfo} from ${req.remoteAddr | ||
.getOrElse("<unknown>")}""" | ||
) | ||
.unsafeRunSync() | ||
val firstResp = mf.toHttpResponse[G](req.httpVersion) | ||
Response[G]( | ||
status = firstResp.status, | ||
httpVersion = firstResp.httpVersion, | ||
headers = firstResp.headers.redactSensitive(redactWhen), | ||
).withEntity(JsonErrorHandlerResponse[G](req, mf)).pure[F] | ||
.as { | ||
val firstResp = mf.toHttpResponse[G](req.httpVersion) | ||
Response[G]( | ||
status = firstResp.status, | ||
httpVersion = firstResp.httpVersion, | ||
headers = firstResp.headers.redactSensitive(redactWhen), | ||
).withEntity(JsonErrorHandlerResponse[G](req, mf)) | ||
} | ||
case t => | ||
serviceErrorLogger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, 'serviceErrorLogger' is defined as a ): Kleisli[F, Request[G], Response[G]] = {
val serviceErrorLogger = LoggerFactory[F].getLoggerFromName(...)
Kleisli { req =>
...
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good point. We can probably do the same with Btw is there a meaningful difference between the effectful and non-effectful APIs for obtaining a logger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
.error(t)( | ||
s"""Error servicing request: ${req.method} ${req.pathInfo} from ${req.remoteAddr | ||
.getOrElse("<unknown>")}""" | ||
) | ||
.unsafeRunSync() | ||
Response[G]( | ||
Status.InternalServerError, | ||
req.httpVersion, | ||
Headers(Connection.close), | ||
) | ||
.withEntity(JsonErrorHandlerResponse[G](req, t)) | ||
.pure[F] | ||
.as( | ||
Response[G]( | ||
Status.InternalServerError, | ||
req.httpVersion, | ||
Headers(Connection.close), | ||
) | ||
.withEntity(JsonErrorHandlerResponse[G](req, t)) | ||
) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the PR, but it caught my eye.
The
entEnc
is always used withG
type parameter. Technically, we can preallocate it too:On the other hand, since it's defined as
def
, no error = no allocation. The same is true for loggers.