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

OpenTelemetry symbols marked private to pyright #2455

Open
quom opened this issue Oct 18, 2023 · 11 comments
Open

OpenTelemetry symbols marked private to pyright #2455

quom opened this issue Oct 18, 2023 · 11 comments
Labels
Enhancement New feature or request Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest! Triaged Has been looked at recently during old issue triage

Comments

@quom
Copy link

quom commented Oct 18, 2023

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.32.0

Steps to Reproduce

  • Use pyright
  • Import from opentelemetry package:
from sentry_sdk.integrations.opentelemetry import SentryPropagator, SentrySpanProcessor
  • pyright error:
error: "SentryPropagator" is not exported from module "sentry_sdk.integrations.opentelemetry"
    Import from "sentry_sdk.integrations.opentelemetry.propagator" instead (reportPrivateImportUsage)
error: "SentrySpanProcessor" is not exported from module "sentry_sdk.integrations.opentelemetry"
    Import from "sentry_sdk.integrations.opentelemetry.span_processor" instead (reportPrivateImportUsage)

Expected Result

Import without pyright errors

Actual Result

Errors as above.

By changing the imports to be more specific pyright would pass but this is not in the documentation:

from sentry_sdk.integrations.opentelemetry.propagator import SentryPropagator
from sentry_sdk.integrations.opentelemetry.span_processor import SentrySpanProcessor
@sentrivana
Copy link
Contributor

Hey @quom, thanks for bringing this to our attention. We don't check our code with pyright so we weren't aware of this.

This needs a bit of looking into how to tell pyright those are not private imports. Based on my very brief investigation adding an __all__ to the __init__.py could do the trick. Some related issues I found, for the reference:

@sentrivana sentrivana added Enhancement New feature or request Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest! labels Oct 18, 2023
@khuongduy354
Copy link

Is this issue assigned ?

@sentrivana
Copy link
Contributor

@khuongduy354 No, it's up for grabs!

@khuongduy354
Copy link

khuongduy354 commented Oct 23, 2023

I know this may be a beginner question, my project cant find Open Telemetry package, i followed this guide here: https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md, import sentry_sdk.integrations works, and i checked there's a init.py in opentelemtry folder (so it's a package). Don't know why it cant be found.
This is the full error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/khuongduy354/developments/ongoing/sentry-python/sentry_sdk/integrations/opentelemetry/__init__.py", line 1, in <module>
    from sentry_sdk.integrations.opentelemetry.span_processor import (  # noqa: F401
  File "/home/khuongduy354/developments/ongoing/sentry-python/sentry_sdk/integrations/opentelemetry/span_processor.py", line 3, in <module>
    from opentelemetry.context import get_value  # type: ignore
ModuleNotFoundError: No module named 'opentelemetry'

@sentrivana
Copy link
Contributor

@khuongduy354 The error is a bit misleading, it's complaining about not being able to import opentelemetry the third-party dependency, as opposed to something in the SDK. Do you have the opentelemetry-distro package installed? Running pip install 'opentelemetry-distro>=0.35b0' should do the trick.

@khuongduy354
Copy link

image
Pyright doesn't yield error with the original code. I don't use pyright, so i don't know if i reproduced the issue correctly.
What i did was pip install pyright , then try importing things from opentelemetry as above. Then run pyright testpy.py, no error pops up

@sentrivana
Copy link
Contributor

Tried to repro too, also unsuccessfully. @quom could you help us out with more details on how you installed and ran pyright and what version you're using? I have pyright==1.1.332 and I'm not seeing the reportPrivateImportUsage errors.

@quom
Copy link
Author

quom commented Oct 24, 2023

$ pyright --version
pyright 1.1.332

$ pyright tracing.py 
tracing.py
tracing.py:16:51 - error: "SentryPropagator" is not exported from module "sentry_sdk.integrations.opentelemetry"
    Import from "sentry_sdk.integrations.opentelemetry.propagator" instead (reportPrivateImportUsage)
tracing.py:16:69 - error: "SentrySpanProcessor" is not exported from module "sentry_sdk.integrations.opentelemetry"
    Import from "sentry_sdk.integrations.opentelemetry.span_processor" instead (reportPrivateImportUsage)
2 errors, 0 warnings, 0 informations 

I can see why it is creating the error as per the spec for typed libraries. Are you using the normal sentry_sdk package install or a local dev dependency of it? There may be different behaviour depending on how the package is installed in your environment.

@khuongduy354
Copy link

Maybe a local dev dependency. I followed setup here: https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md. Which is pip install in editable mode

@quom
Copy link
Author

quom commented Oct 24, 2023

I'm not exactly sure why pyright might not be reproducing it on your side (can't see anything specific about local dependencies that may be different). Here is an example of a package's __init__.py that explicitly defines the exports though: https://github.com/litestar-org/litestar/blob/main/litestar/middleware/__init__.py

@khuongduy354
Copy link

Does adding add to init.py in your telemetry fix the issue on your machine?

@sentrivana sentrivana added the Triaged Has been looked at recently during old issue triage label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Good first issue Good for newcomers Hacktoberfest 🎃 Issues eligible for Hacktoberfest! Triaged Has been looked at recently during old issue triage
Projects
Status: No status
Development

No branches or pull requests

4 participants