Configuring your logging deployment

Enabling multi-line exception detection

Enables multi-line error detection of container logs.

Enabling this feature could have performance implications and may require additional computing resources or alternate logging solutions.

Log parsers often incorrectly identify separate lines of the same exception as separate exceptions. This leads to extra log entries and an incomplete or inaccurate view of the traced information.

Example java exception

  1. java.lang.NullPointerException: Cannot invoke "String.toString()" because "<param1>" is null
  2. at testjava.Main.handle(Main.java:47)
  3. at testjava.Main.printMe(Main.java:19)
  4. at testjava.Main.main(Main.java:10)
  • To enable logging to detect multi-line exceptions and reassemble them into a single log entry, ensure that the ClusterLogForwarder Custom Resource (CR) contains a detectMultilineErrors field, with a value of true.

Example ClusterLogForwarder CR

  1. apiVersion: logging.openshift.io/v1
  2. kind: ClusterLogForwarder
  3. metadata:
  4. name: instance
  5. namespace: openshift-logging
  6. spec:
  7. pipelines:
  8. - name: my-app-logs
  9. inputRefs:
  10. - application
  11. outputRefs:
  12. - default
  13. detectMultilineErrors: true

Details

When log messages appear as a consecutive sequence forming an exception stack trace, they are combined into a single, unified log record. The first log message’s content is replaced with the concatenated content of all the message fields in the sequence.

Table 1. Supported languages per collector:
LanguageFluentdVector

Java

JS

Ruby

Python

Golang

PHP

Dart

Troubleshooting

When enabled, the collector configuration will include a new section with type: detect_exceptions

Example vector configuration section

  1. [transforms.detect_exceptions_app-logs]
  2. type = "detect_exceptions"
  3. inputs = ["application"]
  4. languages = ["All"]
  5. group_by = ["kubernetes.namespace_name","kubernetes.pod_name","kubernetes.container_name"]
  6. expire_after_ms = 2000
  7. multiline_flush_interval_ms = 1000

Example fluentd config section

  1. <label @MULTILINE_APP_LOGS>
  2. <match kubernetes.**>
  3. @type detect_exceptions
  4. remove_tag_prefix 'kubernetes'
  5. message message
  6. force_line_breaks true
  7. multiline_flush_interval .2
  8. </match>
  9. </label>