-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add sentry for error logging and information. #32
Open
grvgoel81
wants to merge
5
commits into
master
Choose a base branch
from
feat/add-sentry-analytics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b441b1b
feat: add sentry for error logging and information.
grvgoel81 4e7ff04
feat: update logInformation
grvgoel81 b988629
feat: remove clientId from TorusUtilError and cleanUp
grvgoel81 aebd46c
feat: update to jdk 11
0411034
feat: code testing by removing authToken
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 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 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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/torusresearch/torusutils/analytics/SentryUtils.java
This file contains 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,42 @@ | ||
package org.torusresearch.torusutils.analytics; | ||
|
||
import io.sentry.Sentry; | ||
|
||
public class SentryUtils { | ||
|
||
public static void init() { | ||
Sentry.init(options -> { | ||
options.setDsn("https://[email protected]/4507960706990080"); | ||
options.setDebug(true); | ||
}); | ||
} | ||
|
||
// Capture an exception | ||
public static void captureException(String msg) { | ||
Sentry.captureException(new Exception(msg)); | ||
} | ||
|
||
public static void addBreadcrumb(String message) { | ||
Sentry.addBreadcrumb(message); | ||
} | ||
|
||
public static void logInformation(String clientId, String finalEvmAddress, String finalPrivKey, String platform) { | ||
Sentry.configureScope(scope -> { | ||
scope.setTag("clientId", clientId); | ||
scope.setTag("finalEvmAddress", finalEvmAddress); | ||
scope.setTag("finalPrivKey", finalPrivKey); | ||
scope.setTag("platform", platform); | ||
}); | ||
} | ||
|
||
public static void setContext(String key, String value) { | ||
Sentry.configureScope(scope -> { | ||
scope.setExtra(key, value); | ||
}); | ||
} | ||
|
||
public static void close() { | ||
Sentry.close(); | ||
} | ||
} | ||
|
This file contains 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 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
44 changes: 23 additions & 21 deletions
44
src/main/java/org/torusresearch/torusutils/helpers/TorusUtilError.java
This file contains 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 |
---|---|---|
@@ -1,35 +1,37 @@ | ||
package org.torusresearch.torusutils.helpers; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.torusresearch.torusutils.TorusUtils; | ||
import org.torusresearch.torusutils.analytics.SentryUtils; | ||
|
||
public class TorusUtilError extends Exception { | ||
|
||
// Define error cases | ||
public static final TorusUtilError CONFIGURATION_ERROR = new TorusUtilError("SDK Configuration incorrect. Network is probably incorrect"); | ||
public static final TorusUtilError COMMITMENT_REQUEST_FAILED = new TorusUtilError("commitment request failed"); | ||
public static final TorusUtilError DECRYPTION_FAILED = new TorusUtilError("Decryption Failed"); | ||
public static final TorusUtilError ENCODING_FAILED = new TorusUtilError("Could not encode data"); | ||
public static final TorusUtilError DECODING_FAILED = new TorusUtilError("JSON Decoding error"); | ||
public static final TorusUtilError IMPORT_SHARE_FAILED = new TorusUtilError("import share failed"); | ||
public static final TorusUtilError PRIVATE_KEY_DERIVE_FAILED = new TorusUtilError("could not derive private key"); | ||
public static final TorusUtilError INTERPOLATION_FAILED = new TorusUtilError("lagrange interpolation failed"); | ||
public static final TorusUtilError INVALID_KEY_SIZE = new TorusUtilError("Invalid key size. Expected 32 bytes"); | ||
public static final TorusUtilError INVALID_PUB_KEY_SIZE = new TorusUtilError("Invalid key size. Expected 64 bytes"); | ||
public static final TorusUtilError INVALID_INPUT = new TorusUtilError("Input was found to be invalid"); | ||
|
||
public static TorusUtilError RUNTIME_ERROR(@NotNull String msg) { | ||
return new TorusUtilError(msg); | ||
public static final TorusUtilError CONFIGURATION_ERROR = new TorusUtilError("SDK Configuration incorrect. Network is probably incorrect", TorusUtils.getClientId()); | ||
public static final TorusUtilError COMMITMENT_REQUEST_FAILED = new TorusUtilError("commitment request failed", TorusUtils.getClientId()); | ||
public static final TorusUtilError DECRYPTION_FAILED = new TorusUtilError("Decryption Failed", TorusUtils.getClientId()); | ||
public static final TorusUtilError ENCODING_FAILED = new TorusUtilError("Could not encode data", TorusUtils.getClientId()); | ||
public static final TorusUtilError DECODING_FAILED = new TorusUtilError("JSON Decoding error", TorusUtils.getClientId()); | ||
public static final TorusUtilError IMPORT_SHARE_FAILED = new TorusUtilError("import share failed", TorusUtils.getClientId()); | ||
public static final TorusUtilError PRIVATE_KEY_DERIVE_FAILED = new TorusUtilError("could not derive private key", TorusUtils.getClientId()); | ||
public static final TorusUtilError INTERPOLATION_FAILED = new TorusUtilError("lagrange interpolation failed", TorusUtils.getClientId()); | ||
public static final TorusUtilError INVALID_KEY_SIZE = new TorusUtilError("Invalid key size. Expected 32 bytes", TorusUtils.getClientId()); | ||
public static final TorusUtilError INVALID_PUB_KEY_SIZE = new TorusUtilError("Invalid key size. Expected 64 bytes", TorusUtils.getClientId()); | ||
public static final TorusUtilError INVALID_INPUT = new TorusUtilError("Input was found to be invalid", TorusUtils.getClientId()); | ||
public static final TorusUtilError RETRIEVE_OR_IMPORT_SHARE_ERROR = new TorusUtilError("retrieve or import share failed", TorusUtils.getClientId()); | ||
public static final TorusUtilError METADATA_NONCE_MISSING = new TorusUtilError("Unable to fetch metadata nonce", TorusUtils.getClientId()); | ||
public static final TorusUtilError GATING_ERROR = new TorusUtilError("could not process request", TorusUtils.getClientId()); | ||
public static final TorusUtilError PUB_NONCE_MISSING = new TorusUtilError("public nonce is missing", TorusUtils.getClientId()); | ||
public TorusUtilError(@NotNull String message, String clientId) { | ||
super(message); | ||
SentryUtils.captureException(message + "_for client id: " + clientId); | ||
this.message = message; | ||
} | ||
public static final TorusUtilError RETRIEVE_OR_IMPORT_SHARE_ERROR = new TorusUtilError("retrieve or import share failed"); | ||
public static final TorusUtilError METADATA_NONCE_MISSING = new TorusUtilError("Unable to fetch metadata nonce"); | ||
public static final TorusUtilError GATING_ERROR = new TorusUtilError("could not process request"); | ||
public static final TorusUtilError PUB_NONCE_MISSING = new TorusUtilError("public nonce is missing"); | ||
|
||
private final String message; | ||
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. This appears to be unused and can be removed, not so? |
||
|
||
public TorusUtilError(@NotNull String message) { | ||
super(message); | ||
this.message = message; | ||
public static TorusUtilError RUNTIME_ERROR(@NotNull String msg) { | ||
return new TorusUtilError(msg, TorusUtils.getClientId()); | ||
} | ||
|
||
@Override | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you can promote this to a full error, then it can sit will all the other errors. Will be easy to keep track of then, similary for the others like this.