Skip to content

Commit

Permalink
http (feature): Support adding extra logParamters to individual HTTP …
Browse files Browse the repository at this point in the history
…requests
  • Loading branch information
xerial committed Mar 5, 2025
1 parent 10a4a26 commit 4b320e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class HttpClientLoggingFilterTest extends AirSpec {
test("switch dest") {
client.send(Http.GET("/").withDest(ServerAddress("localhost:8081")))
}

test("with logParameters") {
client.send(
Http.GET("/"),
context = HttpClientContext(
logParameters = Map("k1" -> "v1")
)
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import wvlet.airframe.http.RPCMethod
* @param rpcMethod
*/
case class HttpClientContext(
clientName: String,
clientName: String = "default",
rpcMethod: Option[RPCMethod] = None,
rpcInput: Option[Any] = None
rpcInput: Option[Any] = None,
// Extra parameters used for logging
logParameters: Map[String, Any] = Map.empty
)

object HttpClientContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ object HttpLogs extends LogSupport {
m ++= requestHeaderLogs(request, httpLogger.excludeHeaders)

// Log RPC context in the client side
clientContext.foreach {
_.rpcMethod.map { rpc => m ++= rpcMethodLogs(rpc) }
clientContext.foreach { ctx =>
ctx.rpcMethod.map { rpc => m ++= rpcMethodLogs(rpc) }
m ++= ctx.logParameters
}
// Log RPC context in the server side
rpcContext.flatMap(_.rpcCallContext).foreach { rcc =>
Expand Down

0 comments on commit 4b320e4

Please # to comment.