Documentation ¶
Index ¶
- func CreateFactoryMap[K any](factories ...Factory[K]) map[string]Factory[K]
- type Arguments
- type BoolExpr
- type BoolGetter
- type BoolLikeGetter
- type ByteSliceLikeGetter
- type Condition
- type ConditionSequence
- type ConditionSequenceOption
- type CreateFunctionFunc
- type DurationGetter
- type Enum
- type EnumParser
- type EnumSymbol
- type ErrorMode
- type Expr
- type ExprFunc
- type Factory
- type FactoryOption
- type FloatGetter
- type FloatLikeGetter
- type FunctionContext
- type FunctionGetter
- type GetSetter
- type Getter
- type IntGetter
- type IntLikeGetter
- type Key
- type LogicOperation
- type Option
- type Optional
- type PMapGetter
- type ParsedStatementConverter
- type Parser
- func (p *Parser[K]) ParseCondition(condition string) (*Condition[K], error)
- func (p *Parser[K]) ParseConditions(conditions []string) ([]*Condition[K], error)
- func (p *Parser[K]) ParseStatement(statement string) (*Statement[K], error)
- func (p *Parser[K]) ParseStatements(statements []string) ([]*Statement[K], error)
- type ParserCollection
- type ParserCollectionOption
- func EnableParserCollectionModifiedStatementLogging[R any](enabled bool) ParserCollectionOption[R]
- func WithParserCollectionContext[K any, R any](context string, parser *Parser[K], converter ParsedStatementConverter[K, R]) ParserCollectionOption[R]
- func WithParserCollectionErrorMode[R any](errorMode ErrorMode) ParserCollectionOption[R]
- type Path
- type PathExpressionParser
- type Setter
- type StandardBoolGetter
- type StandardBoolLikeGetter
- type StandardByteSliceLikeGetter
- type StandardDurationGetter
- type StandardFloatGetter
- type StandardFloatLikeGetter
- type StandardFunctionGetter
- type StandardGetSetter
- type StandardIntGetter
- type StandardIntLikeGetter
- type StandardPMapGetter
- type StandardStringGetter
- type StandardStringLikeGetter
- type StandardTimeGetter
- type Statement
- type StatementSequence
- type StatementSequenceOption
- type StatementsGetter
- type StringGetter
- type StringLikeGetter
- type TimeGetter
- type TypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Arguments ¶ added in v0.77.0
type Arguments any
Arguments holds the arguments for an OTTL function, with arguments specified as fields on a struct. Argument ordering is defined
type BoolExpr ¶ added in v0.64.0
type BoolExpr[K any] struct { // contains filtered or unexported fields }
type BoolGetter ¶ added in v0.89.0
type BoolGetter[K any] interface { // Get retrieves a bool value. Get(ctx context.Context, tCtx K) (bool, error) }
BoolGetter is a Getter that must return a bool.
type BoolLikeGetter ¶ added in v0.89.0
type BoolLikeGetter[K any] interface { // Get retrieves a bool value. // Unlike `BoolGetter`, the expectation is that the underlying value is converted to a bool if possible. // If the value cannot be converted to a bool, nil and an error are returned. // If the value is nil, nil is returned without an error. Get(ctx context.Context, tCtx K) (*bool, error) }
BoolLikeGetter is a Getter that returns a bool by converting the underlying value to a bool if necessary.
type ByteSliceLikeGetter ¶ added in v0.104.0
type ByteSliceLikeGetter[K any] interface { // Get retrieves []byte value. // The expectation is that the underlying value is converted to []byte if possible. // If the value cannot be converted to []byte, nil and an error are returned. // If the value is nil, nil is returned without an error. Get(ctx context.Context, tCtx K) ([]byte, error) }
ByteSliceLikeGetter is a Getter that returns []byte by converting the underlying value to an []byte if necessary
type Condition ¶ added in v0.90.0
type Condition[K any] struct { // contains filtered or unexported fields }
Condition holds a top level Condition. A Condition is a boolean expression to match telemetry.
type ConditionSequence ¶ added in v0.91.0
type ConditionSequence[K any] struct { // contains filtered or unexported fields }
ConditionSequence represents a list of Conditions that will be evaluated sequentially for a TransformContext and will handle errors returned by conditions based on an ErrorMode. By default, the conditions are ORed together, but they can be ANDed together using the WithLogicOperation option.
func NewConditionSequence ¶ added in v0.91.0
func NewConditionSequence[K any](conditions []*Condition[K], telemetrySettings component.TelemetrySettings, options ...ConditionSequenceOption[K]) ConditionSequence[K]
NewConditionSequence creates a new ConditionSequence with the provided Condition slice and component.TelemetrySettings. The default ErrorMode is `Propagate` and the default LogicOperation is `OR`. You may also augment the ConditionSequence with a slice of ConditionSequenceOption.
func (*ConditionSequence[K]) Eval ¶ added in v0.91.0
func (c *ConditionSequence[K]) Eval(ctx context.Context, tCtx K) (bool, error)
Eval evaluates the result of each Condition in the ConditionSequence. The boolean logic between conditions is based on the ConditionSequence's Logic Operator. If using the default OR LogicOperation, if any Condition evaluates to true, then true is returned and if all Conditions evaluate to false, then false is returned. If using the AND LogicOperation, if any Condition evaluates to false, then false is returned and if all Conditions evaluate to true, then true is returned. When the ErrorMode of the ConditionSequence is `propagate`, errors cause the evaluation to be false and an error is returned. When the ErrorMode of the ConditionSequence is `ignore`, errors are logged and cause the evaluation to continue to the next condition. When the ErrorMode of the ConditionSequence is `silent`, errors are not logged and cause the evaluation to continue to the next condition. When using the AND LogicOperation with the `ignore` ErrorMode the sequence will evaluate to false if all conditions error.
type ConditionSequenceOption ¶ added in v0.91.0
type ConditionSequenceOption[K any] func(*ConditionSequence[K])
func WithConditionSequenceErrorMode ¶ added in v0.91.0
func WithConditionSequenceErrorMode[K any](errorMode ErrorMode) ConditionSequenceOption[K]
WithConditionSequenceErrorMode sets the ErrorMode of a ConditionSequence
func WithLogicOperation ¶ added in v0.91.0
func WithLogicOperation[K any](logicOp LogicOperation) ConditionSequenceOption[K]
WithLogicOperation sets the LogicOperation of a ConditionSequence When setting AND the conditions will be ANDed together. When setting OR the conditions will be ORed together.
type CreateFunctionFunc ¶ added in v0.77.0
type CreateFunctionFunc[K any] func(fCtx FunctionContext, args Arguments) (ExprFunc[K], error)
type DurationGetter ¶ added in v0.84.0
type DurationGetter[K any] interface { // Get retrieves a time.Duration value. Get(ctx context.Context, tCtx K) (time.Duration, error) }
DurationGetter is a Getter that must return a time.Duration.
type EnumParser ¶
type EnumParser func(*EnumSymbol) (*Enum, error)
type EnumSymbol ¶
type EnumSymbol string
type ErrorMode ¶ added in v0.71.0
type ErrorMode string
func (*ErrorMode) UnmarshalText ¶ added in v0.72.0
type Factory ¶ added in v0.77.0
type Factory[K any] interface { // Name is the canonical name to be used by the user when invocating // the function generated by this Factory. Name() string // CreateDefaultArguments initializes an Arguments struct specific to this // Factory containing the arguments for the function. CreateDefaultArguments() Arguments // CreateFunction creates an OTTL function that will use the given Arguments. CreateFunction(fCtx FunctionContext, args Arguments) (ExprFunc[K], error) // contains filtered or unexported methods }
Factory defines an OTTL function factory that will generate an OTTL function to be called within a statement.
func NewFactory ¶ added in v0.77.0
func NewFactory[K any](name string, args Arguments, createFunctionFunc CreateFunctionFunc[K], options ...FactoryOption[K]) Factory[K]
type FactoryOption ¶ added in v0.77.0
type FactoryOption[K any] func(factory *factory[K])
type FloatGetter ¶ added in v0.78.0
type FloatGetter[K any] interface { // Get retrieves a float64 value. Get(ctx context.Context, tCtx K) (float64, error) }
FloatGetter is a Getter that must return a float64.
type FloatLikeGetter ¶ added in v0.78.0
type FloatLikeGetter[K any] interface { // Get retrieves a float64 value. // Unlike `FloatGetter`, the expectation is that the underlying value is converted to a float64 if possible. // If the value cannot be converted to a float64, nil and an error are returned. // If the value is nil, nil is returned without an error. Get(ctx context.Context, tCtx K) (*float64, error) }
FloatLikeGetter is a Getter that returns a float64 by converting the underlying value to a float64 if necessary.
type FunctionContext ¶ added in v0.77.0
type FunctionContext struct {
Set component.TelemetrySettings
}
FunctionContext contains data provided by the Collector component to the OTTL for use in functions.
type FunctionGetter ¶ added in v0.83.0
type FunctionGetter[K any] interface { // Get returns a function as an Expr[K] built with the provided Arguments Get(args Arguments) (Expr[K], error) }
FunctionGetter uses a function factory to return an instantiated function as an Expr.
type GetSetter ¶
GetSetter is an interface that combines the Getter and Setter interfaces. It should be used to represent the ability to both get and set a value.
type Getter ¶
type Getter[K any] interface { // Get retrieves a value of type 'Any' and returns an error if there are any issues during retrieval. Get(ctx context.Context, tCtx K) (any, error) }
Getter resolves a value at runtime without performing any type checking on the value that is returned.
type IntGetter ¶ added in v0.72.0
type IntGetter[K any] interface { // Get retrieves an int64 value. Get(ctx context.Context, tCtx K) (int64, error) }
IntGetter is a Getter that must return an int64.
type IntLikeGetter ¶ added in v0.78.0
type IntLikeGetter[K any] interface { // Get retrieves an int value. // Unlike `IntGetter`, the expectation is that the underlying value is converted to an int if possible. // If the value cannot be converted to an int, nil and an error are returned. // If the value is nil, nil is returned without an error. Get(ctx context.Context, tCtx K) (*int64, error) }
IntLikeGetter is a Getter that returns an int by converting the underlying value to an int if necessary
type Key ¶ added in v0.77.0
type Key[K any] interface { // String returns a pointer to the Key's string value. // If the Key does not have a string value the returned value is nil. // If Key experiences an error retrieving the value it is returned. String(context.Context, K) (*string, error) // Int returns a pointer to the Key's int value. // If the Key does not have a int value the returned value is nil. // If Key experiences an error retrieving the value it is returned. Int(context.Context, K) (*int64, error) }
Key represents a chain of keys in an OTTL statement, such as `attributes["foo"]["bar"]`. A Key has a String or Int, and potentially the next Key. If the path in the OTTL statement contains multiple keys, then the Key will have a pointer to the next Key.
type LogicOperation ¶ added in v0.91.0
type LogicOperation string
const ( And LogicOperation = "and" Or LogicOperation = "or" )
func (*LogicOperation) UnmarshalText ¶ added in v0.91.0
func (l *LogicOperation) UnmarshalText(text []byte) error
type Option ¶ added in v0.70.0
func WithEnumParser ¶ added in v0.70.0
func WithEnumParser[K any](parser EnumParser) Option[K]
func WithPathContextNames ¶ added in v0.109.0
WithPathContextNames sets the context names to be considered when parsing a Path value. When this option is empty or nil, all Path segments are considered fields, and the Path.Context value is always empty. When this option is configured, and the path's context is empty or is not present in this context names list, it results into an error.
type Optional ¶ added in v0.86.0
type Optional[T any] struct { // contains filtered or unexported fields }
func NewTestingOptional ¶ added in v0.86.0
Allows creating an Optional with a value already populated for use in testing OTTL functions.
type PMapGetter ¶ added in v0.75.0
type PMapGetter[K any] interface { // Get retrieves a pcommon.Map value. Get(ctx context.Context, tCtx K) (pcommon.Map, error) }
PMapGetter is a Getter that must return a pcommon.Map.
type ParsedStatementConverter ¶ added in v0.116.0
type ParsedStatementConverter[K any, R any] func( collection *ParserCollection[R], parser *Parser[K], context string, statements StatementsGetter, parsedStatements []*Statement[K], ) (R, error)
ParsedStatementConverter is a function that converts the parsed ottl.Statement[K] into a common representation to all parser collection contexts passed through WithParserCollectionContext. Given each parser has its own transform context type, they must agree on a common type [R] so it can be returned by the ParserCollection.ParseStatements and ParserCollection.ParseStatementsWithContext functions.
Experimental: *NOTE* this API is subject to change or removal in the future.
type Parser ¶
type Parser[K any] struct { // contains filtered or unexported fields }
Parser provides the means to parse OTTL StatementSequence and Conditions given a specific set of functions, a PathExpressionParser, and an EnumParser.
func NewParser ¶
func NewParser[K any]( functions map[string]Factory[K], pathParser PathExpressionParser[K], settings component.TelemetrySettings, options ...Option[K], ) (Parser[K], error)
func (*Parser[K]) ParseCondition ¶ added in v0.90.0
ParseCondition parses a single string condition into a Condition objects ready for execution. Returns an Condition and a nil error on successful parsing. If parsing fails, returns nil and an error.
func (*Parser[K]) ParseConditions ¶ added in v0.90.0
ParseConditions parses string conditions into a Condition slice ready for execution. Returns a slice of Condition and a nil error on successful parsing. If parsing fails, returns nil and an error containing each error per failed condition.
func (*Parser[K]) ParseStatement ¶ added in v0.72.0
ParseStatement parses a single string statement into a Statement struct ready for execution. Returns a Statement and a nil error on successful parsing. If parsing fails, returns nil and an error.
func (*Parser[K]) ParseStatements ¶
ParseStatements parses string statements into ottl.Statement objects ready for execution. Returns a slice of statements and a nil error on successful parsing. If parsing fails, returns nil and a joined error containing each error per failed statement.
type ParserCollection ¶ added in v0.116.0
type ParserCollection[R any] struct { Settings component.TelemetrySettings ErrorMode ErrorMode // contains filtered or unexported fields }
ParserCollection is a configurable set of ottl.Parser that can handle multiple OTTL contexts parsings, inferring the context, choosing the right parser for the given statements, and transforming the parsed ottl.Statement[K] slice into a common result of type R.
Experimental: *NOTE* this API is subject to change or removal in the future.
func NewParserCollection ¶ added in v0.116.0
func NewParserCollection[R any]( settings component.TelemetrySettings, options ...ParserCollectionOption[R], ) (*ParserCollection[R], error)
NewParserCollection creates a new ParserCollection.
Experimental: *NOTE* this API is subject to change or removal in the future.
func (*ParserCollection[R]) ParseStatements ¶ added in v0.116.0
func (pc *ParserCollection[R]) ParseStatements(statements StatementsGetter) (R, error)
ParseStatements parses the given statements into [R] using the configured context's ottl.Parser and subsequently calling the ParsedStatementConverter function. The statement's context is automatically inferred from the [Path.Context] values, choosing the highest priority context found. If no contexts are present in the statements, or if the inferred value is not supported by the ParserCollection, it returns an error. If parsing the statements fails, it returns the underlying ottl.Parser.ParseStatements error.
Experimental: *NOTE* this API is subject to change or removal in the future.
func (*ParserCollection[R]) ParseStatementsWithContext ¶ added in v0.116.0
func (pc *ParserCollection[R]) ParseStatementsWithContext(context string, statements StatementsGetter, prependPathsContext bool) (R, error)
ParseStatementsWithContext parses the given statements into [R] using the configured context's ottl.Parser and subsequently calling the ParsedStatementConverter function. Unlike ParseStatements, it uses the provided context and does not infer it automatically. The context value must be supported by the ParserCollection, otherwise an error is returned. If the statement's Path does not provide their Path.Context value, the prependPathsContext argument should be set to true, so it rewrites the statements prepending the missing paths contexts. If parsing the statements fails, it returns the underlying ottl.Parser.ParseStatements error.
Experimental: *NOTE* this API is subject to change or removal in the future.
type ParserCollectionOption ¶ added in v0.116.0
type ParserCollectionOption[R any] func(*ParserCollection[R]) error
ParserCollectionOption is a configurable ParserCollection option.
Experimental: *NOTE* this API is subject to change or removal in the future.
func EnableParserCollectionModifiedStatementLogging ¶ added in v0.116.0
func EnableParserCollectionModifiedStatementLogging[R any](enabled bool) ParserCollectionOption[R]
EnableParserCollectionModifiedStatementLogging controls the statements modification logs. When enabled, it logs any statements modifications performed by the parsing operations, instructing users to rewrite the statements accordingly.
Experimental: *NOTE* this API is subject to change or removal in the future.
func WithParserCollectionContext ¶ added in v0.116.0
func WithParserCollectionContext[K any, R any]( context string, parser *Parser[K], converter ParsedStatementConverter[K, R], ) ParserCollectionOption[R]
WithParserCollectionContext configures an ottl.Parser for the given context. The provided ottl.Parser must be configured to support the provided context using the ottl.WithPathContextNames option.
Experimental: *NOTE* this API is subject to change or removal in the future.
func WithParserCollectionErrorMode ¶ added in v0.116.0
func WithParserCollectionErrorMode[R any](errorMode ErrorMode) ParserCollectionOption[R]
WithParserCollectionErrorMode has no effect on the ParserCollection, but might be used by the ParsedStatementConverter functions to handle/create StatementSequence.
Experimental: *NOTE* this API is subject to change or removal in the future.
type Path ¶
type Path[K any] interface { // Context is the OTTL context name of this Path. Context() string // Name is the name of this segment of the path. Name() string // Next provides the next path segment for this Path. // Will return nil if there is no next path. Next() Path[K] // Keys provides the Keys for this Path. // Will return nil if there are no Keys. Keys() []Key[K] // String returns a string representation of this Path and the next Paths String() string }
Path represents a chain of path parts in an OTTL statement, such as `body.string`. A Path has a name, and potentially a set of keys. If the path in the OTTL statement contains multiple parts (separated by a dot (`.`)), then the Path will have a pointer to the next Path.
type Setter ¶
type Setter[K any] interface { // Set sets a value of type 'Any' and returns an error if there are any issues during the setting process. Set(ctx context.Context, tCtx K, val any) error }
Setter allows setting an untyped value on a predefined field within some data at runtime.
type StandardBoolGetter ¶ added in v0.89.0
StandardBoolGetter is a basic implementation of BoolGetter
type StandardBoolLikeGetter ¶ added in v0.89.0
type StandardByteSliceLikeGetter ¶ added in v0.104.0
type StandardDurationGetter ¶ added in v0.84.0
StandardDurationGetter is a basic implementation of DurationGetter
type StandardFloatGetter ¶ added in v0.79.0
StandardFloatGetter is a basic implementation of FloatGetter
type StandardFloatLikeGetter ¶ added in v0.78.0
type StandardFunctionGetter ¶ added in v0.83.0
type StandardFunctionGetter[K any] struct { FCtx FunctionContext Fact Factory[K] }
StandardFunctionGetter is a basic implementation of FunctionGetter.
func (StandardFunctionGetter[K]) Get ¶ added in v0.83.0
func (g StandardFunctionGetter[K]) Get(args Arguments) (Expr[K], error)
Get takes an Arguments struct containing arguments the caller wants passed to the function and instantiates the function with those arguments. If there is a mismatch between the function's signature and the arguments the caller wants to pass to the function, an error is returned.
type StandardGetSetter ¶
type StandardGetSetter[K any] struct { Getter func(ctx context.Context, tCtx K) (any, error) Setter func(ctx context.Context, tCtx K, val any) error }
type StandardIntGetter ¶ added in v0.79.0
StandardIntGetter is a basic implementation of IntGetter
type StandardIntLikeGetter ¶ added in v0.78.0
type StandardPMapGetter ¶ added in v0.79.0
StandardPMapGetter is a basic implementation of PMapGetter
type StandardStringGetter ¶ added in v0.79.0
StandardStringGetter is a basic implementation of StringGetter
type StandardStringLikeGetter ¶ added in v0.75.0
type StandardTimeGetter ¶ added in v0.85.0
StandardTimeGetter is a basic implementation of TimeGetter
type Statement ¶
type Statement[K any] struct { // contains filtered or unexported fields }
Statement holds a top level Statement for processing telemetry data. A Statement is a combination of a function invocation and the boolean expression to match telemetry for invoking the function.
func (*Statement[K]) Execute ¶ added in v0.62.0
Execute is a function that will execute the statement's function if the statement's condition is met. Returns true if the function was run, returns false otherwise. If the statement contains no condition, the function will run and true will be returned. In addition, the functions return value is always returned.
type StatementSequence ¶ added in v0.91.0
type StatementSequence[K any] struct { // contains filtered or unexported fields }
StatementSequence represents a list of statements that will be executed sequentially for a TransformContext and will handle errors based on an ErrorMode.
func NewStatementSequence ¶ added in v0.91.0
func NewStatementSequence[K any](statements []*Statement[K], telemetrySettings component.TelemetrySettings, options ...StatementSequenceOption[K]) StatementSequence[K]
NewStatementSequence creates a new StatementSequence with the provided Statement slice and component.TelemetrySettings. The default ErrorMode is `Propagate`. You may also augment the StatementSequence with a slice of StatementSequenceOption.
func (*StatementSequence[K]) Execute ¶ added in v0.91.0
func (s *StatementSequence[K]) Execute(ctx context.Context, tCtx K) error
Execute is a function that will execute all the statements in the StatementSequence list. When the ErrorMode of the StatementSequence is `propagate`, errors cause the execution to halt and the error is returned. When the ErrorMode of the StatementSequence is `ignore`, errors are logged and execution continues to the next statement. When the ErrorMode of the StatementSequence is `silent`, errors are not logged and execution continues to the next statement.
type StatementSequenceOption ¶ added in v0.91.0
type StatementSequenceOption[K any] func(*StatementSequence[K])
func WithStatementSequenceErrorMode ¶ added in v0.91.0
func WithStatementSequenceErrorMode[K any](errorMode ErrorMode) StatementSequenceOption[K]
WithStatementSequenceErrorMode sets the ErrorMode of a StatementSequence
type StatementsGetter ¶ added in v0.116.0
type StatementsGetter interface { // GetStatements retrieves the OTTL statements to be parsed GetStatements() []string }
StatementsGetter represents a set of statements to be parsed.
Experimental: *NOTE* this API is subject to change or removal in the future.
func NewStatementsGetter ¶ added in v0.116.0
func NewStatementsGetter(statements []string) StatementsGetter
NewStatementsGetter creates a new StatementsGetter.
Experimental: *NOTE* this API is subject to change or removal in the future.
type StringGetter ¶ added in v0.72.0
type StringGetter[K any] interface { // Get retrieves a string value. Get(ctx context.Context, tCtx K) (string, error) }
StringGetter is a Getter that must return a string.
type StringLikeGetter ¶ added in v0.75.0
type StringLikeGetter[K any] interface { // Get retrieves a string value. // Unlike `StringGetter`, the expectation is that the underlying value is converted to a string if possible. // If the value cannot be converted to a string, nil and an error are returned. // If the value is nil, nil is returned without an error. Get(ctx context.Context, tCtx K) (*string, error) }
StringLikeGetter is a Getter that returns a string by converting the underlying value to a string if necessary.