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

SDK namespace package #55

Merged
merged 9 commits into from
Jul 17, 2019
Merged

SDK namespace package #55

merged 9 commits into from
Jul 17, 2019

Conversation

c24t
Copy link
Member

@c24t c24t commented Jul 16, 2019

This PR adds a stub tracer implementation that depends on the API.

Doing this required some package surgery: moving the opentelemetry package in opentelemetry-api to opentelemetry.api and losing opentelemetry/__init__ modules, making both API and SDK PEP 420 namespace packages.

The result is that you can now install both packages without either clobbering the other and causing import errors.

@reyang let me know if this matches your grand vision for the package structure.

@@ -11,24 +11,32 @@ deps =
mypy: mypy~=0.711

setenv =
PYTHONPATH={toxinidir}/opentelemetry-api/src/
mypy: MYPYPATH={env:PYTHONPATH}
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting PYTHONPATH instead of installing the package was a kludge. It may be possible to get mypy to pass without setting MYPYPATH here, but just installing the packages didn't seem to do it.


changedir =
test: opentelemetry-api/tests
test-api: opentelemetry-api/tests
test-sdk: opentelemetry-sdk/tests
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not want separate test targets in the long run, but this was the easiest way to get test discovery to work since opentelemetry isn't a package (with an __init__.py) anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to remove opentelemetry/__init__.py after we workaround the pylint discovery issue #37 (comment).

commands_pre =
test-api: pip install -e {toxinidir}/opentelemetry-api
test-sdk: pip install -e {toxinidir}/opentelemetry-api
test-sdk: pip install -e {toxinidir}/opentelemetry-sdk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to install these as regular deps so they're not reinstalled on each run. There may be another better way to do this.


commands =
py37-mypy: mypy opentelemetry-api/src/opentelemetry/
mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See python/mypy#1645, mypy fails to find opentelemetry.api without this flag.

@reyang
Copy link
Member

reyang commented Jul 16, 2019

This is different from my understanding. We've discussed that given users are only going to use APIs in their code, it makes more sense to let them use import opentelemetry.trace.foobar instead of import opentelemetry.api.trace.foobar. Maybe I've missed something, which problem did you see @c24t?

Regarding the __init__.py file, it was a temporary thing to unblock tox #37 (comment), would be great to get it removed.

With what we have in the master branch today, installing/uninstall api/sdk package should work:

E:\opentelemetry-python\opentelemetry-api>pip install .
Processing e:\opentelemetry-python\opentelemetry-api
Building wheels for collected packages: opentelemetry-api
  Building wheel for opentelemetry-api (setup.py) ... done
  Stored in directory: C:\Users\reyang\AppData\Local\pip\Cache\wheels\53\5b\1f\5953c7ce944056c8b8062b53185672010c9b07d8bf8b83d62e       
Successfully built opentelemetry-api
Installing collected packages: opentelemetry-api
Successfully installed opentelemetry-api-0.1.dev0

E:\opentelemetry-python\opentelemetry-api>cd ..\opentelemetry-sdk

E:\opentelemetry-python\opentelemetry-sdk>pip install .
Processing e:\opentelemetry-python\opentelemetry-sdk
Building wheels for collected packages: opentelemetry-sdk
  Building wheel for opentelemetry-sdk (setup.py) ... done
  Stored in directory: C:\Users\reyang\AppData\Local\pip\Cache\wheels\49\57\d1\0faf86eb968fb8959880eea93f73520d53b073de7316e7192a       
Successfully built opentelemetry-sdk
Installing collected packages: opentelemetry-sdk
Successfully installed opentelemetry-sdk-0.1.dev0

E:\opentelemetry-python\opentelemetry-sdk>pip uninstall opentelemetry-sdk
Uninstalling opentelemetry-sdk-0.1.dev0:
  Would remove:
    c:\python37\lib\site-packages\opentelemetry\sdk\*
    c:\python37\lib\site-packages\opentelemetry_sdk-0.1.dev0.dist-info\*
Proceed (y/n)? y
  Successfully uninstalled opentelemetry-sdk-0.1.dev0

E:\opentelemetry-python\opentelemetry-sdk>pip uninstall opentelemetry-api
Uninstalling opentelemetry-api-0.1.dev0:
  Would remove:
    c:\python37\lib\site-packages\opentelemetry\*
    c:\python37\lib\site-packages\opentelemetry_api-0.1.dev0.dist-info\*
Proceed (y/n)? y
  Successfully uninstalled opentelemetry-api-0.1.dev0

@c24t
Copy link
Member Author

c24t commented Jul 17, 2019

The problem is that the API package takes over the opentelemetry namespace:

% pip install -e opentelemetry-sdk; python -c "from opentelemetry import sdk"
Obtaining file:///Users/libc/src/opentelemetry-python/opentelemetry-sdk
Installing collected packages: opentelemetry-sdk
  Running setup.py develop for opentelemetry-sdk
Successfully installed opentelemetry-sdk
% pip install -e opentelemetry-api; python -c "from opentelemetry import sdk"
Obtaining file:///Users/libc/src/opentelemetry-python/opentelemetry-api
Installing collected packages: opentelemetry-api
  Running setup.py develop for opentelemetry-api
Successfully installed opentelemetry-api
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'sdk' from 'opentelemetry' (/Users/libc/src/opentelemetry-python/opentelemetry-api/src/opentelemetry/__init__.py)

@reyang
Copy link
Member

reyang commented Jul 17, 2019

This is due to the fact that we haven't removed opentelemetry/__init__.py.
Once we workaround the pylint discovery issue, we're good to remove opentelemetry/__init__.py, then the namespace package will work.

@c24t
Copy link
Member Author

c24t commented Jul 17, 2019

Got it, removed the api package in 2b527fb. Having separate API and SDK test targets seems like a good solution in the meantime.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@c24t c24t merged commit 7a7a207 into open-telemetry:master Jul 17, 2019
@c24t c24t deleted the tracer-sdk-init branch July 17, 2019 23:06
@c24t c24t mentioned this pull request Jul 26, 2019
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
* Add Propagation interface

* minor doc fix

* Rename interface Propagation to Propagator
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.

2 participants