测试非Spring-boot应用程序的Spring侦探

发布于 2025-02-12 07:58:44 字数 915 浏览 1 评论 0原文

我有一个非常简单的Maven子模块 - “ Unified -Logging” - 提供了一些记录配置和一个Logutil类。该子模块不是弹簧启动应用程序,而是其他应用程序(作为POM中的编译时间依赖性)。

我还添加了该子模块的POM中的弹簧云侦探依赖性,以注入Spanid和Traceid。记录式配置为这些字段提供了模式:

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

如何测试TraceID和Spanid是否真正生成并注入日志中,因为这不是Spring Boot应用程序,并且整个自动配置部分不会加载Spring的整个自动配置部分? 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硪扪都還晓 2025-02-19 07:58:45

您可以通过将Spring Boot作为测试依赖项进行测试,并编写一个简单的测试应用程序来测试集成。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文