0

After migration to spring boot 3 and micrometer tracing library. The tracing IDs aren't automatically appended to the logs for Classes which implement the CommandLineRunner interface unlike for rest controllers.

Example code

public class JobRunner implements CommandLineRunner {

    private final petsJobExecutor petsJobExecutor;

    @TrackExecutionTime
    public void run(String... args) {
        log.info("Started the job");
        petsJobExecutor.updatePets();
        log.info("Finished the job");
    }
}

How can I enable automatically trace-id context propagation for CommandLineRunner implementations in sprint boot 3 with micrometer?

  • Before anyone wastes time trying to answer this, please note that it has also been raised [on GitHub](https://github.com/spring-projects/spring-boot/issues/34449) and [Gitter](https://matrix.to/#/!poRJqCihtKxXkqtIDZ:gitter.im/$aEg6ka9xSGdHKKjCAd9s8cQIVR27vNOpeae2zQ4HI2U?via=gitter.im&via=matrix.org&via=hive-mind.network). – Andy Wilkinson Mar 02 '23 at 19:58
  • Solved by using Observation.createNotStarted("pets-job", observationRegistry).observe(() -> { log.info("Started the job"); petsJobExecutor.updatePets(); log.info("Finished the job"); }); – MariaLO Mar 03 '23 at 13:51

0 Answers0