Slow Operations Logging

  • how-to
Tracing information on slow operations can be found in the logs as threshold logging, orphan logging, and other span metrics. Change the settings to alter how much information you collect

To improve debuggability certain metrics are automatically measured and logged. These include slow queries, responses taking beyond a certain threshold, and orphanned responses.

Threshold Logging Reporting

As of v4.7.0 the Threshold Logger is native to the Node.js SDK. In previous versions the underlying C++ core was responsible for threshold logging.

Threshold logging is the recording of slow operations — useful for diagnosing when and where problems occur in a distributed environment.

Configuring Threshold Logging

By default the a threshold log report can be emitted every 10 seconds, but you can customize the emit interval, along with operation thresholds:

const cluster = await couchbase.connect('couchbase://your-ip', {
  username: 'Administrator',
  password: 'password',
  tracingConfig: {
    emitInterval: 5000, // 5 seconds
    sampleSize: 5, // only report the top 5 slow operations per service
    kvThreshold: 2000, // 2 seconds in milliseconds
  }
})

The ThresholdLogger can be configured via TracingConfig as shown above. The following table shows the currently available properties:

Table 1. TracingConfig Properties
Property Default Description

enableTracing

true

If tracing should be enabled.

kvThreshold

500 milliseconds

The key-value operations threshold.

viewsThreshold

1 second

The view query operations threshold.

queryThreshold

1 second

The query operations threshold.

searchThreshold

1 second

The search query operations threshold.

analyticsThreshold

1 second

The analytics query operations threshold.

eventingThreshold

1 second

The eventing operations threshold.

managementThreshold

1 second

The management operations threshold.

sampleSize

10

The top number of operations to report.

emitInterval

10 seconds

The interval at which a threshold report can be emitted.

Note that the Threshold Logger is set as the cluster level Tracer implementation.

JSON Output Format & Logging

You should expect to see output in JSON format in the logs for the services encountering problems:

{
  "<service-a>": {
    "total_count": 1234,
    "top_requests": [{<entry>}, {<entry>},...]
  },
  "<service-b>": {
    "total_count": 1234,
    "top_requests": [{<entry>}, {<entry>},...]
  },
}

The total_count represents the total amount of over-threshold recorded items in each interval per service. The number of entries in “top_requests” is configured by the sampleSize. The service placeholder is replaced with each service — “kv”, “query”, etc. Each entry looks like this, with all fields populated:

{
  "total_duration_us": 1200,
  "encode_duration_us": 100,
  "last_dispatch_duration_us": 40,
  "total_dispatch_duration_us": 40,
  "last_server_duration_us": 2,
  "total_server_duration_us": 2,
  "operation_name": "upsert",
  "last_local_id": "66388CF5BFCF7522/18CC8791579B567C",
  "operation_id": "0x23",
  "last_local_socket": "10.211.55.3:52450",
  "last_remote_socket": "10.112.180.101:11210"
}

If a field is not present (because for example dispatch did not happen), it will not be included.