Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7bbbe08
ref: fix test linting (#491)
marandaneto Jul 23, 2020
95cc5f4
fix: event.level fatal is not a crashed session (#492)
marandaneto Jul 23, 2020
50a2165
feat: drop store endpoint in favor of envelope (#490)
marandaneto Jul 24, 2020
2f3b563
fix: ktlint for kts files (#493)
marandaneto Jul 24, 2020
29fbcc7
sentry-java readme
bruno-garcia Jul 27, 2020
14a5e29
feat: rotate cache folder (#494)
marandaneto Jul 28, 2020
db5345b
Merge remote-tracking branch 'origin' into feat/sentry-java
maciejwalkowiak Jul 29, 2020
ad2e0d8
make EventProcessor.process Nullable (#507)
davemt Aug 5, 2020
707015f
Merge remote-tracking branch 'origin/master' into feat/sentry-java
maciejwalkowiak Aug 11, 2020
acfb973
Merge remote-tracking branch 'origin/master' into feat/sentry-java
maciejwalkowiak Aug 12, 2020
9607fea
fix merge conflict
marandaneto Aug 13, 2020
d18da36
Add Logback integration. (#511)
maciejwalkowiak Aug 20, 2020
d14445a
Merge branch 'master' into 3.0.0
marandaneto Aug 26, 2020
68c7ceb
Sentry Spring Boot Starter. (#517)
maciejwalkowiak Aug 27, 2020
2d6e215
Refactor binding options (#530)
maciejwalkowiak Aug 29, 2020
0a8bde6
Add `sendDefaultPii` flag to `SentryOptions`. (#531)
maciejwalkowiak Aug 30, 2020
82e4efe
Attach breadcrumbs to events triggered in Logback integration. (#532)
maciejwalkowiak Aug 31, 2020
944f478
Bump to 3.0.0-alpha.1 (#535)
marandaneto Sep 1, 2020
eefdd31
feat: enable release health by default (#534)
marandaneto Sep 1, 2020
df08324
Merge branch 'master' into 3.0.0
marandaneto Sep 2, 2020
35750dd
Add Log4j2 integration. (#537)
maciejwalkowiak Sep 2, 2020
3737aab
feat: session updates along with the event (#514)
marandaneto Sep 3, 2020
cd6f526
Merge remote-tracking branch 'origin/master' into feat/sentry-java
maciejwalkowiak Sep 3, 2020
3915ca4
fix: enable session tracking by default on sample (#538)
marandaneto Sep 3, 2020
9aad2cb
chore 3.0.0-alpha.1
marandaneto Sep 3, 2020
e767af6
prepare: 3.0.0-alpha.2
marandaneto Sep 3, 2020
b754303
Bump Gradle to 6.6.1
marandaneto Sep 3, 2020
60af521
Extract minimum required coverage by Jacoco plugin. (#541)
maciejwalkowiak Sep 4, 2020
799e581
Merge branch 'master' into 3.0.0
marandaneto Sep 4, 2020
923f9fc
Add Spring Integration. (#539)
maciejwalkowiak Sep 8, 2020
7845eb8
Merge branch '3.0.0' into feat/sentry-java
bruno-garcia Sep 8, 2020
89b7606
fix conflicts
marandaneto Sep 9, 2020
ed1b133
Merge branch 'master' into 3.0.0
marandaneto Sep 9, 2020
33766f4
ref: move init flag (#542)
marandaneto Sep 9, 2020
c891d6a
fix: Asserting events on Envelope sent to Transport (#548)
maciejwalkowiak Sep 9, 2020
ae0219d
Add option to set user information via `SentryUserProvider` (#549)
maciejwalkowiak Sep 9, 2020
cdb4530
Merge branch '3.0.0' into feat/sentry-java
bruno-garcia Sep 9, 2020
6d02f98
upgrade cache id
marandaneto Sep 10, 2020
dd0e7d8
Feat/sentry java fix kotlin (#552)
maciejwalkowiak Sep 10, 2020
188ef14
ref: sentry-core to sentry (#553)
bruno-garcia Sep 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sentry Spring Boot Starter. (#517)
  • Loading branch information
maciejwalkowiak authored Aug 27, 2020
commit 68c7ceb3f1446c3fb608182dd7bded36f15edefd
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ allprojects {
dependsOn("cleanTest")
}
withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile"))
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile", "-Xlint:-processing"))
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ object Config {
val kotlinVersion = "1.3.72"
val kotlinStdLib = "stdlib-jdk8"

val springBootVersion = "2.3.3.RELEASE"

object BuildPlugins {
val androidGradle = "com.android.tools.build:gradle:4.0.1"
val kotlinGradlePlugin = "gradle-plugin"
val buildConfig = "com.github.gmazzo.buildconfig"
val buildConfigVersion = "2.0.2"
val springBoot = "org.springframework.boot"
val springDependencyManagement = "io.spring.dependency-management"
val springDependencyManagementVersion = "1.0.10.RELEASE"
}

object Android {
Expand Down Expand Up @@ -35,6 +40,16 @@ object Config {

val logbackVersion = "1.2.3"
val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion"

val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion"

val springWeb = "org.springframework:spring-webmvc"
val servletApi = "javax.servlet:javax.servlet-api"
}

object AnnotationProcessors {
val springBootAutoConfigure = "org.springframework.boot:spring-boot-autoconfigure-processor"
val springBootConfiguration = "org.springframework.boot:spring-boot-configuration-processor"
}

object TestLibs {
Expand All @@ -47,6 +62,9 @@ object Config {
val robolectric = "org.robolectric:robolectric:4.3.1"
val mockitoKotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
val awaitility = "org.awaitility:awaitility-kotlin:4.0.3"
val springBootStarterTest = "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
val springBootStarterWeb = "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
val springBootStarterSecurity = "org.springframework.boot:spring-boot-starter-security:$springBootVersion"
}

object QualityPlugins {
Expand All @@ -66,6 +84,7 @@ object Config {
val SENTRY_JAVA_SDK_NAME = "sentry.java"
val SENTRY_ANDROID_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.android"
val SENTRY_LOGBACK_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.logback"
val SENTRY_SPRING_BOOT_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.spring-boot"
val group = "io.sentry"
val description = "SDK for sentry.io"
val website = "https://sentry.io"
Expand Down
11 changes: 11 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -123,6 +124,16 @@ public static void init(
init(options, globalHubMode);
}

/**
* Initializes the SDK with a SentryOptions.
*
* @param options options the SentryOptions
*/
@ApiStatus.Internal
public static void init(final @NotNull SentryOptions options) {
init(options, GLOBAL_HUB_DEFAULT_MODE);
}

/**
* Initializes the SDK with a SentryOptions and globalHubMode
*
Expand Down
60 changes: 34 additions & 26 deletions sentry-core/src/main/java/io/sentry/core/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -78,19 +79,7 @@ public SentryClient(final @NotNull SentryOptions options, @Nullable Connection c
.log(SentryLevel.DEBUG, "Event was cached so not applying scope: %s", event.getEventId());
}

for (EventProcessor processor : options.getEventProcessors()) {
event = processor.process(event, hint);

if (event == null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped by processor: %s",
processor.getClass().getName());
break;
}
}
event = processEvent(event, hint, options.getEventProcessors());

if (event == null) {
return SentryId.EMPTY_ID;
Expand Down Expand Up @@ -127,6 +116,37 @@ public SentryClient(final @NotNull SentryOptions options, @Nullable Connection c
return event.getEventId();
}

@Nullable
private SentryEvent processEvent(
@NotNull SentryEvent event,
final @Nullable Object hint,
final @NotNull List<EventProcessor> eventProcessors) {
for (EventProcessor processor : eventProcessors) {
try {
event = processor.process(event, hint);
} catch (Exception e) {
options
.getLogger()
.log(
SentryLevel.ERROR,
e,
"An exception occurred while processing event by processor: %s",
processor.getClass().getName());
}

if (event == null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped by a processor: %s",
processor.getClass().getName());
break;
}
}
return event;
}

/**
* Updates the session data based on the event, hint and scope data
*
Expand Down Expand Up @@ -274,19 +294,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
event.setLevel(scope.getLevel());
}

for (EventProcessor processor : scope.getEventProcessors()) {
event = processor.process(event, hint);

if (event == null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped by scope processor: %s",
processor.getClass().getName());
break;
}
}
event = processEvent(event, hint, scope.getEventProcessors());
}
return event;
}
Expand Down
8 changes: 8 additions & 0 deletions sentry-core/src/test/java/io/sentry/core/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.sentry.core.transport.AsyncConnection
import io.sentry.core.transport.HttpTransport
import io.sentry.core.transport.ITransportGate
import java.io.IOException
import java.lang.RuntimeException
import java.net.URL
import java.util.UUID
import kotlin.test.Ignore
Expand Down Expand Up @@ -655,6 +656,13 @@ class SentryClientTest {
}, anyOrNull())
}

@Test
fun `exception thrown by an event processor is handled gracefully`() {
fixture.sentryOptions.addEventProcessor { _, _ -> throw RuntimeException() }
val sut = fixture.getSut()
sut.captureEvent(SentryEvent())
}

private fun createScope(): Scope {
return Scope(SentryOptions()).apply {
addBreadcrumb(Breadcrumb().apply {
Expand Down
40 changes: 40 additions & 0 deletions sentry-samples/sentry-samples-spring-boot/build.gradle.kts
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")
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")
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
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 + '\'' + '}';
}
}
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;
}
}
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);
}
}
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);
}
}
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://[email protected]/1808954
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>
Loading