Interface JsonLogConverter
- All Superinterfaces:
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:
- Set up test configuration similar to this:
telemetry: service: "otel-config-example" signals: tracing: processors: - type: simple exporters: - type: logging_otlp
processors.type: simple
avoids batching of span data so span data becomes accessible more quickly, and usingexporters.type: logging_otlp
directs the span data to the JUL logger as JSON text. - Invoke the static
create()
method on this type (ideally in a try-with-resource block). - Execute test code that causes OTel to create one or more spans
- 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
(seeio.opentelemetry.exporter.internal.otlp.ResourceMarshaler
)attributes
array (seeio.opentelemetry.exporter.internal.otlp.KeyValueMarshaler
)Various marshalers (some private to
KeyValueMarshaler
deal with their respective datatypes:stringValue
boolValue
intValue
doubleValue
scopeSpans
(seeio.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)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Top-level resource data for emitted span data.static interface
Top-level aggregation of resource and scope-spans information.static interface
Information about a "log scope" in the emitted span data.static interface
Combined scope and spans information.static interface
Information describing a specific span. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonLogConverter
create()
Creates an instance of the converter that captures spans reported by OTel.resourceSpans
(int expectedCount) ReturnsJsonLogConverterImpl.LogResourceScopeSpans
instances corresponding to the data emitted by the log exporter.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
create
Creates an instance of the converter that captures spans reported by OTel.- Returns:
- new
JsonLogConverterImpl
instance
-
resourceSpans
ReturnsJsonLogConverterImpl.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
-