Open martinvisser opened 2 months ago
Are you explicitly creating one in your app (I think that's what you're saying) or is it something coming implicitly from Webflux?
If it's your own, do you create a bean of type ContextRegistgry
as well? The DGS provided one is @ConditionalOnMissingBean
so you can override it by providing one yourself. Does that work?
I'm trying to fully understand the scenario to figure out if we should have other conditionals (or config) for this.
We don't create or try to load our own, and I'm not entirely sure where it came from. The ObervationRegistry
is autowired. The DGS bean is loaded, so that means there isn't any other, based on the conditional on the DGS one.
I haven't tried creating our own context registry bean, but can try, although we never needed one.
This works too indeed:
@Bean
fun contextRegistry(): ContextRegistry = ContextRegistry()
But obviously this just hides the DGS bean
The one that already loads the ObservationThreadLocalAccessor
comes from io.micrometer:micrometer-observation
from META-INF/services/io.micrometer.context.ThreadLocalAccessor
:
io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor
And is loaded via a ServiceLoader
in ContextRegistry
from:
private static final ContextRegistry instance = new ContextRegistry().loadContextAccessors()
.loadThreadLocalAccessors();
// ...
public ContextRegistry loadThreadLocalAccessors() {
ServiceLoader.load(ThreadLocalAccessor.class).forEach(this::registerThreadLocalAccessor);
return this;
}
Probably relevant, it's ContextPropagationSupport
that loads the class, which is triggered because we have Hooks.enableAutomaticContextPropagation()
in our Spring Boot app:
fun main(vararg args: String) {
Hooks.enableAutomaticContextPropagation()
runApplication<MySecondApplication>(*args)
}
ContextPropagationSupport
comes from io.projectreactor:reactor-core
Expected behavior
When using MDC values, even if it is just the
traceId
and/orspanId
- the defaults from Spring Boot -, they should be logged ifObservationRegistry
is used. At least, I think it is related to usingObservationRegistry
.Actual behavior
No MDC values are logged.
Steps to reproduce
I'm using Spring Boot
3.2.5
, withgraphql-dgs-webflux-starter
. I upgradedgraphql-dgs-platform-dependencies
to version8.5.5
or8.5.6
, coming from8.5.3
, when I noticed all MDC values were gone. I search for changes made and found a related change that added this bean:This adds a second
ThreadLocalAccessor
to my application, which fully overwrites the first entry, theObservationThreadLocalAccessor
. Before8.5.5
there was noContextRegistry
, and as this bean is triggered, there still isn't one. However, theContextRegsitry
did load theObservationThreadLocalAccessor
already.I found a workaround by removing
Slf4jThreadLocalAccessor
later on, which brought back all MDC values:I don't know if it's an option to register
Slf4jThreadLocalAccessor
with a condition perhaps, or maybe have an option to disable it in a different way, but anything would be appreciated so that I do not need to use the workaround.