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

Added global visibility and Added logic not to send frames and stacktraces if it is empty #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions force-app/main/default/classes/Sentry.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
* @description :
* @author : jmather
* @group :
* @last modified on : 04-28-2021
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-28-2021 Jheel Added a method to send custom title and breadcrumbs to Sentry
* 1.2 04-29-2021 Jheel Added global visibility for the class and required methods
**/
public without sharing class Sentry {
public static void record(Exception e) {
global without sharing class Sentry
{
global static void record(Exception e)
{
Sentry_Event err = convertExceptionToError(e);
sendEvent(err);
}

public static void record(String issueTitle, Exception e, List<Sentry_LogMessage> lExtraMessages)
global static void record(String issueTitle, Exception e, List<Sentry_LogMessage> lExtraMessages)
{
Sentry_Event err = convertExceptionToError(issueTitle, e, lExtraMessages);
sendEvent(err);
Expand Down
6 changes: 4 additions & 2 deletions force-app/main/default/classes/SentryTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
* @description :
* @author : jmather
* @group :
* @last modified on : 04-28-2021
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-28-2021 Jheel Added new methods RecordwithCustomException() and RecordCustomExceptionWithoutSendingToSentry() for test class coverge
* 1.2 04-29-2021 Jheel Added global visibility for the class and required methods
**/
@IsTest
public with sharing class SentryTest {
global with sharing class SentryTest
{
@IsTest
static void Record() {
Exception ex;
Expand Down
19 changes: 14 additions & 5 deletions force-app/main/default/classes/Sentry_ApiMock.cls
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
/**
* Created by jmather on 2019-08-10.
*/

* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
@IsTest
public with sharing class Sentry_ApiMock implements HttpCalloutMock {
public HttpResponse respond(HttpRequest param1) {
global with sharing class Sentry_ApiMock implements HttpCalloutMock
{
global HttpResponse respond(HttpRequest param1)
{
System.debug(param1);
HttpResponse response = new HttpResponse();
response.setStatusCode(200);
Expand Down
19 changes: 14 additions & 5 deletions force-app/main/default/classes/Sentry_Client.cls
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-03-18.
*/

public with sharing class Sentry_Client {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global with sharing class Sentry_Client
{
private static Sentry_Dsn dsn = Sentry_Config.getDsn();

public static void sendEventToSentry(String serializedEvent) {
global static void sendEventToSentry(String serializedEvent)
{
HttpRequest req = new HttpRequest();

// you'll have to register a remote site for this url, but can probably just do a generic https://sentry.io...
Expand Down
36 changes: 25 additions & 11 deletions force-app/main/default/classes/Sentry_Config.cls
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-06-25.
*/

public without sharing class Sentry_Config {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global without sharing class Sentry_Config
{
private static Boolean isInDebugMode = null;
private static Sentry_Active_Config__c activeConfig;
private static Sentry_Config__mdt config;

public static Sentry_Config__mdt getConfig() {
global static Sentry_Config__mdt getConfig()
{
checkDebugging();

if (config == null) {
Expand Down Expand Up @@ -41,7 +50,8 @@ public without sharing class Sentry_Config {
return config;
}

public static String getEnvironmentName() {
global static String getEnvironmentName()
{
Sentry_Active_Config__c ac = getActiveConfig();

if (String.isBlank(ac.Environment_Name__c)) {
Expand All @@ -51,11 +61,13 @@ public without sharing class Sentry_Config {
return ac.Environment_Name__c;
}

public static Sentry_Dsn getDsn() {
global static Sentry_Dsn getDsn()
{
return new Sentry_Dsn(getConfig().DSN__c);
}

public static Boolean checkDebugging() {
global static Boolean checkDebugging()
{
if (isInDebugMode == null) {
Sentry_Active_Config__c ac = getActiveConfig();

Expand All @@ -71,7 +83,8 @@ public without sharing class Sentry_Config {
return isInDebugMode;
}

public static Boolean canSendToSentry() {
global static Boolean canSendToSentry()
{
Sentry_Active_Config__c ac = getActiveConfig();

Sentry_Log.logSentry('[Sentry_config.canSendToSentry] active config: ' + JSON.serializePretty(ac));
Expand All @@ -83,13 +96,14 @@ public without sharing class Sentry_Config {
return ac.IsIssueCreationDisabled__c == false;
}

private static Sentry_Active_Config__c getActiveConfig() {
private static Sentry_Active_Config__c getActiveConfig()
{
if (activeConfig == null) {
activeConfig = Sentry_Active_Config__c.getOrgDefaults();
}

return activeConfig;
}

public class SentryConfigException extends Exception {}
global class SentryConfigException extends Exception {}
}
40 changes: 28 additions & 12 deletions force-app/main/default/classes/Sentry_Context.cls
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-03-25.
*/

public abstract class Sentry_Context {
public static Map<String, Object> create() {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global abstract class Sentry_Context
{
global static Map<String, Object> create()
{
return new Map<String, Object>();
}

public static Map<String, Object> Basic() {
global static Map<String, Object> Basic()
{
return new Map<String, Object>();
}

public static Map<String, Object> Breadcrumbs() {
global static Map<String, Object> Breadcrumbs()
{
Map<String, Object> data = create();
data.put('values', create());
return data;
}

public static Map<String, Object> OsSystem() {
global static Map<String, Object> OsSystem()
{
return new Map<String, Object> {
'os' => Server(),
'runtime' => Runtime(),
'org' => Org()
};
}

public static Map<String, String> Org() {
global static Map<String, String> Org()
{
return new Map<String, String> {
'name' => Sentry_Environment.getInstanceLabel(),
'type' => String.valueOf(Sentry_Environment.getInstanceType())
};
}

public static Map<String, String> Server() {
global static Map<String, String> Server()
{
return new Map<String, String> {
'name' => 'Salesforce',
'version' => '1'
};
}

public static Map<String, String> Runtime() {
global static Map<String, String> Runtime()
{
return new Map<String, String> {
'name' => 'Apex',
'version' => '1'
};
}

public static Map<String, String> User() {
global static Map<String, String> User()
{
return new Map<String, String> {
'id' => UserInfo.getUserId(),
'username' => UserInfo.getUserName(),
Expand Down
31 changes: 20 additions & 11 deletions force-app/main/default/classes/Sentry_Dsn.cls
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-03-25.
*/

public with sharing class Sentry_Dsn {
public String privateKey;
public String publicKey;
public String projectId;
public Url sentryUrl;
public Url url;

public Sentry_Dsn(String dsn) {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global with sharing class Sentry_Dsn
{
global String privateKey;
global String publicKey;
global String projectId;
global Url sentryUrl;
global Url url;

global Sentry_Dsn(String dsn)
{
url = new Url(dsn);
this.publicKey = getPublicKey(url);
this.privateKey = getPrivateKey(url);
Expand Down
26 changes: 18 additions & 8 deletions force-app/main/default/classes/Sentry_Environment.cls
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-06-25.
*/

public without sharing class Sentry_Environment {
public enum InstanceType { PRODUCTION, TRIAL, SANDBOX, SCRATCH_ORG }

public static String getInstanceLabel() {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global without sharing class Sentry_Environment
{
global enum InstanceType { PRODUCTION, TRIAL, SANDBOX, SCRATCH_ORG }

global static String getInstanceLabel()
{
String orgUrl = Url.getOrgDomainUrl().toExternalForm();
Sentry_Log.logSentry('[Sentry_Environment.getInstanceLabel] orgUrl: ' + orgUrl);
List<String> protoAndRemainder = orgUrl.split('://');
Expand All @@ -27,7 +36,8 @@ public without sharing class Sentry_Environment {
return url_fragment.split('--')[0].toLowerCase();
}

public static InstanceType getInstanceType() {
global static InstanceType getInstanceType()
{
Organization org = [SELECT InstanceName, IsSandbox, TrialExpirationDate FROM Organization];

if (org.IsSandbox == true && org.TrialExpirationDate == null) {
Expand Down
22 changes: 16 additions & 6 deletions force-app/main/default/classes/Sentry_Error_Handler.cls
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/**
* Created by Jacob Mather <[email protected]> on 2019-06-25.
*/

public with sharing class Sentry_Error_Handler {
public void run() {
* @description :
* @author : jmather
* @group :
* @last modified on : 04-29-2021
* @last modified by : Jheel
* Modifications Log
* Ver Date Author Modification
* 1.0 08-10-2019 jmather Initial Version
* 1.1 04-29-2021 Jheel Added global visibility for the class and required methods
**/
global with sharing class Sentry_Error_Handler
{
global void run()
{
List<String> errors = new List<String>();

for (Sentry_Error__e e : (List<Sentry_Error__e>) Trigger.new) {
Expand All @@ -29,7 +38,8 @@ public with sharing class Sentry_Error_Handler {
}

@Future(Callout=true)
public static void sendErrors(List<String> errors) {
global static void sendErrors(List<String> errors)
{
for (String error : errors) {
Sentry_Client.sendEventToSentry(error);
}
Expand Down
Loading