1

I have an angular application using a tracing library to trace each operation (user bouton click).

This application after SPA is loaded sends a list of traces in the request body to the backend microservice to log them. In the backend microservice, I am using the spring boot 2.3.7, the spring cloud Hoxton.SR9 and logback 1.2.3.

This is the method:

@PostMapping("/traces")
public ResponseEntity<List<Trace>> addTrace(@RequestBody List<Trace> traces) {
   traces.forEach(trace -> {
         RtLog log = RtLog.builder.parentSpanId(trace.getParentId()).traceId(trace.getTraceId()).spanId(trace.getSpanId)).operationName(trace.getOperationName())
            .businessJourney(trace.getBaggages().getBusinessJourney())
            .componentId(trace.getBaggages().getComponentId()).componentType(trace.getBaggages().getComponentType())
            .sessionId(trace.getBaggages().getSessionId()).userId(trace.getBaggages().getUserId())
            .duration(trace.getDuration())
            .time(!Null.isNullOrEmpty(datetime) ? datetime.format(DateTimeFormatter.ofPattern(TIMESTAMP_PATTERN))
                    : EMPTY)
            .tags(trace.getTags()).build();
 logger.info("spa_log", StructuredArguments.fields(log));

An example of traces send by the application: enter image description here

The problem is when logging the information, the spring sleuth adds on the log another traceId and spanId that I don't need, and it causes conflict with the correct Ids.

So how can I override the traceId and spanId or is it possible to disable the tracing in this method?

There is the traceContext or brave Tracing but I found that I can builder a new trace but I didn't find a way to change the current trace.

nayomi
  • 137
  • 1
  • 5
  • 20
  • please show your log configuration file. like as logback.xml or logback-spring.xml – BlackC Sep 23 '22 at 09:30
  • did you find the solution to reuse same traceId between client and the spring boot to join the requests – bhantol Nov 07 '22 at 18:58
  • Yes, the solution is using MDC to force tha values of traceId and spanId : MDC.put("traceId", trace.getTraceId()); MDC.put("spanId", trace.getSpanId()); – nayomi Nov 07 '22 at 21:07

0 Answers0