Skip to content

Commit a267a8c

Browse files
authored
http (feature): Support adding extra logParamters to individual HTTP requests (#3861)
1 parent 10a4a26 commit a267a8c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

airframe-http/.jvm/src/test/scala/wvlet/airframe/http/client/HttpClientLoggingFilterTest.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ class HttpClientLoggingFilterTest extends AirSpec {
6666
test("switch dest") {
6767
client.send(Http.GET("/").withDest(ServerAddress("localhost:8081")))
6868
}
69+
70+
test("with logParameters") {
71+
client.send(
72+
Http.GET("/"),
73+
context = HttpClientContext(
74+
logParameters = Map("k1" -> "v1")
75+
)
76+
)
77+
}
6978
}
7079

7180
}

airframe-http/src/main/scala/wvlet/airframe/http/client/HttpClientContext.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import wvlet.airframe.http.RPCMethod
2020
* @param rpcMethod
2121
*/
2222
case class HttpClientContext(
23-
clientName: String,
23+
clientName: String = "default",
2424
rpcMethod: Option[RPCMethod] = None,
25-
rpcInput: Option[Any] = None
25+
rpcInput: Option[Any] = None,
26+
// Extra parameters used for logging
27+
logParameters: Map[String, Any] = Map.empty
2628
)
2729

2830
object HttpClientContext {

airframe-http/src/main/scala/wvlet/airframe/http/internal/HttpLogs.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ object HttpLogs extends LogSupport {
5050
m ++= requestHeaderLogs(request, httpLogger.excludeHeaders)
5151

5252
// Log RPC context in the client side
53-
clientContext.foreach {
54-
_.rpcMethod.map { rpc => m ++= rpcMethodLogs(rpc) }
53+
clientContext.foreach { ctx =>
54+
ctx.rpcMethod.map { rpc => m ++= rpcMethodLogs(rpc) }
55+
m ++= ctx.logParameters
5556
}
5657
// Log RPC context in the server side
5758
rpcContext.flatMap(_.rpcCallContext).foreach { rcc =>

0 commit comments

Comments
 (0)