ottl

package module
v0.116.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 21 Imported by: 25

README

OpenTelemetry Transformation Language

Status
Stability alpha: traces, metrics, logs
Issues Open issues Closed issues
Code Owners @TylerHelmuth, @kentquirk, @bogdandrutu, @evan-bradley | Seeking more code owners!

The OpenTelemetry Transformation Language (OTTL) is a small, domain-specific programming language intended to process data with OpenTelemetry-native concepts and constructs.

This package implements everything necessary to use OTTL in a Collector component or in another user-facing system.

Getting Started

If you're looking to write OTTL statements for a component's configuration check out these resources.

See OTTL Functions for a list of functions available for use in the OTTL statements of most components.

OTTL Contexts define how you access the fields on a given telemetry item. See the table to find the exact list of available fields:

Telemetry OTTL Context
Resource Resource
Instrumentation Scope Instrumentation Scope
Span Span
Span Event SpanEvent
Metric Metric
Datapoint DataPoint
Log Log

To understand what OTTL offers as a language, check out OTTL's grammar doc.

Where to use OTTL

Troubleshooting

When using OTTL you can enable debug logging in the collector to print out useful information, such as the current Statement/Condition and the current TransformContext, to help you troubleshoot why a statement is not behaving as you expect. This feature is very verbose, but provides you an accurate view into how OTTL views the underlying data.

service:
  telemetry:
    logs:
      level: debug
2024-05-29T16:38:09.600-0600    debug   ottl@v0.101.0/parser.go:265     initial TransformContext        {"kind": "processor", "name": "transform", "pipeline": "logs", "TransformContext": {"resource": {"attributes": {}, "dropped_attribute_count": 0}, "scope": {"attributes": {}, "dropped_attribute_count": 0, "name": "", "version": ""}, "log_record": {"attributes": {"log.file.name": "test.log"}, "body": "test", "dropped_attribute_count": 0, "flags": 0, "observed_time_unix_nano": 1717022289500721000, "severity_number": 0, "severity_text": "", "span_id": "", "time_unix_nano": 0, "trace_id": ""}, "cache": {}}}
2024-05-29T16:38:09.600-0600    debug   ottl@v0.101.0/parser.go:268     TransformContext after statement execution      {"kind": "processor", "name": "transform", "pipeline": "logs", "statement": "set(resource.attributes[\"test\"], \"pass\")", "condition matched": true, "TransformContext": {"resource": {"attributes": {"test": "pass"}, "dropped_attribute_count": 0}, "scope": {"attributes": {}, "dropped_attribute_count": 0, "name": "", "version": ""}, "log_record": {"attributes": {"log.file.name": "test.log"}, "body": "test", "dropped_attribute_count": 0, "flags": 0, "observed_time_unix_nano": 1717022289500721000, "severity_number": 0, "severity_text": "", "span_id": "", "time_unix_nano": 0, "trace_id": ""}, "cache": {}}}
2024-05-29T16:38:09.600-0600    debug   ottl@v0.101.0/parser.go:268     TransformContext after statement execution      {"kind": "processor", "name": "transform", "pipeline": "logs", "statement": "set(instrumentation_scope.attributes[\"test\"], [\"pass\"])", "condition matched": true, "TransformContext": {"resource": {"attributes": {"test": "pass"}, "dropped_attribute_count": 0}, "scope": {"attributes": {"test": ["pass"]}, "dropped_attribute_count": 0, "name": "", "version": ""}, "log_record": {"attributes": {"log.file.name": "test.log"}, "body": "test", "dropped_attribute_count": 0, "flags": 0, "observed_time_unix_nano": 1717022289500721000, "severity_number": 0, "severity_text": "", "span_id": "", "time_unix_nano": 0, "trace_id": ""}, "cache": {}}}
2024-05-29T16:38:09.601-0600    debug   ottl@v0.101.0/parser.go:268     TransformContext after statement execution      {"kind": "processor", "name": "transform", "pipeline": "logs", "statement": "set(attributes[\"test\"], true)", "condition matched": true, "TransformContext": {"resource": {"attributes": {"test": "pass"}, "dropped_attribute_count": 0}, "scope": {"attributes": {"test": ["pass"]}, "dropped_attribute_count": 0, "name": "", "version": ""}, "log_record": {"attributes": {"log.file.name": "test.log", "test": true}, "body": "test", "dropped_attribute_count": 0, "flags": 0, "observed_time_unix_nano": 1717022289500721000, "severity_number": 0, "severity_text": "", "span_id": "", "time_unix_nano": 0, "trace_id": ""}, "cache": {}}}

Resources

These are previous conference presentations given about OTTL:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFactoryMap added in v0.77.0

func CreateFactoryMap[K any](factories ...Factory[K]) map[string]Factory[K]

CreateFactoryMap takes a list of factories and returns a map of Factories keyed on their canonical names.

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
}

func (BoolExpr[K]) Eval added in v0.64.0

func (e BoolExpr[K]) Eval(ctx context.Context, tCtx K) (bool, error)

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.

func (*Condition[K]) Eval added in v0.90.0

func (c *Condition[K]) Eval(ctx context.Context, tCtx K) (bool, error)

Eval returns true if the condition was met for the given TransformContext and false otherwise.

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 Enum

type Enum int64

type EnumParser

type EnumParser func(*EnumSymbol) (*Enum, error)

type EnumSymbol

type EnumSymbol string

type ErrorMode added in v0.71.0

type ErrorMode string
const (
	IgnoreError    ErrorMode = "ignore"
	PropagateError ErrorMode = "propagate"
	SilentError    ErrorMode = "silent"
)

func (*ErrorMode) UnmarshalText added in v0.72.0

func (e *ErrorMode) UnmarshalText(text []byte) error

type Expr added in v0.64.0

type Expr[K any] struct {
	// contains filtered or unexported fields
}

func (Expr[K]) Eval added in v0.64.0

func (e Expr[K]) Eval(ctx context.Context, tCtx K) (any, error)

type ExprFunc

type ExprFunc[K any] func(ctx context.Context, tCtx K) (any, error)

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

type GetSetter[K any] interface {
	Getter[K]
	Setter[K]
}

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

type Option[K any] func(*Parser[K])

func WithEnumParser added in v0.70.0

func WithEnumParser[K any](parser EnumParser) Option[K]

func WithPathContextNames added in v0.109.0

func WithPathContextNames[K any](contexts []string) Option[K]

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

func NewTestingOptional[T any](val T) Optional[T]

Allows creating an Optional with a value already populated for use in testing OTTL functions.

func (Optional[T]) Get added in v0.86.0

func (o Optional[T]) Get() T

func (Optional[T]) IsEmpty added in v0.86.0

func (o Optional[T]) IsEmpty() bool

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

func (p *Parser[K]) ParseCondition(condition string) (*Condition[K], error)

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

func (p *Parser[K]) ParseConditions(conditions []string) ([]*Condition[K], error)

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

func (p *Parser[K]) ParseStatement(statement string) (*Statement[K], error)

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

func (p *Parser[K]) ParseStatements(statements []string) ([]*Statement[K], error)

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 PathExpressionParser

type PathExpressionParser[K any] func(Path[K]) (GetSetter[K], error)

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

type StandardBoolGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardBoolGetter is a basic implementation of BoolGetter

func (StandardBoolGetter[K]) Get added in v0.89.0

func (g StandardBoolGetter[K]) Get(ctx context.Context, tCtx K) (bool, error)

Get retrieves a bool value. If the value is not a bool a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardBoolLikeGetter added in v0.89.0

type StandardBoolLikeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

func (StandardBoolLikeGetter[K]) Get added in v0.89.0

func (g StandardBoolLikeGetter[K]) Get(ctx context.Context, tCtx K) (*bool, error)

type StandardByteSliceLikeGetter added in v0.104.0

type StandardByteSliceLikeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

func (StandardByteSliceLikeGetter[K]) Get added in v0.104.0

func (g StandardByteSliceLikeGetter[K]) Get(ctx context.Context, tCtx K) ([]byte, error)

type StandardDurationGetter added in v0.84.0

type StandardDurationGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardDurationGetter is a basic implementation of DurationGetter

func (StandardDurationGetter[K]) Get added in v0.84.0

func (g StandardDurationGetter[K]) Get(ctx context.Context, tCtx K) (time.Duration, error)

Get retrieves an time.Duration value. If the value is not an time.Duration a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardFloatGetter added in v0.79.0

type StandardFloatGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardFloatGetter is a basic implementation of FloatGetter

func (StandardFloatGetter[K]) Get added in v0.79.0

func (g StandardFloatGetter[K]) Get(ctx context.Context, tCtx K) (float64, error)

Get retrieves a float64 value. If the value is not a float64 a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardFloatLikeGetter added in v0.78.0

type StandardFloatLikeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

func (StandardFloatLikeGetter[K]) Get added in v0.78.0

func (g StandardFloatLikeGetter[K]) Get(ctx context.Context, tCtx K) (*float64, error)

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
}

func (StandardGetSetter[K]) Get

func (path StandardGetSetter[K]) Get(ctx context.Context, tCtx K) (any, error)

func (StandardGetSetter[K]) Set

func (path StandardGetSetter[K]) Set(ctx context.Context, tCtx K, val any) error

type StandardIntGetter added in v0.79.0

type StandardIntGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardIntGetter is a basic implementation of IntGetter

func (StandardIntGetter[K]) Get added in v0.79.0

func (g StandardIntGetter[K]) Get(ctx context.Context, tCtx K) (int64, error)

Get retrieves an int64 value. If the value is not an int64 a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardIntLikeGetter added in v0.78.0

type StandardIntLikeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

func (StandardIntLikeGetter[K]) Get added in v0.78.0

func (g StandardIntLikeGetter[K]) Get(ctx context.Context, tCtx K) (*int64, error)

type StandardPMapGetter added in v0.79.0

type StandardPMapGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardPMapGetter is a basic implementation of PMapGetter

func (StandardPMapGetter[K]) Get added in v0.79.0

func (g StandardPMapGetter[K]) Get(ctx context.Context, tCtx K) (pcommon.Map, error)

Get retrieves a pcommon.Map value. If the value is not a pcommon.Map a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardStringGetter added in v0.79.0

type StandardStringGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardStringGetter is a basic implementation of StringGetter

func (StandardStringGetter[K]) Get added in v0.79.0

func (g StandardStringGetter[K]) Get(ctx context.Context, tCtx K) (string, error)

Get retrieves a string value. If the value is not a string a new TypeError is returned. If there is an error getting the value it will be returned.

type StandardStringLikeGetter added in v0.75.0

type StandardStringLikeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

func (StandardStringLikeGetter[K]) Get added in v0.75.0

func (g StandardStringLikeGetter[K]) Get(ctx context.Context, tCtx K) (*string, error)

type StandardTimeGetter added in v0.85.0

type StandardTimeGetter[K any] struct {
	Getter func(ctx context.Context, tCtx K) (any, error)
}

StandardTimeGetter is a basic implementation of TimeGetter

func (StandardTimeGetter[K]) Get added in v0.85.0

func (g StandardTimeGetter[K]) Get(ctx context.Context, tCtx K) (time.Time, error)

Get retrieves a time.Time value. If the value is not a time.Time, a new TypeError is returned. If there is an error getting the value it will be returned.

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

func (s *Statement[K]) Execute(ctx context.Context, tCtx K) (any, bool, error)

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.

type TimeGetter added in v0.85.0

type TimeGetter[K any] interface {
	// Get retrieves a time.Time value.
	Get(ctx context.Context, tCtx K) (time.Time, error)
}

TimeGetter is a Getter that must return a time.Time.

type TypeError added in v0.80.0

type TypeError string

TypeError represents that a value was not an expected type.

func (TypeError) Error added in v0.80.0

func (t TypeError) Error() string

Jump to

Keyboard shortcuts

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