Skip to content

Conversation

@jsvd
Copy link
Contributor

@jsvd jsvd commented Dec 10, 2025

Description

Setters in OTTL contexts now validate that values are of the expected type and return descriptive errors when type mismatches occur, improving debugging experience. This is the continuation of work done in #43505, addressing remaining context such as datapoint, profile, resource, span, and span event.

Link to tracking issue

Completes the fix to #40198, part 1 was #43505.

Testing

Tests were adapted to conform to the new error statements. New tests were not added given the simplicity of where ctxutil.ExpectType is applied to and given ctxutil.ExpectType itself was added with proper tests. Introducing tests for each setter would just be a large amount of code duplication, testing the exact same code pattern over and over.

Note for reviewer

This PR is likely best reviewed without whitespace taken into consideration since most of the changes convert a block like

			if v, ok := val.(Type); ok {
				// instruction
			}

into

			v, err := ctxutil.ExpectType[Type](val)
			if err != nil {
				return err
			}
			// instruction

where any instruction or set of instructions will always be indented left after the refactor.

While it improves overall readability by putting the happy path logic outside a conditional, it makes reviewing the PR harder by touching a lot of code just for indentation.

Setters in OTTL contexts now validate that values are of the expected type and return
descriptive errors when type mismatches occur, improving debugging experience.
This is the continuation of work done in open-telemetry#43505, addressing remaining context such
as datapoint, profile, resource, span, and span event.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants