Skip to content

Protocol Debugging

bchavez edited this page Jun 10, 2019 · 18 revisions

.NET Framework / Mono Logging

Debugging the JSON protocol can be useful when debugging driver issues. This driver uses Common.Logging for the logging infrastructure. To enable driver protocol log tracing add the following to your App.config (or Web.config):

  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
        <arg key="level" value="TRACE" />
        <arg key="showLogName" value="false" />
        <arg key="showDateTime" value="false" />
      </factoryAdapter>
    </logging>
  </common>

Common.Logging allows customization of the log level and permits the use of different log adapters for popular logging libraries like NLog or log4net.

Log Levels
  • TRACE - Logs the AST JSON sent to the server and the JSON response.

.NET Core Logging

.NET Core logging is handled by Microsoft.Extensions.Logging.

Use the RethinkDB EnableRethinkDbLogging() extension method on an instance of ILoggerFactory to enable logging in startup code as shown in the example below:

var loggerFactory = new LoggerFactory(); //optional
loggerFactory.AddConsole(LogLevel.Debug);
loggerFactory.EnableRethinkDbLogging();
Log Levels
  • DEBUG - Logs the AST JSON sent to the server and the JSON response.

Query Debugging

If you're concerned the C# driver is sending an invalid AST query, you can compare C# AST query sent to the server with the official JavaScript driver in the RethinkDB web admin console.

There're two ways to find the JSON AST from the web admin console:

Option A: Using r.expr and .build

Thanks to @neumino the following will output the AST in the web admin console:

r.expr(
  r.Table("foo").map(function(x) { return x.merge({foo: "bar"})}).build()
  // Or <your_query>.build()
)
Option B: Using Chrome Developer Console
  1. Browse to the RethinkDb web admin console.
  2. Select the RethinkDB Data Explorer.
  3. Open up the Chrome developer console.
  4. Select the Sources tab, and press F8 to pause script execution.
  5. After the script pauses, check your breakpoint is inside cluster-min.js.
  • If your breakpoint is in another file, press F10 and skip over function calls until you're inside cluster-min.js.
  1. Once inside clsuter-min.js type the following in the JavaScript console: n.timers. You'll get output similar to:
    • Object {1: Object, 2: Object}
  2. Next, disable the timers by typing:
    • driver.stop_timer(1) (or n.stop_timer(1) in 2.3.6+)
    • driver.stop_timer(2) (or n.stop_timer(2) in 2.3.6+)
  3. Press F8 to resume script execution.
  4. Select the Network tab, and clear the requests.
  5. Now finally, type your query in the Data Explorer and press Run.
  6. Your query's AST is in the HTTP request payload for network traffic named ?conn_id=hash. For example, running r.now() translates to:
    • [1,[103,[]], {global args}]

Using the debugging technique above, you can compare the C# driver's AST output with the JavaScript AST to help you locate any AST discrepancies.

Clone this wiki locally