This repository was archived by the owner on Aug 30, 2023. It is now read-only.
  
  
  - 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 32
Sentry Spring Boot Starter. #517
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            28 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f107786
              
                Initial Sentry Spring Boot Starter.
              
              
                maciejwalkowiak 58aab5a
              
                Pass request and user data to Sentry event.
              
              
                maciejwalkowiak b4ef72e
              
                Set cookies on SentryEvent.
              
              
                maciejwalkowiak b15ae23
              
                Merge branch 'feat/sentry-java' into sentry-java-spring-boot
              
              
                maciejwalkowiak f2b950e
              
                Generate properties files from Spring Boot auto-configuration and con…
              
              
                maciejwalkowiak fada413
              
                Raise required test coverage to 60%
              
              
                maciejwalkowiak 3588a51
              
                Refactor & add more auto-configuration tests.
              
              
                maciejwalkowiak 7714510
              
                Polish.
              
              
                maciejwalkowiak 73a4d56
              
                Add more auto-configuration tests.
              
              
                maciejwalkowiak b9adb07
              
                Set Git commit id as release version.
              
              
                maciejwalkowiak fa510f3
              
                Improve printing failed tests reason.
              
              
                maciejwalkowiak fdb3b7e
              
                Await assertions as events are sent asynchronously.
              
              
                maciejwalkowiak 1acf623
              
                Polish.
              
              
                maciejwalkowiak 1219ad1
              
                Catch exceptions thrown by event processors.
              
              
                maciejwalkowiak fd609ce
              
                Polish.
              
              
                maciejwalkowiak f5490cc
              
                Fix attaching request and user information for uncaught exceptions.
              
              
                maciejwalkowiak 21bc5be
              
                Add Sentry Spring Boot Sample.
              
              
                maciejwalkowiak c2f7f57
              
                Add Sentry Spring Boot Sample.
              
              
                maciejwalkowiak f8c5352
              
                Import classes.
              
              
                maciejwalkowiak 75f8d55
              
                Polish.
              
              
                maciejwalkowiak 5a7f15e
              
                Polish.
              
              
                maciejwalkowiak 85ad96d
              
                Polish.
              
              
                maciejwalkowiak 6cba5b5
              
                Polish.
              
              
                maciejwalkowiak 8e6ad89
              
                Change group id in Spring Boot Sample.
              
              
                maciejwalkowiak bb863f2
              
                Handle multiple ip addresses in X-FORWARDED-FOR header.
              
              
                maciejwalkowiak 41b845e
              
                Polish Gradle configuration.
              
              
                maciejwalkowiak cb0a1a9
              
                Polish Gradle configuration.
              
              
                maciejwalkowiak c311428
              
                Polish Gradle configuration.
              
              
                maciejwalkowiak File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  sentry-samples/sentry-samples-spring-boot/build.gradle.kts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|  | ||
| plugins { | ||
| id(Config.BuildPlugins.springBoot) version Config.springBootVersion | ||
| id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion | ||
| kotlin("jvm") | ||
| kotlin("plugin.spring") version Config.kotlinVersion | ||
| } | ||
|  | ||
| group = "io.sentry.sample.spring-boot" | ||
| version = "0.0.1-SNAPSHOT" | ||
| java.sourceCompatibility = JavaVersion.VERSION_1_8 | ||
|  | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|  | ||
| dependencies { | ||
| implementation("org.springframework.boot:spring-boot-starter-security") | ||
| implementation("org.springframework.boot:spring-boot-starter-web") | ||
| implementation("org.springframework.boot:spring-boot-starter") | ||
| implementation("org.jetbrains.kotlin:kotlin-reflect") | ||
| implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
|         
                  maciejwalkowiak marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| implementation(project(":sentry-spring-boot-starter")) | ||
| implementation(project(":sentry-logback")) | ||
| testImplementation("org.springframework.boot:spring-boot-starter-test") { | ||
| exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | ||
| } | ||
| } | ||
|  | ||
| tasks.withType<Test> { | ||
| useJUnitPlatform() | ||
| } | ||
|  | ||
| tasks.withType<KotlinCompile> { | ||
| kotlinOptions { | ||
| freeCompilerArgs = listOf("-Xjsr305=strict") | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this? just curiosity There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
| } | ||
| } | ||
        
          
          
            24 changes: 24 additions & 0 deletions
          
          24 
        
  sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/Person.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package io.sentry.samples.spring; | ||
|  | ||
| public class Person { | ||
| private final String firstName; | ||
| private final String lastName; | ||
|  | ||
| public Person(String firstName, String lastName) { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| } | ||
|  | ||
| public String getFirstName() { | ||
| return firstName; | ||
| } | ||
|  | ||
| public String getLastName() { | ||
| return lastName; | ||
| } | ||
|  | ||
| @Override | ||
| public String toString() { | ||
| return "Person{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}'; | ||
| } | ||
| } | 
        
          
          
            27 changes: 27 additions & 0 deletions
          
          27 
        
  ...s/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/PersonController.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package io.sentry.samples.spring; | ||
|  | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|  | ||
| @RestController | ||
| @RequestMapping("/person/") | ||
| public class PersonController { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(PersonController.class); | ||
|  | ||
| @GetMapping("{id}") | ||
| Person person(@PathVariable Long id) { | ||
| throw new IllegalArgumentException("Something went wrong [id=" + id + "]"); | ||
| } | ||
|  | ||
| @PostMapping | ||
| Person create(@RequestBody Person person) { | ||
| LOGGER.warn("Creating person: {}", person); | ||
| return person; | ||
| } | ||
| } | 
        
          
          
            55 changes: 55 additions & 0 deletions
          
          55 
        
  ...try-samples-spring-boot/src/main/java/io/sentry/samples/spring/SecurityConfiguration.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.sentry.samples.spring; | ||
|  | ||
| import io.sentry.core.IHub; | ||
| import io.sentry.spring.boot.SentrySecurityFilter; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| import org.springframework.security.core.userdetails.User; | ||
| import org.springframework.security.core.userdetails.UserDetails; | ||
| import org.springframework.security.core.userdetails.UserDetailsService; | ||
| import org.springframework.security.crypto.factory.PasswordEncoderFactories; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
| import org.springframework.security.web.authentication.AnonymousAuthenticationFilter; | ||
|  | ||
| @Configuration | ||
| public class SecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
|  | ||
| private final @NotNull IHub hub; | ||
|  | ||
| public SecurityConfiguration(final @NotNull IHub hub) { | ||
| this.hub = hub; | ||
| } | ||
|  | ||
| @Override | ||
| protected void configure(final @NotNull HttpSecurity http) throws Exception { | ||
| // register SentrySecurityFilter to attach user information to SentryEvents | ||
| http.addFilterAfter(new SentrySecurityFilter(hub), AnonymousAuthenticationFilter.class) | ||
| .csrf() | ||
| .disable() | ||
| .authorizeRequests() | ||
| .anyRequest() | ||
| .authenticated() | ||
| .and() | ||
| .httpBasic(); | ||
| } | ||
|  | ||
| @Bean | ||
| @Override | ||
| public @NotNull UserDetailsService userDetailsService() { | ||
| final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); | ||
|  | ||
| final UserDetails user = | ||
| User.builder() | ||
| .passwordEncoder(encoder::encode) | ||
| .username("user") | ||
| .password("password") | ||
| .roles("USER") | ||
| .build(); | ||
|  | ||
| return new InMemoryUserDetailsManager(user); | ||
| } | ||
| } | 
        
          
          
            12 changes: 12 additions & 0 deletions
          
          12 
        
  ...try-samples-spring-boot/src/main/java/io/sentry/samples/spring/SentryDemoApplication.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.sentry.samples.spring; | ||
|  | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|  | ||
| @SpringBootApplication | ||
| public class SentryDemoApplication { | ||
|  | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(SentryDemoApplication.class, args); | ||
| } | ||
| } | 
        
          
          
            2 changes: 2 additions & 0 deletions
          
          2 
        
  sentry-samples/sentry-samples-spring-boot/src/main/resources/application.properties
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard | ||
| sentry.dsn=https://f7f320d5c3a54709be7b28e0f2ca7081@sentry.io/1808954 | 
        
          
          
            16 changes: 16 additions & 0 deletions
          
          16 
        
  sentry-samples/sentry-samples-spring-boot/src/main/resources/logback.xml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
| <include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
| <include resource="org/springframework/boot/logging/logback/console-appender.xml" /> | ||
|  | ||
| <appender name="SENTRY" class="io.sentry.logback.SentryAppender"> | ||
| <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
| <level>WARN</level> | ||
| </filter> | ||
| </appender> | ||
|  | ||
| <root level="info"> | ||
| <appender-ref ref="CONSOLE" /> | ||
| <appender-ref ref="SENTRY" /> | ||
| </root> | ||
| </configuration> | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.