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

Calling Sentry.init and specifying contextTags now has an effect on the Logback SentryAppender #2052

Merged
merged 8 commits into from
May 25, 2022

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented May 16, 2022

📜 Description

No longer used the options property in SentryAppender, instead get Options from HubAdapter.

💡 Motivation and Context

Fix #2043 for Logback

💚 How did you test it?

Demo Code

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

…java

Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (6.x.x@48c6733). Click here to learn what that means.
The diff coverage is n/a.

@@           Coverage Diff            @@
##             6.x.x    #2052   +/-   ##
========================================
  Coverage         ?   80.88%           
  Complexity       ?     3170           
========================================
  Files            ?      228           
  Lines            ?    11717           
  Branches         ?     1574           
========================================
  Hits             ?     9477           
  Misses           ?     1649           
  Partials         ?      591           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48c6733...cf94b46. Read the comment docs.

@marandaneto
Copy link
Contributor

Missing changelog.

@@ -112,8 +116,9 @@ protected void append(@NotNull ILoggingEvent eventObject) {
CollectionUtils.filterMapEntries(
loggingEvent.getMDCPropertyMap(), entry -> entry.getValue() != null);
if (!mdcProperties.isEmpty()) {
if (!options.getContextTags().isEmpty()) {
for (final String contextTag : options.getContextTags()) {
final List<String> contextTags = HubAdapter.getInstance().getOptions().getContextTags();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing, we have the options property, but we read from HubAdapter.getInstance().getOptions().
Should we rather get rid of the options then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why i created #2053 I just didn't want to do it now as this quick fix solves the current problem and further improvements didn't seem urgent

Comment on lines 57 to 58
// NOTE: logback.xml properties will not be applied in this case as the SDK has already been
// initialized
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather improve the logging message below instead of adding a comment in the code.

Copy link
Member Author

@adinauer adinauer May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like I put this in the wrong else path, will update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -33,6 +34,7 @@
/** Appender for logback in charge of sending the logged events to a Sentry server. */
@Open
public class SentryAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
// WARNING: Do not use these options in here, they are only to be used for startup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove this options altogether and set the values directly in the configuration callback when initing the SDK, unless there's a reason to not do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above regarding #2053

Copy link
Contributor

@maciejwalkowiak maciejwalkowiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done differently: pass SentryOptions in SentryLogbackInitializer to SentryAppender via constructor - this way options used in both will be in sync - i think it's a better approach than HubAdapter.getInstance.

BUT in case of unhandled exception, event triggered by Logback will be removed by DuplicateEventDetectionEventProcessor. As a result, only event created by SentryExceptionResolver will be send to sentry, and this one does not contain context tags

So unfortunately neither this PR, nor my constructor approach to SentryAppender solve this issue.

@adinauer adinauer merged commit 6b3fd20 into 6.x.x May 25, 2022
@adinauer adinauer deleted the fix/init-not-affecting-logback branch May 25, 2022 09:50
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.

5 participants