by Guest » 05 Jan 2025, 15:11
Ich habe einen Post-Filter, der versucht, die Trace-ID als Header in die Antwort einzufügen. Ich habe die Vorschläge hier befolgt, aber der TraceContext ist immer noch null.
Code: Select all
@Slf4j
@Configuration
public class PostFilters {
public static final String CORRELATION_ID = "X-CORRELATION-ID";
@Bean
public GlobalFilter correlationIdPostFilter() {
return(exchange, chain) -> chain.filter(exchange)
.then(Mono.just(exchange))
.map(serverWebExchange -> {
TraceContext traceContext = WebFluxSleuthOperators.currentTraceContext(serverWebExchange);
log.info("Trace Context: {}", traceContext;
if (traceContext != null) {
serverWebExchange.getResponse().getHeaders().set(CORRELATION_ID, traceContext.traceId());
}
return serverWebExchange;
})
.then();
}
}
Abhängigkeiten
Code: Select all
org.springframework.boot
spring-boot-starter-actuator
io.micrometer
micrometer-tracing-bridge-brave
io.zipkin.reporter2
zipkin-reporter-brave
io.zipkin.reporter2
zipkin-sender-okhttp3
org.springframework.cloud
spring-cloud-sleuth-instrumentation
Haupt
Code: Select all
@SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
Hooks.enableAutomaticContextPropagation();
new SpringApplicationBuilder(ApiGatewayApplication.class)
.web(WebApplicationType.REACTIVE)
.run(args);
}
}
Ich weiß, dass der Kontext weitergegeben wird, da ich die Trace-IDs dienstübergreifend in den Protokollen und in Zipkin sehen kann.
Ich habe einen Post-Filter, der versucht, die Trace-ID als Header in die Antwort einzufügen. Ich habe die Vorschläge hier befolgt, aber der TraceContext ist immer noch null.
[code]@Slf4j
@Configuration
public class PostFilters {
public static final String CORRELATION_ID = "X-CORRELATION-ID";
@Bean
public GlobalFilter correlationIdPostFilter() {
return(exchange, chain) -> chain.filter(exchange)
.then(Mono.just(exchange))
.map(serverWebExchange -> {
TraceContext traceContext = WebFluxSleuthOperators.currentTraceContext(serverWebExchange);
log.info("Trace Context: {}", traceContext;
if (traceContext != null) {
serverWebExchange.getResponse().getHeaders().set(CORRELATION_ID, traceContext.traceId());
}
return serverWebExchange;
})
.then();
}
}
[/code]
Abhängigkeiten
[code]
org.springframework.boot
spring-boot-starter-actuator
io.micrometer
micrometer-tracing-bridge-brave
io.zipkin.reporter2
zipkin-reporter-brave
io.zipkin.reporter2
zipkin-sender-okhttp3
org.springframework.cloud
spring-cloud-sleuth-instrumentation
[/code]
Haupt
[code]@SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
Hooks.enableAutomaticContextPropagation();
new SpringApplicationBuilder(ApiGatewayApplication.class)
.web(WebApplicationType.REACTIVE)
.run(args);
}
}
[/code]
Ich weiß, dass der Kontext weitergegeben wird, da ich die Trace-IDs dienstübergreifend in den Protokollen und in Zipkin sehen kann.