Package codes.grow.packages.loki
Class LokiLogExporter
java.lang.Object
codes.grow.packages.loki.LokiLogExporter
- All Implemented Interfaces:
LogExporter
LogExporter of the logging category that writes records with POST
/loki/api/v1/push.
Mapping (recordsToStreams(java.util.List<codes.grow.packages.loki.logging.LogRecord>, codes.grow.packages.loki.CardinalityGuard)): resource and attribute keys are normalized (
service.name → service_name); allowlisted keys become index labels, plus level
(lower-case severity) when allowed; everything else, and trace_id, span_id,
trace_flags, severity_text, severity_number and
observed_timestamp, becomes structured metadata. The body is the log line. Loki accepts or
rejects a whole push, so a result is either all accepted or all rejected (with the error).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringStructured metadata key of the observed timestamp (Unix nanoseconds).static final StringStructured metadata key of the OTel severity number.static final StringStructured metadata key of the severity text.static final StringStructured metadata key of the span id.static final StringStructured metadata key of the trace flags.static final StringStructured metadata key of the trace id. -
Constructor Summary
ConstructorsConstructorDescriptionLokiLogExporter(LokiClient client, PushFormat format, CardinalityGuard guard) Creates an exporter. -
Method Summary
Modifier and TypeMethodDescriptionexport(List<LogRecord> records, ExportOptions options) Exports a batch.static List<LokiStream> recordsToStreams(List<LogRecord> records, CardinalityGuard guard) Converts records into Loki streams; records with the same final label set share a stream.shutdown()Releases resources.
-
Field Details
-
METADATA_TRACE_ID
Structured metadata key of the trace id.- See Also:
-
METADATA_SPAN_ID
Structured metadata key of the span id.- See Also:
-
METADATA_TRACE_FLAGS
Structured metadata key of the trace flags.- See Also:
-
METADATA_SEVERITY_TEXT
Structured metadata key of the severity text.- See Also:
-
METADATA_SEVERITY_NUMBER
Structured metadata key of the OTel severity number.- See Also:
-
METADATA_OBSERVED_TIMESTAMP
Structured metadata key of the observed timestamp (Unix nanoseconds).- See Also:
-
-
Constructor Details
-
LokiLogExporter
Creates an exporter.- Parameters:
client- client (and tenant) to push withformat- wire formatguard- cardinality guard
-
-
Method Details
-
recordsToStreams
Converts records into Loki streams; records with the same final label set share a stream.- Parameters:
records- recordsguard- cardinality guard- Returns:
- streams, in first-seen order of their label sets
-
export
Description copied from interface:LogExporterExports a batch. The future completes with the accepted/rejected counts; it may also complete exceptionally (treated as "all rejected"). Cancelling the future cancels the export.- Specified by:
exportin interfaceLogExporter- Parameters:
records- records to send (never empty)options- gzip flag and time budget- Returns:
- the export result
-
shutdown
Description copied from interface:LogExporterReleases resources. Called once byBatchProcessor.shutdown.- Specified by:
shutdownin interfaceLogExporter- Returns:
- completes when the exporter is closed
-