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

Conversation

@maciejwalkowiak
Copy link
Contributor

@maciejwalkowiak maciejwalkowiak commented Aug 14, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Sentry Spring Boot Starter providing configuration via Spring Boot @ConfigurationProperties, automatically setting HTTP request details on SentryEvent#request, setting user details on SentryEvent#user.

💡 Motivation and Context

In conjunction with sentry-logback enables users to utilise Sentry with close to zero extra effort.

💚 How did you test it?

📝 Checklist

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

🔮 Next steps

Currently we have only Spring MVC integration (and indirectly Spring Security through getting user data from Principal). I think this PR should not contain anything more.
We can consider other integrations as separate tasks & PRs.

@maciejwalkowiak maciejwalkowiak changed the base branch from master to feat/sentry-java August 20, 2020 10:05
@maciejwalkowiak
Copy link
Contributor Author

I figured out how to set up annotation processing 🎉

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.

First pass: Love where this is going!

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.

happy where this is going @maciejwalkowiak
left a few comments though.

private static @NotNull User toUser(
final @Nullable User existingUser, final @NotNull HttpServletRequest request) {
final User user = existingUser != null ? existingUser : new User();
user.setIpAddress(toIpAddress(request));
Copy link
Contributor

@marandaneto marandaneto Aug 25, 2020

Choose a reason for hiding this comment

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

I'm afraid that this would require the send_default_pii flag to be added on options, which is disabled by default.
https://docs.sentry.io/error-reporting/configuration/?platform=python

cc @bruno-garcia

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like it is working for me

image

Copy link
Contributor

Choose a reason for hiding this comment

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

but that's the problem, the SDK should only capture (automatically) PII if the flag send_default_pii is enabled, as we don't even have the flag, sending this info would be a PII problem, basically, to capture and send the IP address should only be possible if the user has enabled this flag like sentry.sendDefaultPII=true, as we don't even have/expose this flag yet, I'd say that we should skip the IP address for now (maybe just commenting the code and adding a TODO).
or to implement the flag on this or another PR.

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 ok, understood. I imagine username could be also considered PII. In case of Spring integration, this filter has to be added explicitly by the user as we are not able to autoconfigure it. Maybe it's ok then to stay as it's just an opt-in option?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah usually those things are opt-in.
the thing is, we need to make it opt-in when we are able to collect this info automatically eg IP Address, if the user depends on the customer setting like Sentry.setUser(...) then it's fine, I'm just not sure if the IP address here is set by the customer or Spring offers this for free, that's the question that should be answered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We either take the ip address from the X-FORWARDED-FOR header set by load balancers or directly from HttpServletRequest object. But in order to use it, users have to explicitly create an instance of this filter and add it to Spring Security configuration (example https://github.com/getsentry/sentry-android/pull/517/files#diff-6c5b2fc2c37b9e5c8bdbdc86be9588ccR30)

Copy link
Member

Choose a reason for hiding this comment

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

What @marandaneto said.
Could you please add Boolean sendDefaultPii to SentryOptions and checking for that before adding any of this user data by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, in this case it is enough to add it to SentryProperties but I am wondering if we shouldn't erase any personal information somewhere deeper in sentry-core if this flag is set to false?

Copy link
Contributor

Choose a reason for hiding this comment

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

that's a good point, if the flag is a safeguard to not even set it, I don't see how we could do differently other than doing the check guard in all the setters/all the integrations.

the other option would be if setIpAddress gets a boolean to set it or not so at least we don't repeat the same if everywhere.

we could start doing this check guard in here and if we see the need for other places, we just refactor it?!

the other option would be, we always set it, if possible, and we could create a PiiEventProcessor that reads the flag and erase the values if set, it'd be an elegant way of solving it, but this allows the user to set it in the first place, I don't know if this is fine or not. cc @bruno-garcia

Copy link
Member

Choose a reason for hiding this comment

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

We don't have any PII to be erased yet. We delayed adding the flag until the first one popped up.
Happy to merge this and add that later

@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review August 25, 2020 11:45
@maciejwalkowiak maciejwalkowiak changed the title Initial Sentry Spring Boot Starter. Sentry Spring Boot Starter. Aug 25, 2020
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.

Just a few minor points.
Looking forward to merging this! 🚀

}

private static @NotNull String toIpAddress(final @NotNull HttpServletRequest request) {
final String ipAddress = request.getHeader("X-FORWARDED-FOR");
Copy link
Member

Choose a reason for hiding this comment

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

Should this be opt-in?
Would technically expose the server to report a fake client IP if the request was sent to the server by the client with this (no-proxy) set?

Also, I believe the value here can be a list (chained-proxy servers) so might require some more handling.

Comment on lines 4 to 5
id("org.springframework.boot") version "2.3.3.RELEASE"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
Copy link
Contributor

Choose a reason for hiding this comment

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

would be possible to reuse the Config class like the SDK itself? they are probably the same groups/modules/versions

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 build.gradle.kts is kept as close as possible to one generated using https://start.spring.io - I think if we don't touch it much it will be easier to understand for users what exactly needs to be set up to use Sentry.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get your point, but the thing is, the samples on this repo are to easier the development/testing/debugging, not really customer samples, they still could learn from it, but that's not the main reason, we have eg https://github.com/getsentry/examples/tree/master/java
we'd be updating the examples after publishing these new integrations and there we'd keep as close as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it. Would you also like to put all the dependencies from sample application to Config class?

Copy link
Contributor

@marandaneto marandaneto Aug 26, 2020

Choose a reason for hiding this comment

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

for me, it only makes sense the ones that are also used in the SDK itself, the dependencies of the samples that are only used in the samples, its fine to be hardcoded.
if it happens that a dependency of a sample is hardcoded but still share a version that is in the config file, then I'd do a string template like "dependency$Config.sharedVersion" so we know that if we update something, it's done only in one place, this is just a nit about DRY though.


tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this? just curiosity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also added by start.spring.io - i think it's meant to tell Kotlin to respect Spring Framework nullability related annotations.

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.

LGTM

@bruno-garcia bruno-garcia merged commit 68c7ceb into feat/sentry-java Aug 27, 2020
@bruno-garcia bruno-garcia deleted the sentry-java-spring-boot branch August 27, 2020 14:22
maciejwalkowiak added a commit to maciejwalkowiak/sentry-android that referenced this pull request Aug 30, 2020
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