Because KRL rulesets run in the cloud, it can often be difficult to know just how to go about debugging them. Here are a few methods you can use:
Printing Out Values
A time-honored method of debugging code is to print out values at critical points in the program to see if they're correct. KRL doesn't have a "print" statement, but you can use an alert() or notify() action to put values onto a Web page. There are a few hints that will make this easier:
- If you expect a complex value, use the encode() operator to turn the data structure into a string that can be printed.
- You can include multiple actions in a single rule so that the rule does what it's supposed to, as well as notifying you of the data you want to see.
Using the Console Log
For more complex situations, you can use an emit() action to directly write to the browser's console log:
x to the browser's console.
To effectively use this technique, it's critical that you understand the dual execution environment of Web-oriented rulesets.
Using Error Logging
You can use explicit error events to send logging data to a error processing rule. Along with a service like ErrorStack, you can see logged data without using the browser's console. This is especially helpful for rulesets that aren't intended for use in a browser.
Using the Ruleset Logging Information
This information assumes:
- You are using Chrome
- You have the Kynetx Browser Extension installed
- In the
metasection of your ruleset, make sure the logging pragma is "on". Save and deploy your ruleset.
- Click WIndow->Extensions to see the extensions you have installed.
- Check "Developer Mode" in the upper right-hand corner.
- Click the expansion triangle to the left of the KBX entry to expose the details about the KBX. You should see this:
- Click the "background.html" link to see the KBX background page. You should see a page that looks like this after clicking on the "Network" tab:
- Now, run the ruleset. You should see this after clicking on one of the entries:
What you're seeing is the debug trace from the execution engine. Reading this isn't easy, but there's a lot of information in it.
- You should see, for example, clear delineations where each rule executes. Are all the rules you expect to be executing actually running?
- Are values getting set the way you like?
Using the Sky Event Console
The Sky Event Console is a Chrome application that raises events directly to the Sky API.
Once you do, the console looks like this:
You can enter the event domain and type, a token, and any event attributes.
- Clicking on the “Raise Event” button at the bottom raises the event to the specified event engine for the user identified by the token.
- Any rule sets that are salient for the given event are executed and the results are returned and show at the bottom.
- Clicking the “Debug” button shows the debug results.
- The console saves your last inputs from invocation to invocation. You can also easily see the raw response, response headers, request body, and request headers.
To use the Sky API, also need to know how to create tokens for your account. Sky is still early beta, so we haven’t made tokens visible on every account, but they’re there.
- Log into apps.kynetx.com and then click on your email address in the upper right-hand corner. The URL you see is your account profile URL.
- Just add /tokens to it and you’ll see a place to create and manage tokens. Create all you want. Each token represents a private event address for your personal event network.
- Once you’ve created a token, just plug it into the Sky console.