Skip to content

Commit dc057c1

Browse files
authored
Callable Logger updates (#835)
* Fixed internally reported issue with tags not being passed as a List<String> but as a List<Object> from OmniStudio * Closed #814 by adding tryCatch callable method for OmniStudio * Updated CallableLogger to add some explanatory comments for the OmniStudio-specific code
1 parent c8e2502 commit dc057c1

7 files changed

Lines changed: 51 additions & 24 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.
77

8-
## Unlocked Package - v4.15.5
8+
## Unlocked Package - v4.15.6
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015p5jQAA)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015p5jQAA)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pEdQAI)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pEdQAI)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://github.com/jongpie/NebulaLogger/wiki)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015p5jQAA`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015pEdQAI`
1515

1616
---
1717

nebula-logger/core/main/logger-engine/classes/CallableLogger.cls

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ global without sharing class CallableLogger implements System.Callable {
7272
@SuppressWarnings('PMD.ApexDoc, PMD.StdCyclomaticComplexity')
7373
private class CallableHandler {
7474
public void handleCall(String action, Map<String, Object> input, Map<String, Object> output) {
75+
if (action == 'tryCatch') {
76+
action = 'newEntry';
77+
input.put(ARGUMENT_MESSAGE, 'An unexpected error occurred:\n' + System.JSON.serializePretty(input));
78+
input.put(ARGUMENT_LOGGING_LEVEL, System.LoggingLevel.ERROR.name());
79+
}
7580
switch on action {
7681
// Methods for transaction IDs / parent transaction IDs
7782
when 'getTransactionId' {
@@ -148,7 +153,10 @@ global without sharing class CallableLogger implements System.Callable {
148153
logEntryEventBuilder.setRecord((Map<Id, SObject>) input.get(ARGUMENT_RECORD_MAP));
149154
}
150155
if (input.containsKey(ARGUMENT_TAGS)) {
151-
logEntryEventBuilder.addTags((List<String>) input.get(ARGUMENT_TAGS));
156+
List<Object> tags = (List<Object>) input.get(ARGUMENT_TAGS);
157+
for (Object tag : tags) {
158+
logEntryEventBuilder.addTag(tag?.toString());
159+
}
152160
}
153161
if (CallableLogger.isOmniStudioInput(input)) {
154162
LogEntryEvent__e logEntryEvent = logEntryEventBuilder.getLogEntryEvent();
@@ -172,20 +180,10 @@ global without sharing class CallableLogger implements System.Callable {
172180
}
173181

174182
private static String getFormattedMessage(Map<String, Object> originalInput) {
175-
String message = (String) originalInput.get(ARGUMENT_MESSAGE);
183+
String message = (String) originalInput.get(ARGUMENT_MESSAGE) ?? '';
176184

177185
if (CallableLogger.isOmniStudioInput(originalInput)) {
178-
Map<String, Object> cleanedInput = new Map<String, Object>();
179-
for (String inputName : originalInput.keySet()) {
180-
Object inputValue = originalInput.get(inputName);
181-
if (inputValue instanceof Map<String, Object>) {
182-
cleanedInput.put(inputName, inputValue);
183-
}
184-
}
185-
186-
if (cleanedInput.keySet().isEmpty() == false) {
187-
message += '\n\nOmniStudio Input:\n' + System.JSON.serializePretty(cleanedInput);
188-
}
186+
message += addOmniStudioSpecificFormatting(originalInput);
189187
}
190188

191189
return message;
@@ -194,4 +192,19 @@ global without sharing class CallableLogger implements System.Callable {
194192
private static Boolean isOmniStudioInput(Map<String, Object> input) {
195193
return input.containsKey(OMNISTUDIO_ARGUMENT_INPUT_OMNI_PROCESS_ID) || Logger.getCurrentQuiddity() == System.Quiddity.REMOTE_ACTION;
196194
}
195+
196+
private static String addOmniStudioSpecificFormatting(Map<String, Object> originalInput) {
197+
// "Remote Actions of Omniscripts and Integration Procedures can invoke any class that implements Callable"
198+
// within both of those, OmniStudio developers can declaratively add "Additional Inputs", which themselves
199+
// are a key/value pairing
200+
Map<String, Object> cleanedOmniStudioInputs = new Map<String, Object>();
201+
for (String inputName : originalInput.keySet()) {
202+
Object inputValue = originalInput.get(inputName);
203+
if (inputValue instanceof Map<String, Object>) {
204+
cleanedOmniStudioInputs.put(inputName, inputValue);
205+
}
206+
}
207+
// if we've added any of the so-called Additional Inputs, help to differentiate them within the larger message
208+
return cleanedOmniStudioInputs.isEmpty() == false ? '\n\nOmniStudio Input:\n' + System.JSON.serializePretty(cleanedOmniStudioInputs) : '';
209+
}
197210
}

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.15.5';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.15.6';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';

nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
1010
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
1111
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';
1212

13-
const CURRENT_VERSION_NUMBER = 'v4.15.5';
13+
const CURRENT_VERSION_NUMBER = 'v4.15.6';
1414

1515
const CONSOLE_OUTPUT_CONFIG = {
1616
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,

nebula-logger/core/tests/logger-engine/classes/CallableLogger_Tests.cls

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ private class CallableLogger_Tests {
500500
static void it_adds_new_entry_with_tags_when_using_standard_approach() {
501501
System.LoggingLevel loggingLevel = System.LoggingLevel.FINE;
502502
String message = 'some log entry message';
503-
List<String> tags = new List<String>{ 'some-tag', 'another-tag' };
503+
List<Object> tags = new List<Object>{ 'some-tag', 'another-tag', 1 };
504504

505505
System.Callable callableLoggerInstance = (System.Callable) System.Type.forName('CallableLogger').newInstance();
506506
Map<String, Object> returnedOutput = (Map<String, Object>) callableLoggerInstance
@@ -623,4 +623,17 @@ private class CallableLogger_Tests {
623623
System.Assert.areEqual(0, Logger.getBufferSize());
624624
System.Assert.areEqual(targetSaveMethodName, Logger.lastSaveMethodNameUsed);
625625
}
626+
627+
@IsTest
628+
static void it_logs_try_catch_when_passed_as_action() {
629+
System.Callable callableLoggerInstance = (System.Callable) System.Type.forName('CallableLogger').newInstance();
630+
Map<String, Object> input = new Map<String, Object>{ 'argument_1' => 'first arg', 'argument_2' => 'second arg' };
631+
632+
Map<String, Object> returnedOutput = (Map<String, Object>) callableLoggerInstance.call('tryCatch', input.clone());
633+
634+
System.Assert.areEqual(true, returnedOutput.get('isSuccess'), 'Expected isSuccess == true. Output received: ' + returnedOutput);
635+
LogEntryEvent__e logEntryEvent = ((LogEntryEventBuilder) returnedOutput.get('logEntryEventBuilder')).getLogEntryEvent();
636+
System.Assert.areEqual('An unexpected error occurred:\n' + System.JSON.serializePretty(input), logEntryEvent.Message__c);
637+
System.Assert.areEqual(System.LoggingLevel.ERROR.name(), logEntryEvent.LoggingLevel__c);
638+
}
626639
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nebula-logger",
3-
"version": "4.15.5",
3+
"version": "4.15.6",
44
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
55
"author": "Jonathan Gillespie",
66
"license": "MIT",

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"path": "./nebula-logger/core",
1010
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
1111
"scopeProfiles": true,
12-
"versionNumber": "4.15.5.NEXT",
13-
"versionName": "Bugfix for AuthSession with null LoginHistory exception message handling",
14-
"versionDescription": "Added safe navigation operator on LoginHistory from authSession records to avoid a NullPointerException",
12+
"versionNumber": "4.15.6.NEXT",
13+
"versionName": "Adds tryCatch CallableLogger method",
14+
"versionDescription": "tryCatch CallableLogger method for OmniStudio and other decoupled logging usages",
1515
"postInstallUrl": "https://github.com/jongpie/NebulaLogger/wiki",
1616
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
1717
"unpackagedMetadata": {
@@ -210,6 +210,7 @@
210210
"Nebula Logger - Core@4.15.3-improved-testability-of-queries": "04t5Y0000015ok2QAA",
211211
"Nebula Logger - Core@4.15.4-flowlogger-exception-message-handling": "04t5Y0000015oklQAA",
212212
"Nebula Logger - Core@4.15.5-bugfix-for-authsession-with-null-loginhistory-exception-message-handling": "04t5Y0000015p5jQAA",
213+
"Nebula Logger - Core@4.15.6-adds-trycatch-callablelogger-method": "04t5Y0000015pEdQAI",
213214
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
214215
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
215216
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",

0 commit comments

Comments
 (0)