logstorage

package
v0.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package logstorage defines storage structure for logs storage.

Index

Constants

View Source
const (
	// AnyLocation looks for first occurrence of attribute in the following order:
	// 	record body, record attributes, record scope, record resource.
	AnyLocation = AttributeLocation(iota)
	// BodyLocation looks for a value in record body.
	BodyLocation
	// AttributesLocation looks for a value in record attributes.
	AttributesLocation
	// ScopeLocation looks for a value in scope attributes.
	ScopeLocation
	// ResourceLocation looks for a value in resource attributes.
	ResourceLocation
)
View Source
const (
	LabelTraceID  = "trace_id"
	LabelSpanID   = "span_id"
	LabelSeverity = "level"
	LabelBody     = "msg"

	LabelServiceName       = "service_name"        // resource.service.name
	LabelServiceNamespace  = "service_namespace"   // resource.service.namespace
	LabelServiceInstanceID = "service_instance_id" // resource.service.instance.id

	LabelDetectedLevel = "detected_level" // used by Loki/Grafana in many cases
)

Labels to use where prometheus compatible labels are required, e.g. loki.

View Source
const DefaultServiceName = "unknown_service"

DefaultServiceName is the value used for the service_name label when an OTLP record carries no service.name resource attribute. It mirrors the OTel SDK / Loki default so {service_name="unknown_service"} selects those streams.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeLocation

type AttributeLocation uint8

AttributeLocation defines the location to look for attribute.

func (AttributeLocation) String

func (l AttributeLocation) String() string

String implements fmt.Stringer.

type AttributeRef

type AttributeRef struct {
	Name     string
	Location AttributeLocation
}

AttributeRef define an attribute ref.

func ParseAttributeRef

func ParseAttributeRef(ref string) (AttributeRef, error)

ParseAttributeRef parses AttributeRef from given string.

func (AttributeRef) Evaluate

func (r AttributeRef) Evaluate(body pcommon.Value, record Record) (pcommon.Value, bool)

Evaluate evaluates reference on given record.

func (AttributeRef) String

func (r AttributeRef) String() string

String implements fmt.Stringer.

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer consumes given logs and inserts them using given Inserter.

func NewConsumer

func NewConsumer(i Inserter, opts ConsumerOptions) (*Consumer, error)

NewConsumer creates new Consumer.

func (*Consumer) ConsumeLogs

func (c *Consumer) ConsumeLogs(ctx context.Context, logs plog.Logs) error

ConsumeLogs implements otelreceiver.Consumer.

type ConsumerOptions

type ConsumerOptions struct {
	// TriggerAttributes defines a list of attribute references to trigger format detection.
	TriggerAttributes []AttributeRef
	// FormatAttributes defines a list of attribute references to choose format.
	//
	// Format attribute may define multple formats via comma.
	// The first valid would be used to parse the record.
	//
	// If attribute value is absent, have an unknown or invalid value, the record would be passed as-is.
	FormatAttributes []AttributeRef
	// DetectFormats defines list of formats to detect.
	DetectFormats []logparser.Parser

	// MeterProvider provides OpenTelemetry meter.
	MeterProvider metric.MeterProvider
	// TracerProvider provides OpenTelemetry tracer.
	TracerProvider trace.TracerProvider
}

ConsumerOptions defines options for telemetry pre-processing.

type DetectedField

type DetectedField struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Cardinality uint64 `json:"cardinality"`
}

DetectedField is a detected field with type and cardinality information.

type DetectedLabel

type DetectedLabel struct {
	Name        string `json:"name"`
	Cardinality int    `json:"cardinality"`
}

DetectedLabel is a data structure for log label.

type Inserter

type Inserter interface {
	// RecordWriter creates a new batch.
	RecordWriter(ctx context.Context) (RecordWriter, error)
}

Inserter is a log storage insert interface.

type Label

type Label struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Label is a data structure for log label.

type LabelsOptions

type LabelsOptions struct {
	// Start defines time range for search.
	//
	// Querier ignores parameter, if it is zero.
	Start time.Time
	// End defines time range for search.
	//
	// Querier ignores parameter, if it is zero.
	End time.Time
	// Selector that selects the streams to match.
	Query logql.Selector
	// Limit sets maximum number of results.
	//
	// Querier ignores parameter, if it is zero.
	Limit int
}

LabelsOptions defines options for Querier.LabelNames and Querier.LabelValues methods.

type Querier

type Querier interface {
	// LabelNames returns all available label names.
	LabelNames(ctx context.Context, opts LabelsOptions) ([]string, error)
	// LabelValues returns all available label values for given label.
	LabelValues(ctx context.Context, labelName string, opts LabelsOptions) (iterators.Iterator[Label], error)
	// Series returns all available log series.
	Series(ctx context.Context, opts SeriesOptions) (Series, error)
	// DetectedLabels returns cardinality of all detected labels.
	DetectedLabels(ctx context.Context, opts LabelsOptions) ([]DetectedLabel, error)
	// DetectedFields returns detected fields with type and cardinality.
	DetectedFields(ctx context.Context, opts LabelsOptions) ([]DetectedField, error)
}

Querier is a logs storage query interface.

type Record

type Record = logparser.Record

Record is a log record.

func NewRecordFromOTEL

func NewRecordFromOTEL(
	res pcommon.Resource,
	scope pcommon.InstrumentationScope,
	record plog.LogRecord,
) Record

NewRecordFromOTEL creates new Record.

type RecordWriter

type RecordWriter interface {
	// Add adds record to the batch.
	Add(record Record) error
	// Submit sends batch.
	Submit(ctx context.Context) error
	// Close frees resources.
	//
	// Callers should call [RecordWriter.Close] regardless if they called [RecordWriter.Submit] or not.
	Close() error
}

RecordWriter represents a log record batch.

type Series

type Series []map[string]string

Series defines a list of series.

type SeriesOptions

type SeriesOptions struct {
	// Start defines time range for search.
	//
	// Querier ignores parameter, if it is zero.
	Start time.Time
	// End defines time range for search.
	//
	// Querier ignores parameter, if it is zero.
	End time.Time
	// Selectors defines a list of matchers to filter series.
	Selectors []logql.Selector
}

SeriesOptions defines options for Querier.Series method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL