Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing issue with start_as_current_span #3836

Open
PietroPasotti opened this issue Apr 5, 2024 · 8 comments
Open

typing issue with start_as_current_span #3836

PietroPasotti opened this issue Apr 5, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@PietroPasotti
Copy link

I suspect #3633 broke type checkers' ability to inspect the signature of start_as_current_span.

Describe your environment
python 3.11
opentelemetry-exporter-otlp-proto-http==1.24.0
pyright==1.1.331

Steps to reproduce
run pyright on code using tracer.start_as_current_span(name) or tracer.start_as_current_span(name=name)

What is the expected behavior?
nothing :)

What is the actual behavior?
error: No parameter named "name" (reportGeneralTypeIssues)
or
error: Expected 0 positional arguments (reportGeneralTypeIssues)

Additional context
Probably introduced by #3633

@PietroPasotti PietroPasotti added the bug Something isn't working label Apr 5, 2024
@xrmx
Copy link
Contributor

xrmx commented Apr 5, 2024

@PietroPasotti thanks for reporting, any idea on how to fix that?

@PietroPasotti
Copy link
Author

Sorry but no, I looked a bit into it but I'm not familiar enough with ParamSpec to be useful. Will take another look if I have time next week.

@pmcollins
Copy link
Member

@PietroPasotti do you get the error when you run pyright against docs/examples/auto-instrumentation/client.py on latest main? I'm getting a different error, but not one for start_as_current_span:

auto-instrumentation % pyright client.py
/Users/x/python/open-telemetry/opentelemetry-python/docs/examples/auto-instrumentation/client.py
  /Users/x/python/open-telemetry/opentelemetry-python/docs/examples/auto-instrumentation/client.py:30:29 - error: Cannot access member "add_span_processor" for type "TracerProvider"
    Member "add_span_processor" is unknown (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations 

@jenshnielsen
Copy link
Contributor

@PietroPasotti does this happen for you with 3.11. I am seeing a similar issue with 3.9 and older microsoft/Qcodes#5899

I believe the 3.9 issue is caused by typing.ParamSpec not existing on 3.9 which results in the type effectivly just being a string that would never type check with 3.9. Normally I would suggest that opentelemetry should depend on typing_extensions and use the backported version for older python versions but I am not sure if that is against some policy?

For 3.11 I guess it could be an issue specific to an older patch version. Which exact version are you running? I think there may have been some fixes to paramspec in the patch versions. Note also that the version of pyright that you are using is fairly old. Latest version is 1.1.358. Could you try with a newer one?

@PietroPasotti
Copy link
Author

tried with pyright 1.1.358, the error is different but on the same line.
Now it gives:

error: Expected 0 positional arguments (reportCallIssue)

on tracer.start_as_current_span(name)

@PietroPasotti
Copy link
Author

PietroPasotti commented Apr 15, 2024

Modifying the source to import ParamSpec from typing_extensions fixes it.
that's obviously not a solution for the issue, but it might be useful debugging info :)

@jenshnielsen
Copy link
Contributor

@PietroPasotti Which exact version of python 3.11 are you using. Looks like there were bugfixes to Paramspec in 3.11.1 and 3.11.3
which may be the reason

https://docs.python.org/release/3.11.9/whatsnew/changelog.html#python-3-11-9

@PietroPasotti
Copy link
Author

3.11.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants