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

feat: add sentry for error logging and information. #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 14 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ plugins {
id 'java-library'
id 'maven-publish'
id "org.gradle.test-retry" version "1.5.10"
id "io.sentry.jvm.gradle" version "4.11.0"
}

group 'org.torusresearch'
version '4.0.0'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

sentry {
// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
// code as part of your stack traces in Sentry.
includeSourceContext = true

org = "torus"
projectName = "torus-utils-java"
authToken = System.getenv("SENTRY_AUTH_TOKEN")
}

dependencies {
implementation 'org.torusresearch:fetch-node-details-java:5.0.0'
implementation 'org.web3j:core:4.8.8-android'
Expand Down
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
2 changes: 2 additions & 0 deletions src/main/java/org/torusresearch/torusutils/TorusUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.NotNull;
import org.torusresearch.fetchnodedetails.types.TorusNodePub;
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork;
import org.torusresearch.torusutils.analytics.SentryUtils;
import org.torusresearch.torusutils.apis.APIUtils;
import org.torusresearch.torusutils.apis.JsonRPCErrorInfo;
import org.torusresearch.torusutils.apis.requests.GetMetadataParams;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class TorusUtils {

{
setupBouncyCastle();
SentryUtils.init();
}

public TorusUtils(TorusOptions options) throws TorusUtilError {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 platform) {
Sentry.configureScope(scope -> {
scope.setTag("clientId", clientId);
scope.setTag("finalEvmAddress", finalEvmAddress);
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();
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.torusresearch.torusutils.helpers;

import com.google.gson.Gson;

import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.annotations.Nullable;
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork;
import org.torusresearch.torusutils.TorusUtils;
import org.torusresearch.torusutils.analytics.SentryUtils;
import org.torusresearch.torusutils.apis.APIUtils;
import org.torusresearch.torusutils.apis.JsonRPCErrorInfo;
import org.torusresearch.torusutils.apis.JsonRPCResponse;
Expand Down Expand Up @@ -536,6 +537,8 @@ public static TorusKey retrieveOrImportShare(@NotNull String legacyMetadataHost,
isUpgraded = metadataNonce.equals(BigInteger.ZERO);
}

SentryUtils.logInformation(clientId, finalEvmAddress, "torus-utils-java");

return new TorusKey(
new FinalKeyData(finalEvmAddress, finalPubKeyCoords[0], finalPubKeyCoords[1], finalPrivKey),
new OAuthKeyData(oAuthKeyAddress, oAuthPublicKeyCoords[0], oAuthPublicKeyCoords[1], oAuthKey),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.torusresearch.torusutils.helpers;

import org.jetbrains.annotations.NotNull;
import org.torusresearch.torusutils.analytics.SentryUtils;

public class TorusUtilError extends Exception {

Expand All @@ -16,22 +17,23 @@ public class TorusUtilError extends Exception {
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 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;

public TorusUtilError(@NotNull String message) {
super(message);
SentryUtils.captureException(message);
this.message = message;
}

private final String message;
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be unused and can be removed, not so?


public static TorusUtilError RUNTIME_ERROR(@NotNull String msg) {
return new TorusUtilError(msg);
}

@Override
public String toString() {
return message;
Expand Down