有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Sentry接收我的日志消息但不接收我的异常

在Dropwizard项目中使用Sentry时,我遇到了一个奇怪的问题

我在两个具有类似框架的应用程序中配置了它

在其中一个例子中,我得到了所有日志消息的正确跟踪,但没有异常,因为我不知道为什么

我注意到与应用程序不同的是:

java.lang.Exception: some error
        at testEndpoint(EventResource.kt:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)

vs有效的应用程序:

io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 22059c429b65153e
! java.lang.Exception: Test Hello Exception
! at myMethod(TestResource.kt:40)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

我注意到其中有一个LoggingExceptionMapper,它由Dropwizard自动激活,但另一个似乎不存在

我正在使用sentry 1.7.23和Dropwizard 1.3.9

关于我的依赖:

implementation("io.sentry:sentry:$sentryVersion")
implementation("io.sentry:sentry-logback:$sentryVersion")
implementation("org.dhatim:dropwizard-sentry:1.3.1-1")

我有最后一个依赖项作为帮助,不必创建我的工厂,也不必在我的配置中指定日志附加器的值。yml

https://github.com/dhatim/dropwizard-sentry

这两个项目的init都是这样的:

Sentry.init("some-value...")

我的配置。yml

logging:
  level: INFO
  appenders:
    - type: console
    - type: sentry
      threshold: ${SENTRY_THRESHOLD}
      dsn: ${SENTRY_DSN}
      environment: ${SENTRY_ENVIRONMENT}
      release: 1.0.0

你知道会出什么问题吗

由于Dropwizard的核心库中包含logback,因此不需要依赖它


共 (2) 个答案

  1. # 1 楼答案

    如果存在依赖性冲突,那么您可以使用2-way进行检查

    1)只需在cmd或IDE控制台上使用以下命令。这将显示依赖关系树,您可以从树中搜索哪个库存在冲突

          mvn dependency:tree -Dverbose -Dincludes=commons-collections
    

    参考链接:https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

    2)这是发现依赖冲突的最有效方法。在你的pom中添加以下插件。xml

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.4.1</version>
            <configuration>
                <rules>
                    <dependencyConvergence />
                </rules>
            </configuration>
        </plugin>
    

    然后使用enforcer:enforce目标构建项目,它将向您显示与冲突版本的确切依赖关系。如果发现任何冲突库,请将其排除在外

    使用上述方法后,如果您遇到同样的问题,请尝试用1.3升级版本,或在添加组织后尝试。玻璃鱼。运动衫媒体依赖

    希望任何一种方法都能对你有用

  2. # 2 楼答案

    LoggingExceptionMapper的实现在dropwizard项目中

    尝试将依赖项添加到:dropwizard