open-telemetry / opentelemetry-php

The OpenTelemetry PHP Library
https://opentelemetry.io/docs/instrumentation/php/
Apache License 2.0
752 stars 186 forks source link

[Attribute-based hooking] SpanAttribute example does not align with the declared attribute target #1429

Closed LauJosefsen closed 6 days ago

LauJosefsen commented 2 weeks ago

Hi.

PHPStan will report the error

Attribute class OpenTelemetry\API\Instrumentation\SpanAttribute does not have the parameter target.    

If used as the examples in the readme. It is working, ignoring the stan error, so I think it just needs to be added to the attribute target? I am however not sure if it will break the anything in the extension code to do so.

This occurs with open-telemetry/api^1.1.1, which is as of writing the latest version.

ChrisLightfootWild commented 2 weeks ago

Looks to be the same as this report, in that we are using constructor property promotion and thus facing this complaint.

LauJosefsen commented 2 weeks ago

Ah sorry, I only searched through open issues, as I was sure this was a bug.

Does this mean it is a bug of phpstan and phpstorm to report this as an error?

ChrisLightfootWild commented 2 weeks ago

@LauJosefsen I think we could leave this open and test adding the additional target parameter to see if we can make phpstan happy 👍

mlebrun commented 1 week ago

I almost created another ticket with a Psalm error. I agree, it would be great if the attribute could also target function parameters as that is what the docs recommend the attribute be used for. 🙏

I really appreciate all of the hard work going into the PHP OTEL libraries!