Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setry does not capture event if inited programatically with Spring boot starter #1339

Closed
JanCizmar opened this issue Mar 19, 2021 · 7 comments

Comments

@JanCizmar
Copy link

Hi there,

I am building and app, where I need to configure both backend and frontend DSNs in my properties.yaml such as

tolgee:
  sentry:
    enabled: true
    server-dsn: ...
    client-dsn: ...

That's why i don't want to use other configuration options such as "sentry.dsn" option.

I would like to init sentry in code as documentation says: https://docs.sentry.io/platforms/java/guides/spring-boot/configuration/

import io.sentry.Sentry;

Sentry.init(options -> {
  options.setDsn("https://[email protected]/0");
});

But when I do so, It doesn't capture anything. So maybe the documentation is wrong or I am doing something wrong.
I am calling the init method in my main Application class constructor.

If i provide "sentry.dsn", it works properly, so as a workaround I do this in my application.yaml

sentry:
  dsn: ${tolgee.sentry.server-dsn}

Should I call the Sentry.init method elsewhere? Or is there another reason why it doesn't work?

@maciejwalkowiak
Copy link
Contributor

Hi! Do you want to use trigger some events with one DSN and other events with other DSN or is the second DSN just to serve it to the frontend application?

If you want to benefit from Spring integration, your workaround is a correct solution and I would not even consider it a workaround.

@JanCizmar
Copy link
Author

Hi, the second is just passed to frontend, backend doesn't use it. I don't like there is the unnecessary property, but maybe I am just a nitpicker. So is the documentation wrong and I can't use the init method in my code as described?

@JanCizmar
Copy link
Author

Another issue is, that when i don't provide the dsn in my tolgee.sentry.server-dsn attrubute it fails on

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'tolgee.sentry.server-dsn' in value "${tolgee.sentry.server-dsn}"

@JanCizmar
Copy link
Author

This

sentry:
  dsn: ${tolgee.sentry.server-dsn:#{null}}

also fails:

Caused by: io.sentry.exception.InvalidDsnException: java.lang.IllegalArgumentException: Invalid DSN: No public key provided.

So i really don't know, how to fix this.

@maciejwalkowiak
Copy link
Contributor

You cannot default to null this way (read more: spring-projects/spring-framework#19986).

Sentry accepts empty string as a DSN - this will disable Sentry integration:

sentry.dsn=${tolgee.sentry.server-dsn:}

Spring integration is configured only if property sentry.dsn is present. If you initialize Sentry manually, you can send Sentry events created manually but you the whole servlet infrastructure to capture exceptions to Sentry isn't there.

@JanCizmar
Copy link
Author

You're right! I thought I did it so, but i edited wrong profile yaml. Thanks a lot!

@maciejwalkowiak
Copy link
Contributor

Great! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants