Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Add Spring Integration. #539

Merged
merged 21 commits into from
Sep 8, 2020
Merged

Add Spring Integration. #539

merged 21 commits into from
Sep 8, 2020

Conversation

maciejwalkowiak
Copy link
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Many of beans previously instantiated in Spring Boot integration move to Spring integration. Spring Boot integration enables more fine grained SentryOptions configuration, simple way to register custom event processors, passing git commit id as the event release version.

💡 Motivation and Context

Feature parity with Sentry 1.x

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • No breaking changes

🔮 Next steps

Many of beans previously instantiated in Spring Boot integration move to Spring integration. Spring Boot integration enables more fine grained SentryOptions configuration, simple way to register custom event processors, passing git commit id as the event release version.
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = ["sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true"]
)
class SentrySpringIntegrationTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test class is almost a duplicate from Sentry Spring Boot integration. I am not sure yet if/how we can reduce the duplication keeping the same confidence level.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we maybe add a comment to this class and the "duplicated" one about each other? so when touching either this one or the other one, we know that they need to keep kinda synced

@lgtm-com
Copy link

lgtm-com bot commented Sep 3, 2020

This pull request introduces 1 alert when merging 0bee84f into cd6f526 - view on LGTM.com

new alerts:

  • 1 for Disabled Spring CSRF protection

@lgtm-com
Copy link

lgtm-com bot commented Sep 3, 2020

This pull request introduces 1 alert when merging cd37677 into cd6f526 - view on LGTM.com

new alerts:

  • 1 for Disabled Spring CSRF protection

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Mini first pass

public class CustomEventProcessor implements EventProcessor {
@Override
public SentryEvent process(SentryEvent event, @Nullable Object hint) {
event.setTag("Java Version", System.getProperty("java.version"));
Copy link
Member

Choose a reason for hiding this comment

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

This is nice, should we add to the Runtime context?

https://develop.sentry.dev/sdk/event-payloads/contexts#runtime-context

Shows up like this in Sentry:

image

Can we get for example: JVM version, or if it's Oracle JVM vs OpenJVM?
Graal or whatever else?

We can add the logos etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep we could, but then i guess we would add it to sentry-core? I we go for it i need another idea for reasonable example of event processor ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

not really, it should be a processor specifically for java backend/desktop, it should not be executed on Android at least, it won't return anything.
I mean it could live in sentry-core cus there's no compiling error, but I don't think it should be executed on runtime by default on all the platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sentry does not recognize Java runtime. I keep it for now in a sample, we can consider moving it to sentry-core once it's agreed what runtime values are recognized.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maciejwalkowiak what do you mean by "Sentry does not recognize Java runtime"? if it's about the icon, this is just an UI limitation.
but agreed, we can make this in other PR, it doesn't make sense to block this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my bad. I thought unknown values are not passed but I just had NPE thrown in the processor. All good now :-) Anyway, I would prefer to close this one and move it to the next PR.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

approved prematurely

@bruno-garcia bruno-garcia self-requested a review September 3, 2020 22:44
@@ -29,11 +31,23 @@ protected void doFilterInternal(
final @NotNull FilterChain filterChain)
throws ServletException, IOException {
hub.pushScope();
// clears breadcrumbs that may have been added during application startup through one of the logging integrations.
hub.clearBreadcrumbs();
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to expose the clear method in the hub then? which is basically cleaning everything from the scope?

Copy link
Contributor

Choose a reason for hiding this comment

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

could we lose useful information when cleaning all the breadcrumbs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is there to avoid having startup logs attached to every event sent. If we do not clear breadcrumbs every event looks like:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this is fine, not sure how noisy this can get though.
every event on android also has many startup breadcrumbs, but I believe that this is what breadcrumbs stand for, if it's like less than 5, all good, it'd be a problem if its a huge number and just trash.
maybe @bruno-garcia has opinions
I'm just afraid of losing useful breadcrumbs added by the user manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I still believe these breadcrumbs create noise, but since both @marandaneto and @bruno-garcia are more leaning towards keeping them, they are now not removed.

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/** Initializes Sentry after all beans are registered. */
Copy link
Contributor

@marandaneto marandaneto Sep 7, 2020

Choose a reason for hiding this comment

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

out of curiosity, if there's a bug on customer's beans and Sentry is the last to be inited, would that mean that we won't be able to capture the crash? should it not be the other way around, as the 1st one? if possible, of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is why logging framework integration should be used as well. Logging framework is initialized first so it will catch any bug that happens during startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok sounds good, still curious how this would work, if a logging framework forwards the call to sentry, sentry won't be init./enabled yet, right, unless the logging framework has a sort of caching, not sure.
we can discuss this offline though, I'd like to understand a little bit more :) thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logging frameworks calls init first, sends startup events to sentry, then Spring initializes Sentry and configuration provided there is used from now on. The drawback of this solution is that in order to get startup events sent to sentry DSN has to be provided twice - once to Logback configuration and then to Spring configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, but it's a good trade-off I'd say, we just document it properly, and it's fine IMO.
in the future we could look into it to provide a single DSN, might be possible with a little more work, just guessing here though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will be possible if we follow up on #536. To get it working SDK has to have a way to obtain configuration from external source - independent from framework-specific configuration.
I think we will release what we have and then find out next steps from users feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

that sounds great, thanks for explaining!

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

left a few more comments but I'd say they are not blockers, let's iterate over them if necessary, and happy to LGTM.
looks good, well done!

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

looks very good, well done @maciejwalkowiak
LGTM.

@maciejwalkowiak
Copy link
Contributor Author

Thanks @marandaneto!

@maciejwalkowiak
Copy link
Contributor Author

@bruno-garcia take another look please.


@Override
public SentryEvent process(SentryEvent event, @Nullable Object hint) {
final SentryRuntime runtime = new SentryRuntime();
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to do this to all events (put it in the main event processor)
Likely not going to work for Android though

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it won't, we could have the processor on sentry-core but either it gets added to the processor list only if its non-Android or we do a conditional flag.

testImplementation(Config.TestLibs.springBootStarterTest)
testImplementation(Config.TestLibs.springBootStarterWeb)
testImplementation(Config.TestLibs.springBootStarterSecurity)
testImplementation(Config.Libs.springBootStarterTest)
Copy link
Member

Choose a reason for hiding this comment

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

I think this one was supposed to stay as TestLibs

testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
testImplementation(Config.Libs.springBootStarterTest)
testImplementation(Config.Libs.springBootStarterWeb)
Copy link
Member

Choose a reason for hiding this comment

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

here too, test libs only?

Copy link
Contributor

Choose a reason for hiding this comment

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

if it's used in the samples, it's fine to be in the Libs IMO.

@bruno-garcia bruno-garcia merged commit 923f9fc into feat/sentry-java Sep 8, 2020
@bruno-garcia bruno-garcia deleted the spring-integration branch September 8, 2020 18:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants