https://kotlinlang.org logo
#http4k
Title
# http4k
r

Razvan

01/15/2021, 10:42 AM
And the second problem I have (I guess much harder) is with EventFilter.AddZipkinTraces on a client I expected it to have the client traces not the server ones. I guess is beacause it is lazy evaluated so the currentThread does no longer have the client data. here's a test that shows it
Copy code
@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:
Copy code
{"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
Copy code
{
  "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
Copy code
{
  "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"
    }
  }
}
s

s4nchez

01/15/2021, 4:01 PM
Have you tried using the
startReportFn
and
endReportFn
in
ClientFilters.RequestTracing
instead?
r

Razvan

01/15/2021, 5:38 PM
You mean for call the event log from there? even if I write the client this way
Copy code
val 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.
Copy code
{"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.
5 Views