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

Cleanup thread local context in ThreadLocalContextManager after e… #422

Merged
merged 3 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 1.1.1

- Allow overriding the location of the properties file.
- Add support for handling and uploading Proguard files to Sentry (for Android applications).
- Cleanup thread local context in ``ThreadLocalContextManager`` after each servlet request finishes.
- Change the ``EventBuilder`` hostname lookup code to only run one thread at a time.

Version 1.1.0
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static void setUser(User user) {
* Clears the current context.
*/
public static void clearContext() {
getStoredClient().getContext().clear();
getStoredClient().clearContext();
}

/**
Expand Down
7 changes: 7 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ public void closeConnection() {
}
}

/**
* Clears the {@link ContextManager} data.
*/
public void clearContext() {
contextManager.clear();
}

public Context getContext() {
return contextManager.getContext();
}
Expand Down
5 changes: 5 additions & 0 deletions sentry/src/main/java/io/sentry/context/ContextManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public interface ContextManager {
*/
Context getContext();

/**
* Clear the underlying context data.
*/
void clear();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class SingletonContextManager implements ContextManager {
public Context getContext() {
return context;
}

@Override
public void clear() {
context.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public Context getContext() {
return context.get();
}

@Override
public void clear() {
context.remove();
Copy link
Author

@bretthoerner bretthoerner Jun 20, 2017

Choose a reason for hiding this comment

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

This it the critical difference. The rest is dealing with abstractions/naming.

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
try {
SentryClient sentryClient = Sentry.getStoredClient();
if (sentryClient != null) {
sentryClient.getContext().clear();
sentryClient.clearContext();
}
} catch (Exception e) {
logger.error("Error clearing Context state.", e);
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/SentryClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SentryClientTest extends BaseTest {

@BeforeMethod
public void setup() {
contextManager.getContext().clear();
contextManager.clear();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/SentryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SentryTest extends BaseTest {

@BeforeMethod
public void setup() {
contextManager.getContext().clear();
contextManager.clear();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/event/BreadcrumbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BreadcrumbTest extends BaseTest {

@BeforeMethod
public void setup() {
contextManager.getContext().clear();
contextManager.clear();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/event/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UserTest extends BaseTest {

@BeforeMethod
public void setup() {
contextManager.getContext().clear();
contextManager.clear();
}

@Test
Expand Down