-
Notifications
You must be signed in to change notification settings - Fork 27
Getting Started with Logging in OmniStudio
RFLIB Logging can be used in Salesforce OmniStudio's OmniScript and Integration Procedures. This enables continuous monitoring and troubleshooting of these tools in production environments, 24/7.
Integration Procedures (IP) are the interface between guided experiences and your data. And since data is often at the center of any issues, it is critical to get insights into what is happening within your IPs during production. This is where RFLIB comes in, you can configure Remote Actions to send log messages to the framework. And since RFLIB maintains state within the transaction, anything that happens within the transaction of an IP will be logged. It is highly recommended to treat an IP like code, and log the input parameters, every path, and most importantly any errors.
To create a log message within an IP, follow the steps below:
- Drag the
Remote Action
component into the Integration Procedure structure - Give it a name, i.e. "Log Invocation"
- Set the Remote Class to
rflib_OmniStudioRemoteActions
and the Remote Method toLogMessage
- Add Additional Input:
-
context
: The common name for the log message that makes it easier to filter for in the dashboard. -
level
: The log level such as DEBUG, INFO, WARN, ERROR, or FATAL. -
message
: The actual log message, which can include expressions.
It is recommended to also check the Send Only Additional Input
checkbox.
Using this approach with honor all Logger Settings
configuration values that the framework comes with and set all automatically populated values on the log messages.
When using a TryCatchBlock
in Integration Procedures, you can log the error but not provide any arguments to the logger. Use the LogFailure
method in this case, which will create an ERROR
log message and handle the input provided by OmniStudio properly. The screenshot below shows the proper setup.
Similar to integration procedures, you can log messages from OmniScripts (OS). However, at this time, every configured Remote Action will only log the configured message, not the stack. It is therefore critical to include as much state of the OmniScript as possible in the message to make the single message more meaningful.
To add a log message to your script, follow the steps below:
- Select the "Build" tab.
- Drag the "Remote Action" component into your script layout.
- Give it a name, i.e. "Log Invocation"
- Set the "Invoke Method" to
Fire and Forget
- Set the Remote Class to
rflib_OmniStudioRemoteActions
and the Remote Method toLogMessage
- Add Extra Payload:
-
context
: The common name for the log message, i.e. the name of the OmniScript. -
level
: The log level such as DEBUG, INFO, WARN, ERROR, or FATAL. -
message
: The actual log message, which can include expressions.
It is recommended to also check the Send Only Extra Payload
checkbox.
Application Events can be logged in OmniScript and in Integration Procedures using the Remote Action component. Keep in mind that those are less for investigations, but meant to be used for creating business insights. For example, issue an Application Event at the beginning of an OmniScript and at the end to determine how many times users started the OS but did not finish it. Application Events for errors is also a good option to make it easier to tracking purposes within the Application Event Dashboard.
To send out an Application Event, follow below steps:
- Select the "Build" tab.
- Drag the "Remote Action" component into your script layout.
- Give it a name, i.e. "My OS Start"
- Set the "Invoke Method" to
Fire and Forget
- Set the Remote Class to
rflib_OmniStudioRemoteActions
and the Remote Method toLogApplicationEvent
- Add Extra Payload:
-
context
: The common name for the log message, i.e. the name of the OmniScript. -
level
: The log level such as DEBUG, INFO, WARN, ERROR, or FATAL. -
message
: The actual log message, which can include expressions.
It is recommended to also check the Send Only Extra Payload
checkbox.
The following bullets represent my thoughts on how to use RFLIB in OmniStudio. These are just suggestions and I would love to hear more ideas on how to better use the framework. Here are my thoughts:
- In OmniScripts, add an Application Event for the start and the finish of the script. This applies to sub script representing full processes as well
- In OmniScripts, add an Application Event before any steps displaying error pages
- In OmniScripts, log an ERROR message before any steps displaying error pages
- In Integration Procedures, log inputs specifically when coming from OmniScript at INFO level
- In Integration Procedures, log every condition path using the INFO level
- In Integration Procedures, log the result before returning it to the client
- In Integration Procedures, use try-catch in Integration Procedures and log ERROR messages within the catch block
- In Integration Procedures, use Application Events sparingly. If the IP returns data to an OS, it would be more valuable to log the Application Event on the OS side if needed.