I have workflows implemented with multiple activities and child workflows. The child workflows trigger their own activities. But we have a scenario where we are running multiple workflows simultaneously and the logs are written to the same file. We need to ensure that the logs are written with proper context, like we need the logs to be written with a description simiar to “parentWorkflow ID->childWorkflow ID->activity ID” with every log statement to isolate the logs that are being written by a single workflow. Basically i am looking for something similar to nested diagnostic Context logging (https://www.baeldung.com/java-logging-ndc-log4j)
I checked the documentation ( Observability - Java SDK feature guide | Temporal Documentation ) but it does not address the nested diagnostic part of the problem.
can someone pls point out to relevant documentation page if it exits?
Temporal Java SDK does populate MDC:
Hi @maxim , will the above MDC will be auto applied ?
how about if some one is using there custom MDC , will custom MDC overwrute the one that temporal is already providing .
for example
@Bean
public WorkflowClient workflowClient(
final WorkflowServiceStubs workflowServiceStubs,
final OpenTelemetry openTelemetry) {
Tracer otTracer = OpenTracingShim.createTracerShim(openTelemetry);
OpenTracingOptions openTracingOptions = OpenTracingOptions.newBuilder().setTracer(otTracer).build();
return WorkflowClient.newInstance(workflowServiceStubs,
WorkflowClientOptions.newBuilder()
.setNamespace(temporalServiceConfig.getTemporalNamespace())
.setInterceptors(new OpenTracingClientInterceptor(openTracingOptions))
.setContextPropagators(List.of(new MDCContextPropagator()))
.build());
}
@Bean
public WorkerFactory workerFactory(
final WorkflowClient workflowClient) {
return WorkerFactory.newInstance(workflowClient);
}
but the aim of custom MDC is to poulate the mdc for http calls , not the internal temporal worker to sever logs
I haven’t spent looking into MDC code, but I believe that the SDK will insert the tags in addition to your tags.