io.sentry.SentryClientFactory - 创建有效 DSN 时出错:'https://public:private@host:port/1'

io.sentry.SentryClientFactory - Error creating valid DSN from: 'https://public:private@host:port/1'

我是 Sentry 新手,已关注 this

and this

并按照相同的步骤和代码我有一个 sbt 项目,我在其中创建了 sentry.properties 文件,其内容是

dsn=https://public:private@host:port/1

并在代码运行时将它放在 src/main/resources 下(与上面 link 相同的代码)抛出异常'

18:19:26.745 [run-main-1] DEBUG io.sentry.config.Lookup - Found dsn=https://public:private@host:port/1 in sentry.properties.
18:19:26.754 [run-main-1] ERROR io.sentry.SentryClientFactory - Error creating valid DSN from: 'https://public:private@host:port/1'.
io.sentry.dsn.InvalidDsnException: Invalid DSN, the following properties aren't set '[host, public key]'
    at io.sentry.dsn.Dsn.validate(Dsn.java:209) ~[sentry-1.7.16.jar:na]
    at io.sentry.dsn.Dsn.<init>(Dsn.java:66) ~[sentry-1.7.16.jar:na]
    at io.sentry.dsn.Dsn.<init>(Dsn.java:41) ~[sentry-1.7.16.jar:na]
    at io.sentry.SentryClientFactory.resolveDsn(SentryClientFactory.java:73) [sentry-1.7.16.jar:na]
    at io.sentry.SentryClientFactory.sentryClient(SentryClientFactory.java:42) [sentry-1.7.16.jar:na]
    at io.sentry.Sentry.init(Sentry.java:81) [sentry-1.7.16.jar:na]
    at io.sentry.Sentry.init(Sentry.java:44) [sentry-1.7.16.jar:na]
    at sentry.SentryDemo$.main(SentryDemo.scala:16) [classes/:na]
    at sentry.SentryDemo.main(SentryDemo.scala) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at sbt.Run.invokeMain(Run.scala:67) [run-0.13.16.jar:0.13.16]
    at sbt.Run.run0(Run.scala:61) [run-0.13.16.jar:0.13.16]
    at sbt.Run.sbt$Run$$execute(Run.scala:51) [run-0.13.16.jar:0.13.16]
    at sbt.Run$$anonfun$run.apply$mcV$sp(Run.scala:55) [run-0.13.16.jar:0.13.16]
    at sbt.Run$$anonfun$run.apply(Run.scala:55) [run-0.13.16.jar:0.13.16]
    at sbt.Run$$anonfun$run.apply(Run.scala:55) [run-0.13.16.jar:0.13.16]
    at sbt.Logger$$anon.apply(Logger.scala:84) [logging-0.13.16.jar:0.13.16]
    at sbt.TrapExit$App.run(TrapExit.scala:248) [run-0.13.16.jar:0.13.16]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
[error] (run-main-1) io.sentry.dsn.InvalidDsnException: Invalid DSN, the following properties aren't set '[host, public key]'
io.sentry.dsn.InvalidDsnException: Invalid DSN, the following properties aren't set '[host, public key]'
    at io.sentry.dsn.Dsn.validate(Dsn.java:209)
    at io.sentry.dsn.Dsn.<init>(Dsn.java:66)
    at io.sentry.dsn.Dsn.<init>(Dsn.java:41)
    at io.sentry.SentryClientFactory.resolveDsn(SentryClientFactory.java:73)
    at io.sentry.SentryClientFactory.sentryClient(SentryClientFactory.java:42)
    at io.sentry.Sentry.init(Sentry.java:81)
    at io.sentry.Sentry.init(Sentry.java:44)
    at sentry.SentryDemo$.main(SentryDemo.scala:16)
    at sentry.SentryDemo.main(SentryDemo.scala)
    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)

我需要添加什么来代替属性文件中的 dsn 吗?我在我的项目中使用哨兵,它不是基于网络的项目

DSN 告诉 Sentry SDK 要命中哪个哨兵实例(例如 sentry.io)以及事件属于哨兵中的哪个项目。

您需要从 Sentry 获取 DSN 并添加到您的项目中。 在 Sentry 中,在项目设置页面中,您将看到:Client keys (DSN):

然后您将看到这样的 DSN:

复制这个(右边的按钮),然后粘贴到您的 sentry.properties 替换占位符:https://public:private@host:port/1