All Superinterfaces:
AutoCloseable

public interface JsonLogConverter extends AutoCloseable
Test utility class which converts JSON in a logger, emitted by the OpenTelemetry logger_otlp exporter, into the more convenient JsonLogConverterImpl.LogResourceScopeSpans and related structures for ease of checking the exported tracing information.

To use this class:

  1. Set up test configuration similar to this:
     telemetry:
       service: "otel-config-example"
       signals:
         tracing:
           processors:
             - type: simple
           exporters:
             - type: logging_otlp
    
    Using processors.type: simple avoids batching of span data so span data becomes accessible more quickly, and using exporters.type: logging_otlp directs the span data to the JUL logger as JSON text.
  2. Invoke the static create() method on this type (ideally in a try-with-resource block).
  3. Execute test code that causes OTel to create one or more spans
  4. Invoke the instance resourceSpans(int) method to wait for and retrieve the expected number of spans.

The OTel io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler class organizes the log data into the JSON structure outlined below. This Javadoc excludes some elements that might appear in the log that this test utility class does not support.

The logging-otlp exporter seems to emit a JSON block--and therefore this class creates a LogResourceScopeSpans instance--for each tracing span.

  • resource (see io.opentelemetry.exporter.internal.otlp.ResourceMarshaler)
    • attributes array (see io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler)

      Various marshalers (some private to KeyValueMarshaler deal with their respective datatypes:

      • stringValue
      • boolValue
      • intValue
      • doubleValue
  • scopeSpans (see io.opentelemetry.exporter.internal.otlp.traces.InstrumentationScopeSpansMarshaler
    • scope
      • name
      • attributes array (see above)
    • spans array (again, some potential items might appear that this class does not currently support)
      • traceId
      • spanId
      • parentSpanId
      • name
      • kind (an integer)
      • startTimeUnixNanos
      • endTimeUnixNanos
      • attributes array (as above)
  • Method Details

    • create

      static JsonLogConverter create()
      Creates an instance of the converter that captures spans reported by OTel.
      Returns:
      new JsonLogConverterImpl instance
    • resourceSpans

      List<JsonLogConverter.LogResourceScopeSpans> resourceSpans(int expectedCount)
      Returns JsonLogConverterImpl.LogResourceScopeSpans instances corresponding to the data emitted by the log exporter.
      Parameters:
      expectedCount - exact number of spans expected from a given test
      Returns:
      info converted from the JSON in the logger