Razvan
01/15/2021, 10:42 AMRazvan
01/15/2021, 10:44 AM@Test
fun `client zipkin traces`() {
data class ZipkinTraceInfos(val type: String, val insideTraces: ZipkinTraces): Event
val events = EventFilters.AddZipkinTraces()
.then(AutoMarshallingEvents(Jackson))
val srvWithEvents = ServerFilters.RequestTracing()
.then(ResponseFilters.ReportHttpTransaction {
//println("REQUEST:" + it.request)
events(ZipkinTraceInfos("SERVER", ZipkinTraces(it.request)))
}).then {
val cliWithEvents = ClientFilters.RequestTracing()
.then(
ResponseFilters.ReportHttpTransaction {
// println("REQUEST:" + it.request)
events(ZipkinTraceInfos("CLIENT", ZipkinTraces(it.request)))
})
.then { Response(OK) }
cliWithEvents(Request(Method.GET, "/clientUrl"))
}
// set it in order to have a parentId and force the client create a new spanId
srvWithEvents(
Request(Method.GET, "/srvUrl")
.header("x-b3-traceid", "trace_id")
.header("x-b3-spanid", "span_id")
.header("x-b3-parentspanid", "parent_id")
.header("x-b3-sampled", "1")
)
}
prints:
{"event":{"type":"CLIENT","insideTraces":{"traceId":"trace_id","spanId":"ca2bb755e99c8326","parentSpanId":"span_id","samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
{"event":{"type":"SERVER","insideTraces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
For the client request, the data in the traces
that is added by the AddZipkinTraces, I expected it to be the same one as the insideTraces
form the event
object.
To be clear I expect the line
{
"event": {
"type": "CLIENT",
"insideTraces": {
"traceId": "trace_id",
"spanId": "ca2bb755e99c8326",
"parentSpanId": "span_id",
"samplingDecision": "1"
}
},
"metadata": {
"traces": {
"traceId": "trace_id",
"spanId": "span_id",
"parentSpanId": "parent_id",
"samplingDecision": "1"
}
}
}
to be
{
"event": {
"type": "CLIENT",
"insideTraces": {
"traceId": "trace_id",
"spanId": "ca2bb755e99c8326",
"parentSpanId": "span_id",
"samplingDecision": "1"
}
},
"metadata": {
"traces": {
"traceId": "trace_id",
"spanId": "ca2bb755e99c8326",
"parentSpanId": "span_id",
"samplingDecision": "1"
}
}
}
s4nchez
01/15/2021, 4:01 PMstartReportFn
and endReportFn
in ClientFilters.RequestTracing
instead?Razvan
01/15/2021, 5:38 PMval srvWithEvents = ServerFilters.RequestTracing()
.then(ResponseFilters.ReportHttpTransaction {
//println("REQUEST:" + it.request)
events(ZipkinTraceInfos("SERVER", ZipkinTraces(it.request)))
}).then {
val cliWithEvents = ClientFilters.RequestTracing(
{ req, trace -> events(ZipkinTraceInfos("CLIENT-RequestTracing request", ZipkinTraces(req)))},
{ req, resp, trace -> events(ZipkinTraceInfos("CLIENT-RequestTracing response", ZipkinTraces(req))) }
)
.then(
ResponseFilters.ReportHttpTransaction {
// println("REQUEST:" + it.request)
events(ZipkinTraceInfos("CLIENT", ZipkinTraces(it.request)))
})
.then { Response(OK) }
cliWithEvents(Request(Method.GET, "/clientUrl"))
}
it does not change the traces added by AddZipkinTraces are not the ones of the client.
{"event":{"type":"CLIENT-RequestTracing request","insideTraces":{"traceId":"9d4667552a06a638","spanId":"0c50aa1c74e40a2e","parentSpanId":null,"samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
{"event":{"type":"CLIENT","insideTraces":{"traceId":"trace_id","spanId":"03150ea81e6cb19e","parentSpanId":"span_id","samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
{"event":{"type":"CLIENT-RequestTracing response","insideTraces":{"traceId":"6c71f5b87fcebe45","spanId":"fd2c35177c100d59","parentSpanId":null,"samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
{"event":{"type":"SERVER","insideTraces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}},"metadata":{"traces":{"traceId":"trace_id","spanId":"span_id","parentSpanId":"parent_id","samplingDecision":"1"}}}
I have access as you can see at the right client traces in the custom personal object (insideTraces
field), so the work around is to not use AddZipkinTraces, But then I have to not use it either on server to have the same consistent event object both for client calls and server which makes AddZipkinTraces useless.