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.

First, read Tips for Developers

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 when working with the Web.  If you're not working with Web events, you can use a send_directive() to output results. 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 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 see debug results, you will have to do the following:
  • Use kibdev.kobj.net as the Kynetx event engine rather than cs.kobj.net
  • Set logging to "on" in the meta section of your ruleset. 

 

Debug results are only returned for Web events that create Javascript since JSON cannot have comments.

 

To use the Sky API, also need to know how to create tokens for your account.

  1. You can use the Kynetx Developer Kit (KDK) app in SquareTag to create ECIs.
  2. Once you’ve created a token, just plug it into the Sky console.

Using the Ruleset Logging Information

The Kynetx Browser Extension is no longer available. This section is defunct.

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?
Labels: