Search code examples
spring-bootintegration-testingtracespring-cloud-sleuth

Test spring sleuth for non-spring-boot application


I have a very simple maven sub-module - "unified-logging" - providing some logback configuration and a LogUtil class. This sub-module is not a spring boot application and is used by other applications (as compile time dependecy in pom).

I have added, additionally, spring cloud sleuth dependency in pom of this sub-module to inject spanId and traceId. Logback configuration provides the pattern for these fields:

<nestedField>
                    <fieldName>trace</fieldName>
                    <providers>
                        <pattern>
                            <pattern>
                                {
                                "traceId": "%X{traceId:-}",
                                "parentSpanId": "%X{parentSpanId:-}",
                                "spanId": "%X{spanId:-}"
                                }
                            </pattern>
                        </pattern>
                    </providers>
                </nestedField>

How can I test whether the traceId and spanId is really generated and injected in the logs as this is not a spring boot application and the whole auto-configuration part of spring will not be loaded? Thanks


Solution

  • You can test it by bringing in Spring Boot as a test dependency and write a simple test app that tests the integration.