Skip to end of metadata
Go to start of metadata

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. 
  • A notify() is often more convenient than an alert() because it doesn't interrupt the execution of the Javascript program. 
  • 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:

The preceding would write the value of the JavaScript variable 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
You can see detailed logging information from the execution engine by following these steps:
  1. In the meta section of your ruleset, make sure the logging pragma is "on". Save and deploy your ruleset. 
  2. Click WIndow->Extensions to see the extensions you have installed. 
  3. Check "Developer Mode" in the upper right-hand corner. 
  4. Click the expansion triangle to the left of the KBX entry to expose the details about the KBX. You should see this:
  5. 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:
  6. 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? 
  • At the bottom is the actual JavaScript output. Do variables in the JavaScript have the values that you expect?

Using the Sky Event Console

The Sky Event Console is a Chrome application that raises events directly to the Sky API

You can download the source code for the Sky Event Console from github.com. You install it as an unpacked extension from the source from the Extensions page in Chrome. 

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.

  1. 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.
  2. 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.
  3. Once you’ve created a token, just plug it into the Sky console.

 

Labels: