Skip to content

[pkg/ottl] add Setter for value expression #40484

Open
@kaisecheng

Description

@kaisecheng

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

In signaltometricsconnector, the config accepts OTTL ValueExpression to extract a value from incoming data. For example, user can config resource.attribute["server.address"] to get hostname from log, metric and trace.

However, ValueExpression does not support Setter which means user cannot config resource.attribute["answer"] to save the result to the attribute.

Describe the solution you'd like

Add Setter support to ValueExpression and ParseValueExpression()

type ValueExpression[K any] struct {
	getter Getter[K]
	setter Setter[K]
}

Then, processor can support ValueExpression config for getting and setting an attribute dynamically. Example:

resolve:
  source: resource.attribute["server.hostname"]
  target: resource.attribute["server.ip"]
resolve:
  source: log.body["hostname"]
  target: log.body["ip"]

Describe alternatives you've considered

Without Setter, currently we can use ValueExpression to extract value and config target context and target attribute name to specify the location to store the result.

resolve:
    sources: resource.attributes["hostname"] # Value expressions + context inference (#40194)
    target_context: "resource" # context where the result attribute should be set
    target_attribute: "ip" # new attribute name

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions