expr

package module
v1.51.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 16 Imported by: 6

Documentation

Overview

Package expr provides utilities for evaluating expressions against otel data structures.

Index

Constants

View Source
const (
	MetricNameField     = "metric_name"
	DatapointValueField = "datapoint_value"
)

Metric specific fields for use in expressions

View Source
const (
	// BodyField is the name of the field containing the log body.
	BodyField = "body"

	// ResourceField is the name of the field containing the resource attributes.
	ResourceField = "resource"

	// AttributesField is the name of the field containing the log attributes.
	AttributesField = "attributes"

	// SeverityEnumField is the name of the field containing the log severity enum.
	SeverityEnumField = "severity_enum"

	// SeverityNumberField is the name of the field containing the log severity number.
	SeverityNumberField = "severity_number"

	// TimestampField is the name of the field containing the log timestamp.
	TimestampField = "timestamp"
)
View Source
const (
	SpanKindField          = "trace_kind"
	SpanStatusCodeField    = "trace_status_code"
	SpanStatusMessageField = "trace_status_message"
	SpanDurationField      = "span_duration_ms"
)

Span specific fields for use in expressions

Variables

This section is empty.

Functions

func NewOTTLDatapointStatement

func NewOTTLDatapointStatement(statementStr string, set component.TelemetrySettings) (*ottl.Statement[ottldatapoint.TransformContext], error)

NewOTTLDatapointStatement parses the given statement into an ottl.Statement for a datapoint transform context.

func NewOTTLLogRecordStatement

func NewOTTLLogRecordStatement(statementStr string, set component.TelemetrySettings) (*ottl.Statement[ottllog.TransformContext], error)

NewOTTLLogRecordStatement parses the given statement into an ottl.Statement for a log transform context.

func NewOTTLSpanStatement

func NewOTTLSpanStatement(statementStr string, set component.TelemetrySettings) (*ottl.Statement[ottlspan.TransformContext], error)

NewOTTLSpanStatement parses the given statement into an ottl.Statement for a span transform context.

Types

type Datapoint

type Datapoint = map[string]any

Datapoint is the simplified representation of a metric datapoint.

type DatapointResourceGroup

type DatapointResourceGroup struct {
	Resource   map[string]any
	Datapoints []Datapoint
}

DatapointResourceGroup represents a pmetric.ResourceMetrics as native go types

func ConvertToDatapointResourceGroup

func ConvertToDatapointResourceGroup(metrics pmetric.Metrics) []DatapointResourceGroup

ConvertToDatapointResourceGroup converts a pmetric.Metrics into a slice of DatapointResourceGroup

type Expression

type Expression struct {
	*vm.Program
}

Expression is an Expression used to evaluate values.

func CreateBoolExpression

func CreateBoolExpression(str string) (*Expression, error)

CreateBoolExpression creates an expression from a string that returns a boolean.

func CreateExpression

func CreateExpression(str string, opts ...expr.Option) (*Expression, error)

CreateExpression creates an expression from a string.

func CreateValueExpression

func CreateValueExpression(str string) (*Expression, error)

CreateValueExpression creates an expression from a string that returns a value.

func (*Expression) Evaluate

func (e *Expression) Evaluate(env map[string]any) (any, error)

Evaluate evaluates an expression against the supplied environment.

func (*Expression) ExtractFloat

func (e *Expression) ExtractFloat(record Record) (float64, error)

ExtractFloat extracts a float from the record.

func (*Expression) ExtractInt

func (e *Expression) ExtractInt(record Record) (int64, error)

ExtractInt extracts an integer from the record.

func (*Expression) Match

func (e *Expression) Match(env map[string]any) (bool, error)

Match checks if an expression matches the supplied environment.

func (*Expression) MatchRecord

func (e *Expression) MatchRecord(record Record) bool

MatchRecord checks if an expression matches the supplied record.

type ExpressionMap

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

ExpressionMap is a map of expressions.

func CreateExpressionMap

func CreateExpressionMap(strMap map[string]string) (*ExpressionMap, error)

CreateExpressionMap creates an expression map from a string map.

func (*ExpressionMap) Extract

func (e *ExpressionMap) Extract(record Record) map[string]any

Extract extracts a value map from the record using the expression map.

type OTTLAttributeMap

type OTTLAttributeMap[T any] struct {
	// contains filtered or unexported fields
}

OTTLAttributeMap extracts attributes from telemetry using OTTL expressions. T is an ottl transform context.

func MakeOTTLAttributeMap

func MakeOTTLAttributeMap[T any](m map[string]string, set component.TelemetrySettings, createFunc func(string, component.TelemetrySettings) (*OTTLExpression[T], error)) (*OTTLAttributeMap[T], error)

MakeOTTLAttributeMap compiles the expressions in the given map of attribute keys to ottl expression strings into an OTTLAttributeMap. createFunc is the function for creating the expression, see the NewOTTLxxxExpression functions in this package for functions that may be used here.

func (OTTLAttributeMap[T]) ExtractAttributes

func (t OTTLAttributeMap[T]) ExtractAttributes(ctx context.Context, tCtx T) map[string]any

ExtractAttributes extracts the attributes using the passed in transform context.

type OTTLCondition

type OTTLCondition[T any] struct {
	// contains filtered or unexported fields
}

OTTLCondition evaluates an OTTL expression as a boolean value.

func NewOTTLDatapointCondition

func NewOTTLDatapointCondition(condition string, set component.TelemetrySettings) (*OTTLCondition[ottldatapoint.TransformContext], error)

NewOTTLDatapointCondition creates a new OTTLCondition for a datapoint with the given condition.

func NewOTTLLogRecordCondition

func NewOTTLLogRecordCondition(condition string, set component.TelemetrySettings) (*OTTLCondition[ottllog.TransformContext], error)

NewOTTLLogRecordCondition creates a new OTTLCondition for a log record with the given condition.

func NewOTTLSpanCondition

func NewOTTLSpanCondition(condition string, set component.TelemetrySettings) (*OTTLCondition[ottlspan.TransformContext], error)

NewOTTLSpanCondition creates a new OTTLCondition for a span with the given condition.

func (OTTLCondition[T]) Match

func (e OTTLCondition[T]) Match(ctx context.Context, tCtx T) (bool, error)

Match returns true if the expression is true for the given transform context.

type OTTLExpression

type OTTLExpression[T any] struct {
	// contains filtered or unexported fields
}

OTTLExpression evaluates an OTTL expression, returning a resultant value.

func NewOTTLDatapointExpression

func NewOTTLDatapointExpression(expression string, set component.TelemetrySettings) (*OTTLExpression[ottldatapoint.TransformContext], error)

NewOTTLDatapointExpression creates a new expression for datapoints. The expression is wrapped in an editor function, so only Converter functions and target expressions can be used.

func NewOTTLLogRecordExpression

func NewOTTLLogRecordExpression(expression string, set component.TelemetrySettings) (*OTTLExpression[ottllog.TransformContext], error)

NewOTTLLogRecordExpression creates a new expression for log records. The expression is wrapped in an editor function, so only Converter functions and target expressions can be used.

func NewOTTLSpanExpression

func NewOTTLSpanExpression(expression string, set component.TelemetrySettings) (*OTTLExpression[ottlspan.TransformContext], error)

NewOTTLSpanExpression creates a new expression for spans. The expression is wrapped in an editor function, so only Converter functions and target expressions can be used.

func (OTTLExpression[T]) Execute

func (e OTTLExpression[T]) Execute(ctx context.Context, tCtx T) (any, error)

Execute executes the expression with the given context, returning the value of the expression.

type Record

type Record = map[string]any

Record is the simplified representation of a log record.

func ConvertToRecord

func ConvertToRecord(log plog.LogRecord, resource map[string]any) Record

ConvertToRecord converts a log record to a simplified representation.

func ConvertToRecords

func ConvertToRecords(logs plog.Logs) []Record

ConvertToRecords converts plog.Logs to a slice of records.

type ResourceGroup

type ResourceGroup struct {
	Resource map[string]any
	Records  []Record
}

ResourceGroup is a group of records with the same resource attributes.

func ConvertToResourceGroups

func ConvertToResourceGroups(logs plog.Logs) []ResourceGroup

ConvertToResourceGroups converts plog.Logs to a slice of resource groups.

type Span

type Span = map[string]any

Span is the simplified representation of a metric datapoint.

type SpanResourceGroup

type SpanResourceGroup struct {
	Resource map[string]any
	Spans    []Span
}

SpanResourceGroup represents a ptrace.ResourceSpans as native go types

func ConvertToSpanResourceGroups

func ConvertToSpanResourceGroups(traces ptrace.Traces) []SpanResourceGroup

ConvertToSpanResourceGroups converts a ptrace.Traces into a slice of SpanResourceGroup

Jump to

Keyboard shortcuts

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