Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.
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
5 changes: 4 additions & 1 deletion .forceignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ package.xml
**/.eslintrc.json

# LWC Jest
**/__tests__/**
**/__tests__/**
**/tsconfig.json

**/*.ts
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"salesforcedx-vscode-core.show-cli-success-msg": false
}
12 changes: 12 additions & 0 deletions force-app/main/default/classes/TritonDmlDemoController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
@description LWC Apex Api Class for use to demo Triton
*/
public with sharing class TritonDmlDemoController {

public class TritonDmlDemoControllerException extends Exception {}

@AuraEnabled
public static String triggerDmlException() {
throw new TritonDmlDemoControllerException('Error Msg');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
63 changes: 34 additions & 29 deletions force-app/main/default/classes/TritonLwc.cls
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,44 @@ public with sharing class TritonLwc {
/**
* Create component logs from LWC
* Use this method to persist logs generated from LWC components
* @param componentLogs -- a collection of ComponentLog objects
* @param componentLogs -- a collection of ComponentLog objects serialized
*/
@AuraEnabled
public static void saveComponentLogs(List<ComponentLog> componentLogs) {
public static void saveComponentLogs(String pComponentLogs) {
System.debug('pComponentLogs: ' + pComponentLogs);
List<TritonLwc.ComponentLog> componentLogs = (List<TritonLwc.ComponentLog>)JSON.deserialize(
pComponentLogs,
List<TritonLwc.ComponentLog>.class
);
Triton logInstance = Triton.instance;
for (ComponentLog componentLog : componentLogs) {
for (TritonLwc.ComponentLog componentLog : componentLogs) {
logInstance.add(
Triton.makeBuilder()
//category will be fetched from the componentLog
.category(String.isNotBlank(componentLog.category) ? componentLog.category : componentLog.component.category)
//type will be fetched from the componentLog directly, of from the error. If neither are set, Frontend will be used
.type(String.isNotBlank(componentLog.type) ? componentLog.type :
componentLog.error != null ? componentLog.error.type : TritonTypes.Type.Frontend.name())
//area will be fetched from the componentLog directly if set. Otherwise component name will be used
.area(String.isNotBlank(componentLog.area) ? componentLog.area : componentLog.component.name)
//summary will be fetched from the componentLog directly if set. Otherwise, error message will be used if provided.
.summary(String.isNotBlank(componentLog.summary) ? componentLog.summary :
componentLog.error != null ? componentLog.error.message : null)
.stackTrace(componentLog.stack)
.details(componentLog.details)
//transaction id will be used from the componentLog, or a new transaction id will be generated
.transactionId(String.isNotBlank(componentLog.transactionId) ? componentLog.transactionId : logInstance.TRANSACTION_ID)
.attribute(Triton.USER_ID, componentLog.userId)
//apex name will be set to component.function or component.action
.attribute(Triton.APEX_NAME, componentLog.component.name + '.' +
(String.isNotBlank(componentLog.component.function) ? componentLog.component.function : componentLog.component.action))
.attribute(Triton.RELATED_ID, componentLog.recordId)
//created timestamp will be either set from the componentLog if provided, otherwise current timestamp will be used
.attribute(Triton.CREATED_TIMESTAMP, componentLog.createdTimestamp != null ? Double.valueOf(componentLog.createdTimestamp) : Double.valueOf(System.now().getTime()))
//log level will be taken from the componentLog if provided, otherwise INFO will be used
.attribute(Triton.LOG_LEVEL, String.isNotBlank(componentLog.level) ? componentLog.level : TritonTypes.Level.INFO.name())
.attribute(Triton.DURATION, componentLog.duration)
.build());
Triton.makeBuilder()
//category will be fetched from the componentLog
.category(String.isNotBlank(componentLog.category) ? componentLog.category : componentLog.component.category)
//type will be fetched from the componentLog directly, of from the error. If neither are set, Frontend will be used
.type(String.isNotBlank(componentLog.type) ? componentLog.type :
componentLog.error != null ? componentLog.error.type : TritonTypes.Type.Frontend.name())
//area will be fetched from the componentLog directly if set. Otherwise component name will be used
.area(String.isNotBlank(componentLog.area) ? componentLog.area : componentLog.component.name)
//summary will be fetched from the componentLog directly if set. Otherwise, error message will be used if provided.
.summary(String.isNotBlank(componentLog.summary) ? componentLog.summary :
componentLog.error != null ? componentLog.error.message : null)
.stackTrace(componentLog.stack)
.details(componentLog.details)
//transaction id will be used from the componentLog, or a new transaction id will be generated
.transactionId(String.isNotBlank(componentLog.transactionId) ? componentLog.transactionId : logInstance.TRANSACTION_ID)
.attribute(Triton.USER_ID, componentLog.userId)
//apex name will be set to component.function or component.action
.attribute(Triton.APEX_NAME, componentLog.component.name + '.' +
(String.isNotBlank(componentLog.component.function) ? componentLog.component.function : componentLog.component.action))
.attribute(Triton.RELATED_ID, componentLog.recordId)
//created timestamp will be either set from the componentLog if provided, otherwise current timestamp will be used
.attribute(Triton.CREATED_TIMESTAMP, componentLog.createdTimestamp != null ? Double.valueOf(componentLog.createdTimestamp) : Double.valueOf(System.now().getTime()))
//log level will be taken from the componentLog if provided, otherwise INFO will be used
.attribute(Triton.LOG_LEVEL, String.isNotBlank(componentLog.level) ? componentLog.level : TritonTypes.Level.INFO.name())
.attribute(Triton.DURATION, componentLog.duration)
.build());
}
logInstance.flush();
}
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/classes/TritonTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private class TritonTest {
component.function = 'test function';
componentLog.component = component;
componentLogs.add(componentLog);
TritonLwc.saveComponentLogs(componentLogs);
TritonLwc.saveComponentLogs(JSON.serialize(componentLogs));
Test.stopTest();

List<pharos__Log__c> logs = [SELECT Id, pharos__Summary__c, pharos__Hash__c FROM pharos__Log__c];
Expand Down
Loading