Skip to content

Commit

Permalink
Merge branch 'main' into gh-1351-transaction-advice
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak authored Apr 21, 2021
2 parents 5730537 + 7ac36c0 commit 8aeee71
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 81 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ jobs:

# Zulu Community distribution of OpenJDK
- name: set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: 1.8
distribution: 'adopt'
java-version: '8'

# use sequential key when bumping dependencies till single lock file is out of preview
# https://docs.gradle.org/current/userguide/dependency_locking.html#single_lock_file_per_project
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
- name: Checkout 🛎️
uses: actions/[email protected]
- name: set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: 1.8
distribution: 'adopt'
java-version: '8'
- name: Check formatting with Spotless
run: make checkFormat
5 changes: 3 additions & 2 deletions .github/workflows/generate-javadocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ jobs:
- name: Checkout 🛎️
uses: actions/[email protected]
- name: set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: 1.8
distribution: 'adopt'
java-version: '8'
- name: Generate Aggregate Javadocs
run: |
./gradlew aggregateJavadocs
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Fix: handle network errors in SentrySpanClientHttpRequestInterceptor (#1407)
* Fix: set scope on transaction (#1409)
* Fix: set status and associate events with transactions (#1426)
* Fix: Apply user from the scope to transaction (#1424)
* Fix: Pass maxBreadcrumbs config. to sentry-native (#1425)

# 4.4.0-alpha.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ class DefaultAndroidEventProcessorTest {
setUser(user)
}
event = sut.process(event, null)
assertNotNull(event.user)
assertNotNull(event.user.id)
assertNotNull(event.user) {
assertNotNull(it.id)
}
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions sentry-android-ndk/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
jmethodID environment_mid = (*env)->GetMethodID(env, options_cls, "getEnvironment",
"()Ljava/lang/String;");
jmethodID dist_mid = (*env)->GetMethodID(env, options_cls, "getDist", "()Ljava/lang/String;");
jmethodID max_crumbs_mid = (*env)->GetMethodID(env, options_cls, "getMaxBreadcrumbs", "()I");

jstring outbox_path_j = (jstring) (*env)->CallObjectMethod(env, sentry_sdk_options,
outbox_path_mid);
Expand All @@ -202,6 +203,7 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
jstring environment = (jstring) (*env)->CallObjectMethod(env, sentry_sdk_options,
environment_mid);
jstring dist = (jstring) (*env)->CallObjectMethod(env, sentry_sdk_options, dist_mid);
jint max_crumbs = (jint) (*env)->CallIntMethod(env, sentry_sdk_options, max_crumbs_mid);

ENSURE(outbox_path_j);
const char *outbox_path_str = (*env)->GetStringUTFChars(env, outbox_path_j, 0);
Expand Down Expand Up @@ -229,6 +231,8 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(

sentry_options_set_transport(options, transport);
sentry_options_set_debug(options, debug);
sentry_options_set_max_breadcrumbs(options, max_crumbs);

const char *dsn_str = (*env)->GetStringUTFChars(env, dsn, 0);
sentry_options_set_dsn(options, dsn_str);
(*env)->ReleaseStringUTFChars(env, dsn, dsn_str);
Expand Down
2 changes: 1 addition & 1 deletion sentry-android-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ tasks.withType<Detekt> {
}

configure<DetektExtension> {
failFast = true
buildUponDefaultConfig = true
allRules = true
}
2 changes: 1 addition & 1 deletion sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ tasks.withType<Detekt> {
}

configure<DetektExtension> {
failFast = true
buildUponDefaultConfig = true
allRules = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class SentrySpringIntegrationTest {
assertThat(event.request).isNotNull()
assertThat(event.request!!.url).isEqualTo("http://localhost:$port/hello")
assertThat(event.user).isNotNull()
assertThat(event.user.username).isEqualTo("user")
assertThat(event.user.ipAddress).isEqualTo("169.128.0.1")
assertThat(event.user!!.username).isEqualTo("user")
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
}, anyOrNull())
}
}
Expand All @@ -101,7 +101,8 @@ class SentrySpringIntegrationTest {

await.untilAsserted {
verify(transport).send(checkEvent { event ->
assertThat(event.user.ipAddress).isEqualTo("169.128.0.1")
assertThat(event.user).isNotNull()
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
}, anyOrNull())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class SentrySpringIntegrationTest {
assertThat(event.request).isNotNull()
assertThat(event.request!!.url).isEqualTo("http://localhost:$port/hello")
assertThat(event.user).isNotNull()
assertThat(event.user.username).isEqualTo("user")
assertThat(event.user.ipAddress).isEqualTo("169.128.0.1")
assertThat(event.user!!.username).isEqualTo("user")
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
}, anyOrNull())
}
}
Expand All @@ -106,7 +106,8 @@ class SentrySpringIntegrationTest {

await.untilAsserted {
verify(transport).send(checkEvent { event ->
assertThat(event.user.ipAddress).isEqualTo("169.128.0.1")
assertThat(event.user).isNotNull()
assertThat(event.user!!.ipAddress).isEqualTo("169.128.0.1")
}, anyOrNull())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SentryUserProviderEventProcessorIntegrationTest {
await.untilAsserted {
verify(transport).send(checkEvent { event: SentryEvent ->
assertThat(event.user).isNotNull
assertThat(event.user.username).isEqualTo("john.smith")
assertThat(event.user!!.username).isEqualTo("john.smith")
}, anyOrNull())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class SentryUserProviderEventProcessorTest {
val result = processor.process(event, null)

assertNotNull(result)
assertNotNull(result.user)
assertEquals("john.doe", result.user.username)
assertEquals("user-id", result.user.id)
assertEquals("192.168.0.1", result.user.ipAddress)
assertEquals("[email protected]", result.user.email)
assertEquals(mapOf("key" to "value"), result.user.others)
assertNotNull(result.user) {
assertEquals("john.doe", it.username)
assertEquals("user-id", it.id)
assertEquals("192.168.0.1", it.ipAddress)
assertEquals("[email protected]", it.email)
assertEquals(mapOf("key" to "value"), it.others)
}
}

@Test
Expand All @@ -62,12 +63,13 @@ class SentryUserProviderEventProcessorTest {
val result = processor.process(event, null)

assertNotNull(result)
assertNotNull(result.user)
assertEquals("john.doe", result.user.username)
assertEquals("user-id", result.user.id)
assertEquals("192.168.0.1", result.user.ipAddress)
assertEquals("[email protected]", result.user.email)
assertEquals(mapOf("key" to "value"), result.user.others)
assertNotNull(result.user) {
assertEquals("john.doe", it.username)
assertEquals("user-id", it.id)
assertEquals("192.168.0.1", it.ipAddress)
assertEquals("[email protected]", it.email)
assertEquals(mapOf("key" to "value"), it.others)
}
}

@Test
Expand All @@ -78,22 +80,24 @@ class SentryUserProviderEventProcessorTest {
}

val event = SentryEvent()
event.user = User()
event.user.username = "jane.smith"
event.user.id = "jane-smith"
event.user.ipAddress = "192.168.0.3"
event.user.email = "[email protected]"
event.user.others = mapOf("key" to "value")
event.user = User().apply {
username = "jane.smith"
id = "jane-smith"
ipAddress = "192.168.0.3"
email = "[email protected]"
others = mapOf("key" to "value")
}

val result = processor.process(event, null)

assertNotNull(result)
assertNotNull(result.user)
assertEquals("jane.smith", result.user.username)
assertEquals("jane-smith", result.user.id)
assertEquals("192.168.0.3", result.user.ipAddress)
assertEquals("[email protected]", result.user.email)
assertEquals(mapOf("key" to "value"), result.user.others)
assertNotNull(result.user) {
assertEquals("jane.smith", it.username)
assertEquals("jane-smith", it.id)
assertEquals("192.168.0.3", it.ipAddress)
assertEquals("[email protected]", it.email)
assertEquals(mapOf("key" to "value"), it.others)
}
}

@Test
Expand All @@ -103,22 +107,24 @@ class SentryUserProviderEventProcessorTest {
}

val event = SentryEvent()
event.user = User()
event.user.username = "jane.smith"
event.user.id = "jane-smith"
event.user.ipAddress = "192.168.0.3"
event.user.email = "[email protected]"
event.user.others = mapOf("key" to "value")
event.user = User().apply {
username = "jane.smith"
id = "jane-smith"
ipAddress = "192.168.0.3"
email = "[email protected]"
others = mapOf("key" to "value")
}

val result = processor.process(event, null)

assertNotNull(result)
assertNotNull(result.user)
assertEquals("jane.smith", result.user.username)
assertEquals("jane-smith", result.user.id)
assertEquals("192.168.0.3", result.user.ipAddress)
assertEquals("[email protected]", result.user.email)
assertEquals(mapOf("key" to "value"), result.user.others)
assertNotNull(result.user) {
assertEquals("jane.smith", it.username)
assertEquals("jane-smith", it.id)
assertEquals("192.168.0.3", it.ipAddress)
assertEquals("[email protected]", it.email)
assertEquals(mapOf("key" to "value"), it.others)
}
}

@Test
Expand All @@ -130,14 +136,16 @@ class SentryUserProviderEventProcessorTest {
}

val event = SentryEvent()
event.user = User()
event.user.others = mapOf("new-key" to "new-value")
event.user = User().apply {
others = mapOf("new-key" to "new-value")
}

val result = processor.process(event, null)

assertNotNull(result)
assertNotNull(result.user)
assertEquals(mapOf("key" to "value", "new-key" to "new-value"), result.user.others)
assertNotNull(result.user) {
assertEquals(mapOf("key" to "value", "new-key" to "new-value"), it.others)
}
}

@Test
Expand Down Expand Up @@ -169,7 +177,9 @@ class SentryUserProviderEventProcessorTest {
val result = processor.process(event, null)

assertNotNull(result)
assertEquals(user.ipAddress, result.user.ipAddress)
assertNotNull(result.user) {
assertEquals(user.ipAddress, it.ipAddress)
}
}

@Test
Expand All @@ -186,6 +196,8 @@ class SentryUserProviderEventProcessorTest {
val result = processor.process(event, null)

assertNotNull(result)
assertNull(result.user.ipAddress)
assertNotNull(result.user) {
assertNull(it.ipAddress)
}
}
}
4 changes: 2 additions & 2 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ public abstract class io/sentry/SentryBaseEvent {
public fun getTag (Ljava/lang/String;)Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getThrowable ()Ljava/lang/Throwable;
public fun getUser ()Lio/sentry/protocol/User;
public fun removeTag (Ljava/lang/String;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setEventId (Lio/sentry/protocol/SentryId;)V
Expand All @@ -622,6 +623,7 @@ public abstract class io/sentry/SentryBaseEvent {
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTags (Ljava/util/Map;)V
public fun setThrowable (Ljava/lang/Throwable;)V
public fun setUser (Lio/sentry/protocol/User;)V
}

public final class io/sentry/SentryClient : io/sentry/ISentryClient {
Expand Down Expand Up @@ -709,7 +711,6 @@ public final class io/sentry/SentryEvent : io/sentry/SentryBaseEvent, io/sentry/
public fun getTimestamp ()Ljava/util/Date;
public fun getTransaction ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun getUser ()Lio/sentry/protocol/User;
public fun isCrashed ()Z
public fun isErrored ()Z
public fun removeExtra (Ljava/lang/String;)V
Expand All @@ -729,7 +730,6 @@ public final class io/sentry/SentryEvent : io/sentry/SentryBaseEvent, io/sentry/
public fun setServerName (Ljava/lang/String;)V
public fun setThreads (Ljava/util/List;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
}

public final class io/sentry/SentryItemType : java/lang/Enum {
Expand Down
12 changes: 12 additions & 0 deletions sentry/src/main/java/io/sentry/SentryBaseEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.sentry.protocol.Request;
import io.sentry.protocol.SdkVersion;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.User;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -74,6 +75,9 @@ public abstract class SentryBaseEvent {
*/
private @Nullable String platform;

/** Information about the user who triggered this event. */
private @Nullable User user;

/** The captured Throwable */
protected transient @Nullable Throwable throwable;

Expand Down Expand Up @@ -198,4 +202,12 @@ public void setEnvironment(String environment) {
public void setPlatform(final @Nullable String platform) {
this.platform = platform;
}

public @Nullable User getUser() {
return user;
}

public void setUser(final @Nullable User user) {
this.user = user;
}
}
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ private <T extends SentryBaseEvent> T applyScope(
if (sentryBaseEvent.getRequest() == null) {
sentryBaseEvent.setRequest(scope.getRequest());
}
if (sentryBaseEvent.getUser() == null) {
sentryBaseEvent.setUser(scope.getUser());
}
if (sentryBaseEvent.getTags() == null) {
sentryBaseEvent.setTags(new HashMap<>(scope.getTags()));
} else {
Expand Down
Loading

0 comments on commit 8aeee71

Please sign in to comment.