Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Request to the Scope. #1270

Merged
merged 4 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Fix: Make the ANR Atomic flags immutable
* Enchancement: Integration interface better compatibility with Kotlin null-safety
* Enchancement: Simplify Sentry configuration in Spring integration (#1259)
* Enchancement: Add Request to the Scope. #1270

Breaking Changes:
* Enchancement: SentryExceptionResolver should not send handled errors by default (#1248).
Expand Down
22 changes: 22 additions & 0 deletions sentry/src/main/java/io/sentry/Scope.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry;

import io.sentry.protocol.Contexts;
import io.sentry.protocol.Request;
import io.sentry.protocol.User;
import io.sentry.util.Objects;
import java.util.ArrayList;
Expand Down Expand Up @@ -29,6 +30,9 @@ public final class Scope implements Cloneable {
/** Scope's user */
private @Nullable User user;

/** Scope's request */
private @Nullable Request request;
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved

/** Scope's fingerprint */
private @NotNull List<String> fingerprint = new ArrayList<>();

Expand Down Expand Up @@ -163,6 +167,24 @@ public void setUser(final @Nullable User user) {
}
}

/**
* Returns the Scope's request
*
* @return the request
*/
public @Nullable Request getRequest() {
return request;
}

/**
* Sets the Scope's request
*
* @param request the request
*/
public void setRequest(final @Nullable Request request) {
this.request = request;
}

/**
* Returns the Scope's fingerprint list
*
Expand Down
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 @@ -421,6 +421,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
if (event.getUser() == null) {
event.setUser(scope.getUser());
}
if (event.getRequest() == null) {
event.setRequest(scope.getRequest());
}
if (event.getFingerprints() == null) {
event.setFingerprints(scope.getFingerprint());
}
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ class SentryClientTest {
assertEquals("fp", event.fingerprints[0])
assertEquals("id", event.user.id)
assertEquals(SentryLevel.FATAL, event.level)
assertNotNull(event.request) {
assertEquals("post", it.method)
}
}

@Test
Expand Down Expand Up @@ -855,6 +858,9 @@ class SentryClientTest {
user = User().apply {
id = "id"
}
request = Request().apply {
method = "post"
}
}
}

Expand Down