Skip to content

[pkg/ottl] OTTL contexts paths are ignoring failed setters executions #40198

@edmocosta

Description

@edmocosta

Component(s)

pkg/ottl

Describe the issue you're reporting

Currently, many OTTL contexts path setters are ignoring the value type assertion failures, which I'm not sure if it was a design decision, or some bad pattern that was copied from one context to another.

For example, the following statements would NOT fail the execution, and IMO, it should, as severity_number must be an int64, and not an string:

log_statements:
 - context: log
   statements:
    - set(severity_number, "bar")

It happens because those paths setters are ignoring type assertion failures, and are not returning any error, making the set operation silently fail:

func accessSeverityNumber[K Context]() ottl.StandardGetSetter[K] {
	return ottl.StandardGetSetter[K]{
                // ...
		Setter: func(_ context.Context, tCtx K, val any) error {
			if i, ok := val.(int64); ok {
				tCtx.GetLogRecord().SetSeverityNumber(plog.SeverityNumber(i))
			}
			return nil
		},
	}
}

I understand that changing this behavior would be a kind of breaking change (noop statements doing that would starting failing). So I'm wondering, Do we have any reason for that work like this? If we don't, I really think we should start fixing them and propagating some error when those set operation fails to execute.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions