Skip to content

ref: declare expected arguments explicitly instead of varargs - #20

Merged
Litarnus merged 1 commit into
mainfrom
declare-explicit-params
Jul 16, 2026
Merged

ref: declare expected arguments explicitly instead of varargs#20
Litarnus merged 1 commit into
mainfrom
declare-explicit-params

Conversation

@Litarnus

Copy link
Copy Markdown
Collaborator

Update the signature so it contains all expected keys instead of relying on variadic arguments and proper name matching. This will make it easier for tools and humans to reason about the code and will not require reading docs to see what type is required for what.

It also changed the order of parameters. Before this change, it required the class to be the first parameter and the function name as second. While it might make sense from a hierarchical point of view, it does not in terms of requirements.
A class name can be optional (for functions) but it always requires a function name.
A pattern like instrument(null, "foo") was ugly to read, instead having instrument("foo", Bla::class) is perfectly understandable.

The only downside is that one has to write attributes: now before adding span data that couldn't be added through variadic named arguments. For example:

// before
instrument(Bar::class, "foo", ['bla.blub' => 'abc']); 

// after with names
instrument("foo", Bar::class, attributes: ['bla.blub' => 'abc']);

// after without names
instrument("foo", Bar::class, null, null, ['bla.blub' => 'abc']);

Once this PR is merged, it will be strongly encouraged to use named parameters as the list of allowed params will only grow, thus more breaking changes would happen.

@Litarnus
Litarnus merged commit cb70be5 into main Jul 16, 2026
35 checks passed
@Litarnus
Litarnus deleted the declare-explicit-params branch July 16, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant