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

Add support for "ignoredErrors" functionality in Sentry SDK #286

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

dalbani
Copy link
Contributor

@dalbani dalbani commented Feb 18, 2025

Depends on the Sentry SDK update at #284.

dependabot bot and others added 2 commits February 13, 2025 03:22
Bumps [io.sentry:sentry-jul](https://github.com/getsentry/sentry-java) from 7.8.0 to 8.2.0.
- [Release notes](https://github.com/getsentry/sentry-java/releases)
- [Changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md)
- [Commits](getsentry/sentry-java@7.8.0...8.2.0)

---
updated-dependencies:
- dependency-name: io.sentry:sentry-jul
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@dalbani dalbani requested a review from a team as a code owner February 18, 2025 11:44
@melloware
Copy link
Contributor

@dalbani i just merged #285 can you update your PR to the new Config type?

@melloware melloware force-pushed the dependabot/maven/io.sentry-sentry-jul-8.2.0 branch from 7c42313 to 8219be7 Compare February 20, 2025 15:41
# Conflicts:
#	pom.xml
#	runtime/src/main/java/io/quarkus/logging/sentry/SentryHandlerValueFactory.java
@dalbani dalbani changed the base branch from dependabot/maven/io.sentry-sentry-jul-8.2.0 to main February 20, 2025 16:06
@melloware
Copy link
Contributor

I am going to release 2.0.8 now.

Then I will do a 2.1.0 on the latest Quarkus 3.19 and this fix as well.

@dalbani
Copy link
Contributor Author

dalbani commented Feb 20, 2025

Isn't Quarkus 3.19 still at version CR1?

Edit: it has been released a very short time ago. It's not even mentioned on the front page on https://quarkus.io.
I was planning to use this extension with Keycloak, which is still using Quarkus 3.18.
So I now realise I'll have to wait until the next Keycloak release.

@melloware
Copy link
Contributor

I can bump to 3.18.4 which is the latest 3.18 for this release. It just needs the new CONFIG stuff.

@melloware melloware merged commit 9471f56 into quarkiverse:main Feb 20, 2025
@melloware
Copy link
Contributor

@all-contributors add @dalbani for code

Copy link
Contributor

@melloware

I've put up a pull request to add @dalbani! 🎉

@melloware
Copy link
Contributor

actually it looks like i can leave it 3.15.3!

@melloware
Copy link
Contributor

@dalbani 2.1.0 is in Maven Central if you want to try it.

@dalbani dalbani deleted the ignored-errors branch February 20, 2025 22:42
@dalbani
Copy link
Contributor Author

dalbani commented Feb 20, 2025

For those who might be interested in using the feature, I've run into an issue when trying to set ignored errors via QUARKUS_LOG_SENTRY_IGNORED_ERRORS.
There seems to be a bug in the Sentry whereby the so-called "external configuration" overrides the options previously set via the environment variable, instead of doing a merge.
This behaviour is probably specific to the ignoredErrors setter, where the absence of values defined in the external configuration ends up as an empty list (i.e. not a null object), thereby always overriding any previous value.
I think I will open a bug report at Sentry.

So, in the meantime, I worked around the issue by setting the "low-level" environment variable SENTRY_IGNORED_ERRORS instead.
This worked, but I'm actually surprised that it did. I was expecting Sentry to fully/only rely on the settings from quarkus-logging-sentry.
I guess that's because the SentryHandler() always sets enableExternalConfiguration to true, and then immediately calls Sentry.init(options) without giving the opportunity to disable this external configuration.
I find this behaviour of the Sentry SDK a bit strange.

By the way, as I mentioned above, the SentryHandler() constructor already calls Sentry::init(options).
Isn't the following line redundant then?

@melloware
Copy link
Contributor

Seems redundant to me. Wanna submit a PR?

Also did you report the original issue to the Sentry SDK team?

@melloware
Copy link
Contributor

@dalbani i am new to Sentry but can you explain how breadcrumbs work?

so the docs say this

Every log statement that is greater than minimum breadcrumb level is added to Sentry scope as a breadcrumb, which can be later attached to SentryEvent if one is triggered.

So if I do this...

public String nope() {
        LOG.info("Log before throwing a runtime error!");
        sentryLogger.info("Log before throwing a runtime error!");
        throw new RuntimeException("broken");
    }

I get the Sentry error for the RuntimeException but I was expecting to see the LOG.INFO message as "breadcrumb" and I am not. So there is something I am not understanding about breadcrumbs?

@dalbani
Copy link
Contributor Author

dalbani commented Feb 24, 2025

Also did you report the original issue to the Sentry SDK team?

I've just done it at getsentry/sentry-java#4205.

@dalbani
Copy link
Contributor Author

dalbani commented Feb 24, 2025

@dalbani i am new to Sentry but can you explain how breadcrumbs work?

I'm not really familiar with breadcrumbs, to be honest.
I understand from https://docs.sentry.io/platforms/java/guides/jul/enriching-events/breadcrumbs/#automatic-breadcrumbs that some SDKs have this automatic breadcrumbs capability.
But I wouldn't be surprised if the Java SDK required adding breadcrumbs manually/programmatically.

@adinauer
Copy link

I get the Sentry error for the RuntimeException but I was expecting to see the LOG.INFO message as "breadcrumb" and I am not. So there is something I am not understanding about breadcrumbs?

@melloware this should be working if you set minimumBreadcrumbLevel to INFO or lower. You may also find our JUL sample helpful, but I'm not sure how well it translates into quarkus.

@melloware
Copy link
Contributor

@adinauer yep I am doing exactly that let me debug futher I had the minimumBreadCrumbLevel set properly but was definitely not seeing any logs like in your JUL example above.

@adinauer
Copy link

@melloware can you attach a debugger and check minimumBreadcrumbLevel in SentryHandler.publish?

@melloware
Copy link
Contributor

@adinauer yep will try and get to this today.

@melloware
Copy link
Contributor

Maybe i am doing something wrong but I can see in the SentryEvent the breadCrumbs is empty

image

@melloware
Copy link
Contributor

Here is a simple reproducer:

sentry-breadcrumb.zip

Unzip and point your DNS in application.properties

quarkus.log.sentry.dsn=http://446042f84f35fff57e40ac40f4ab4489@localhost:9000/2

Then run mvn quarkus:dev

Hit http://localhost:8080/logging-sentry/broken to fire off the exception with no bread crumbs

@dalbani
Copy link
Contributor Author

dalbani commented Feb 26, 2025

@melloware
Would you know if/how it's possible to define the list of ignored errors as a individual environment variables?
The reason being that I have error strings which contains a comma, which is considered a separator in the literal list.
I tried the following, as explained on https://quarkus.io/guides/config-reference#environment-variables and https://stackoverflow.com/questions/73454492/how-to-pass-quarkus-list-configuration-via-environment-variable:

QUARKUS_LOG_SENTRY_IGNORED_ERRORS_0_=error1
QUARKUS_LOG_SENTRY_IGNORED_ERRORS_1_=error2

But it doesn't seem to work as the list as SentryConfig::ignoredErrors() is an empty Optional in SentryHandlerValueFactory.

The reason why I ask for environment variables specifically is that I'm using the Quarkus extension in Keycloak on Kubernetes, where environment variables are the only option I have to pass settings AFAIK.

@melloware
Copy link
Contributor

@dalbani this would probably be a good @radcortez question or on the Zulip channel?

@dalbani
Copy link
Contributor Author

dalbani commented Feb 26, 2025

Thanks for the suggestion.

I've just tried in a dummy Quarkus app where I could put the settings in application.properties:

quarkus.log.sentry.ignored-errors[0]=error1
quarkus.log.sentry.ignored-errors[1]=error2

And it did work then. So there must be magic I'm missing with environment variables.
Provided what I want is technically possible.

@radcortez
Copy link

Yes, it should work, but it seems that having the declaration:

@Deprecated(forRemoval = true)
@WithParentName
Optional<Boolean> enable();

Is causing the that env name to not be matched. I'll have a look.

In the meantime you can use the rules of environment values detailed here: https://quarkus.io/guides/config-reference#environment-variables. Just add an empty quarkus.log.sentry.ignored-errors[0] to override it with QUARKUS_LOG_SENTRY_IGNORED_ERRORS_0_

melloware added a commit that referenced this pull request Feb 27, 2025
melloware added a commit that referenced this pull request Feb 27, 2025
@radcortez
Copy link

@melloware
Copy link
Contributor

thanks @radcortez !

@dalbani
Copy link
Contributor Author

dalbani commented Feb 27, 2025

Just add an empty quarkus.log.sentry.ignored-errors[0] to override it with QUARKUS_LOG_SENTRY_IGNORED_ERRORS_0_

Doh, of course, until I can use environment variables, I can simply pass the settings to the JVM with -Dquarkus.log.sentry.ignored-errors[0]=xxx, -Dquarkus.log.sentry.ignored-errors[1]=xxx, etc.
Thanks for the suggestion!

melloware added a commit that referenced this pull request Feb 27, 2025
@radcortez
Copy link

You can still use environment variables, you just need to have the correct name of the configuration in some source like application.properties. The issue here is that when you only set QUARKUS_LOG_SENTRY_IGNORED_ERRORS_0_, we don't know if the segments should be separated with dots or dashes, so we need to do some matching with the mapping names (which has the bug in that specific scenario that I've fixed).

When a mapping is unavailable to help with the matching, you can set a quarkus.log.sentry.ignored-errors[0] in any source. This would hint the matching mechanism to disambiguate between dots and dashes and perform the matching correctly with the Env name.

So, even if the mapping matching has a bug, you can still rely on the hint matching.

@melloware
Copy link
Contributor

@dalbani once you confirm and get this working can you submit a PR updating the asciidoc Guide for other users related to ignore errors?

@dalbani
Copy link
Contributor Author

dalbani commented Feb 27, 2025

You can still use environment variables, you just need to have the correct name of the configuration in some source like application.properties.

As I mentioned above, my use case is using this extension in Keycloak on Kubernetes, where I don't have the ability to have such an application.properties file.

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

Successfully merging this pull request may close these issues.

4 participants