From de56e3e76a4a73cd2c0f78eb08bb2a5138fc9501 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 13:26:27 -0700 Subject: [PATCH 1/9] Add api namespace, shuffle packages to allow access to both opentelemetry.api and opentelemetry.sdk via namespace packages. --- opentelemetry-api/setup.py | 4 ++-- .../{resources => api}/__init__.py | 6 ++++++ .../{ => api/context}/__init__.py | 0 .../distributedcontext}/__init__.py | 0 .../src/opentelemetry/{ => api}/loader.py | 0 .../logs}/__init__.py | 0 .../{logs => api/metrics}/__init__.py | 0 .../{metrics => api/resources}/__init__.py | 0 .../opentelemetry/{ => api}/trace/__init__.py | 2 +- .../{internal => api}/version.py | 0 .../src/opentelemetry/internal/__init__.py | 19 ------------------- opentelemetry-api/tests/test_loader.py | 4 ++-- opentelemetry-sdk/setup.py | 2 +- .../src/opentelemetry/sdk/__init__.py | 6 +++++- 14 files changed, 17 insertions(+), 26 deletions(-) rename opentelemetry-api/src/opentelemetry/{resources => api}/__init__.py (92%) rename opentelemetry-api/src/opentelemetry/{ => api/context}/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{context => api/distributedcontext}/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{ => api}/loader.py (100%) rename opentelemetry-api/src/opentelemetry/{distributedcontext => api/logs}/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{logs => api/metrics}/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{metrics => api/resources}/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{ => api}/trace/__init__.py (99%) rename opentelemetry-api/src/opentelemetry/{internal => api}/version.py (100%) delete mode 100644 opentelemetry-api/src/opentelemetry/internal/__init__.py diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index d2a27a0d442..36bb59ec7e7 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(__file__) VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "internal", "version.py") + BASE_DIR, "src", "opentelemetry", "api", "version.py") PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used @@ -47,7 +47,7 @@ extras_require={}, license="Apache-2.0", package_dir={"": "src"}, - packages=setuptools.find_namespace_packages(where="src"), + packages=setuptools.find_namespace_packages(where="src", include="opentelemetry.api.*"), url=("https://github.com/open-telemetry/opentelemetry-python" "/tree/master/opentelemetry-api"), zip_safe=False, diff --git a/opentelemetry-api/src/opentelemetry/resources/__init__.py b/opentelemetry-api/src/opentelemetry/api/__init__.py similarity index 92% rename from opentelemetry-api/src/opentelemetry/resources/__init__.py rename to opentelemetry-api/src/opentelemetry/api/__init__.py index d853a7bcf65..4978ec7226b 100644 --- a/opentelemetry-api/src/opentelemetry/resources/__init__.py +++ b/opentelemetry-api/src/opentelemetry/api/__init__.py @@ -11,3 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from . import trace + +__all__ = [ + "trace", +] diff --git a/opentelemetry-api/src/opentelemetry/__init__.py b/opentelemetry-api/src/opentelemetry/api/context/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/__init__.py rename to opentelemetry-api/src/opentelemetry/api/context/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/api/distributedcontext/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/context/__init__.py rename to opentelemetry-api/src/opentelemetry/api/distributedcontext/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/loader.py b/opentelemetry-api/src/opentelemetry/api/loader.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/loader.py rename to opentelemetry-api/src/opentelemetry/api/loader.py diff --git a/opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py b/opentelemetry-api/src/opentelemetry/api/logs/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py rename to opentelemetry-api/src/opentelemetry/api/logs/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/logs/__init__.py b/opentelemetry-api/src/opentelemetry/api/metrics/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/logs/__init__.py rename to opentelemetry-api/src/opentelemetry/api/metrics/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/metrics/__init__.py b/opentelemetry-api/src/opentelemetry/api/resources/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/metrics/__init__.py rename to opentelemetry-api/src/opentelemetry/api/resources/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/api/trace/__init__.py similarity index 99% rename from opentelemetry-api/src/opentelemetry/trace/__init__.py rename to opentelemetry-api/src/opentelemetry/api/trace/__init__.py index d5fd5446a48..d38867844b1 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/api/trace/__init__.py @@ -65,7 +65,7 @@ from contextlib import contextmanager import typing -from opentelemetry import loader +from opentelemetry.api import loader class Span: diff --git a/opentelemetry-api/src/opentelemetry/internal/version.py b/opentelemetry-api/src/opentelemetry/api/version.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/internal/version.py rename to opentelemetry-api/src/opentelemetry/api/version.py diff --git a/opentelemetry-api/src/opentelemetry/internal/__init__.py b/opentelemetry-api/src/opentelemetry/internal/__init__.py deleted file mode 100644 index 83ac009440a..00000000000 --- a/opentelemetry-api/src/opentelemetry/internal/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2019, OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from .version import __version__ - -__all__ = [ - "__version__", -] diff --git a/opentelemetry-api/tests/test_loader.py b/opentelemetry-api/tests/test_loader.py index 68809468f5d..904c8dcc801 100644 --- a/opentelemetry-api/tests/test_loader.py +++ b/opentelemetry-api/tests/test_loader.py @@ -17,8 +17,8 @@ import sys import unittest -from opentelemetry import loader -from opentelemetry import trace +from opentelemetry.api import loader +from opentelemetry.api import trace DUMMY_TRACER = None diff --git a/opentelemetry-sdk/setup.py b/opentelemetry-sdk/setup.py index b95fecb27a9..64bd175f7fe 100644 --- a/opentelemetry-sdk/setup.py +++ b/opentelemetry-sdk/setup.py @@ -45,7 +45,7 @@ extras_require={}, license="Apache-2.0", package_dir={"": "src"}, - packages=setuptools.find_namespace_packages(where="src"), + packages=setuptools.find_namespace_packages(where="src", include="opentelemetry.sdk.*"), url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-sdk", zip_safe=False, ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/__init__.py index 2d52388da33..4978ec7226b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/__init__.py @@ -12,4 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .version import __version__ +from . import trace + +__all__ = [ + "trace", +] From 10a69b6fc603c2446a5ef9e954854ca9b3675b79 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 13:43:58 -0700 Subject: [PATCH 2/9] Make setup files consistent and make SDK package depend on API. --- opentelemetry-api/setup.py | 11 ++++++----- opentelemetry-sdk/setup.py | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index 36bb59ec7e7..746483d0490 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -16,15 +16,15 @@ import setuptools BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "api", "version.py") +VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "api", + "version.py") PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: - exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used + exec(f.read(), PACKAGE_INFO) setuptools.setup( name="opentelemetry-api", - version=PACKAGE_INFO["__version__"], # noqa + version=PACKAGE_INFO["__version__"], author="OpenTelemetry Authors", author_email="cncf-opentelemetry-contributors@lists.cncf.io", classifiers=[ @@ -47,7 +47,8 @@ extras_require={}, license="Apache-2.0", package_dir={"": "src"}, - packages=setuptools.find_namespace_packages(where="src", include="opentelemetry.api.*"), + packages=setuptools.find_namespace_packages(where="src", + include="opentelemetry.api.*"), url=("https://github.com/open-telemetry/opentelemetry-python" "/tree/master/opentelemetry-api"), zip_safe=False, diff --git a/opentelemetry-sdk/setup.py b/opentelemetry-sdk/setup.py index 64bd175f7fe..a6e62114e0d 100644 --- a/opentelemetry-sdk/setup.py +++ b/opentelemetry-sdk/setup.py @@ -15,15 +15,16 @@ import os import setuptools -base_dir = os.path.dirname(__file__) - -package_info = {} -with open(os.path.join(base_dir, "src", "opentelemetry", "sdk", "version.py")) as f: - exec(f.read(), package_info) +BASE_DIR = os.path.dirname(__file__) +VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "sdk", + "version.py") +PACKAGE_INFO = {} +with open(VERSION_FILENAME) as f: + exec(f.read(), PACKAGE_INFO) setuptools.setup( name="opentelemetry-sdk", - version=package_info["__version__"], # noqa + version=PACKAGE_INFO["__version__"], author="OpenTelemetry Authors", author_email="cncf-opentelemetry-contributors@lists.cncf.io", classifiers=[ @@ -41,11 +42,14 @@ include_package_data=True, long_description=open("README.rst").read(), install_requires=[ + "opentelemetry-api==0.1.dev0" ], extras_require={}, license="Apache-2.0", package_dir={"": "src"}, - packages=setuptools.find_namespace_packages(where="src", include="opentelemetry.sdk.*"), - url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-sdk", + packages=setuptools.find_namespace_packages(where="src", + include="opentelemetry.sdk.*"), + url=("https://github.com/open-telemetry/opentelemetry-python" + "/tree/master/opentelemetry-sdk"), zip_safe=False, ) From e7fe15f4bdc7f04a5ea36e806d932b1ae971dc6a Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 14:24:52 -0700 Subject: [PATCH 3/9] Update toxfile for SDK tests --- tox.ini | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tox.ini b/tox.ini index 085d260c260..3f78c83a106 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] skipsdist = True -envlist = py{34,35,36,37}-test, lint, py37-mypy, docs +envlist = py{34,35,36,37}-test-{api,sdk}, lint, py37-mypy, docs [travis] python = @@ -10,18 +10,20 @@ python = deps = mypy: mypy~=0.711 -setenv = - PYTHONPATH={toxinidir}/opentelemetry-api/src/ - mypy: MYPYPATH={env:PYTHONPATH} - changedir = - test: opentelemetry-api/tests + test-api: opentelemetry-api/tests + test-sdk: opentelemetry-sdk/tests + +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 commands = py37-mypy: mypy opentelemetry-api/src/opentelemetry/ ; For test code, we don't want to enforce the full mypy strictness py37-mypy: mypy --config-file=mypy-relaxed.ini opentelemetry-api/tests/ opentelemetry-api/setup.py - test: python -m unittest discover + test-{api,sdk}: python -m unittest discover [testenv:lint] deps = From 5965d98cc1459acc741858709a17d52c82134723 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 14:44:54 -0700 Subject: [PATCH 4/9] Add API, SDK tox test targets and fix mypy cmd --- tox.ini | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 3f78c83a106..cb52ddca98e 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,9 @@ python = deps = mypy: mypy~=0.711 +setenv = + mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/ + changedir = test-api: opentelemetry-api/tests test-sdk: opentelemetry-sdk/tests @@ -20,9 +23,9 @@ commands_pre = test-sdk: pip install -e {toxinidir}/opentelemetry-sdk commands = - py37-mypy: mypy opentelemetry-api/src/opentelemetry/ + mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/ ; For test code, we don't want to enforce the full mypy strictness - py37-mypy: mypy --config-file=mypy-relaxed.ini opentelemetry-api/tests/ opentelemetry-api/setup.py + mypy: mypy --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/ test-{api,sdk}: python -m unittest discover [testenv:lint] From 31952de97a9bb58255770c54f1608c43a5f26f71 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 15:01:19 -0700 Subject: [PATCH 5/9] Update docs for package move --- docs/index.rst | 4 ++-- docs/opentelemetry.api.loader.rst | 4 ++++ docs/opentelemetry.api.trace.rst | 4 ++++ docs/opentelemetry.loader.rst | 4 ---- docs/opentelemetry.trace.rst | 4 ---- opentelemetry-api/src/opentelemetry/api/loader.py | 14 +++++++------- .../src/opentelemetry/api/trace/__init__.py | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 docs/opentelemetry.api.loader.rst create mode 100644 docs/opentelemetry.api.trace.rst delete mode 100644 docs/opentelemetry.loader.rst delete mode 100644 docs/opentelemetry.trace.rst diff --git a/docs/index.rst b/docs/index.rst index 90385dba4a9..dc3b6b1f4a0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,8 +15,8 @@ abstract types for OpenTelemetry implementations. :maxdepth: 1 :caption: Contents: - opentelemetry.trace - opentelemetry.loader + opentelemetry.api.trace + opentelemetry.api.loader Indices and tables diff --git a/docs/opentelemetry.api.loader.rst b/docs/opentelemetry.api.loader.rst new file mode 100644 index 00000000000..3c9c8bd3973 --- /dev/null +++ b/docs/opentelemetry.api.loader.rst @@ -0,0 +1,4 @@ +opentelemetry.api.loader module +=============================== + +.. automodule:: opentelemetry.api.loader diff --git a/docs/opentelemetry.api.trace.rst b/docs/opentelemetry.api.trace.rst new file mode 100644 index 00000000000..08905534910 --- /dev/null +++ b/docs/opentelemetry.api.trace.rst @@ -0,0 +1,4 @@ +opentelemetry.api.trace package +=============================== + +.. automodule:: opentelemetry.api.trace diff --git a/docs/opentelemetry.loader.rst b/docs/opentelemetry.loader.rst deleted file mode 100644 index bd6dd698f8b..00000000000 --- a/docs/opentelemetry.loader.rst +++ /dev/null @@ -1,4 +0,0 @@ -opentelemetry.loader module -=========================== - -.. automodule:: opentelemetry.loader diff --git a/docs/opentelemetry.trace.rst b/docs/opentelemetry.trace.rst deleted file mode 100644 index cec44bd8178..00000000000 --- a/docs/opentelemetry.trace.rst +++ /dev/null @@ -1,4 +0,0 @@ -opentelemetry.trace package -=========================== - -.. automodule:: opentelemetry.trace diff --git a/opentelemetry-api/src/opentelemetry/api/loader.py b/opentelemetry-api/src/opentelemetry/api/loader.py index cf2069edb42..ff3cea85bb5 100644 --- a/opentelemetry-api/src/opentelemetry/api/loader.py +++ b/opentelemetry-api/src/opentelemetry/api/loader.py @@ -15,7 +15,7 @@ """ The OpenTelemetry loader module is mainly used internally to load the -implementation for global objects like :func:`opentelemetry.trace.tracer`. +implementation for global objects like :func:`opentelemetry.api.trace.tracer`. .. _loader-factory: @@ -27,9 +27,9 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]: That function is called with e.g., the type of the global object it should create as an argument (e.g. the type object -:class:`opentelemetry.trace.Tracer`) and should return an instance of that type -(such that ``instanceof(my_factory_for_t(T), T)`` is true). Alternatively, it -may return ``None`` to indicate that the no-op default should be used. +:class:`opentelemetry.api.trace.Tracer`) and should return an instance of that +type (such that ``instanceof(my_factory_for_t(T), T)`` is true). Alternatively, +it may return ``None`` to indicate that the no-op default should be used. When loading an implementation, the following algorithm is used to find a factory function or other means to create the global object: @@ -43,9 +43,9 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]: variable ``OPENTELEMETRY_PYTHON_IMPLEMENTATION_DEFAULT``. 3. Otherwise, if a :samp:`set_preferred_{}_implementation` was called (e.g. - :func:`opentelemetry.trace.set_preferred_tracer_implementation`), the - callback set there is used (that is, the environment variables override - the callback set in code). + :func:`opentelemetry.api.trace.set_preferred_tracer_implementation`), + the callback set there is used (that is, the environment variables + override the callback set in code). 4. Otherwise, if :func:`set_preferred_default_implementation` was called, the callback set there is used. 5. Otherwise, an attempt is made to import and use the OpenTelemetry SDK. diff --git a/opentelemetry-api/src/opentelemetry/api/trace/__init__.py b/opentelemetry-api/src/opentelemetry/api/trace/__init__.py index d38867844b1..2a31186ddf4 100644 --- a/opentelemetry-api/src/opentelemetry/api/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/api/trace/__init__.py @@ -328,7 +328,7 @@ def set_preferred_tracer_implementation( ) -> None: """Set the factory to be used to create the tracer. - See :mod:`opentelemetry.loader` for details. + See :mod:`opentelemetry.api.loader` for details. This function may not be called after a tracer is already loaded. From de3964934dcbb62259e97f76282e86d166256134 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 15:01:39 -0700 Subject: [PATCH 6/9] Install API package for lint check --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index cb52ddca98e..f9761bcc01e 100644 --- a/tox.ini +++ b/tox.ini @@ -34,6 +34,9 @@ deps = flake8~=3.7 isort~=4.3 +commands_pre = + pip install -e {toxinidir}/opentelemetry-api + commands = ; Prefer putting everything in one pylint command to profit from duplication ; warnings. From 8827a38e2be31a742f6e358ac94463e920667712 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 16 Jul 2019 15:04:12 -0700 Subject: [PATCH 7/9] Add stub tracer SDK and test --- .../src/opentelemetry/sdk/trace/__init__.py | 20 +++++++++++++++ opentelemetry-sdk/tests/__init__.py | 13 ++++++++++ opentelemetry-sdk/tests/trace/__init__.py | 13 ++++++++++ opentelemetry-sdk/tests/trace/test_trace.py | 25 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py create mode 100644 opentelemetry-sdk/tests/__init__.py create mode 100644 opentelemetry-sdk/tests/trace/__init__.py create mode 100644 opentelemetry-sdk/tests/trace/test_trace.py diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py new file mode 100644 index 00000000000..97bda720f15 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from opentelemetry import api + + +class Tracer(api.trace.Tracer): + pass + diff --git a/opentelemetry-sdk/tests/__init__.py b/opentelemetry-sdk/tests/__init__.py new file mode 100644 index 00000000000..d853a7bcf65 --- /dev/null +++ b/opentelemetry-sdk/tests/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/opentelemetry-sdk/tests/trace/__init__.py b/opentelemetry-sdk/tests/trace/__init__.py new file mode 100644 index 00000000000..d853a7bcf65 --- /dev/null +++ b/opentelemetry-sdk/tests/trace/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py new file mode 100644 index 00000000000..ec1275905e9 --- /dev/null +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -0,0 +1,25 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from opentelemetry import api +from opentelemetry.sdk import trace + + +class TestTracer(unittest.TestCase): + + def test_extends_api(self): + tracer = trace.Tracer() + self.assertIsInstance(tracer, api.trace.Tracer) From 2b527fbc58307d72bd5b33d7ca95e80985828e5e Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Wed, 17 Jul 2019 13:11:19 -0700 Subject: [PATCH 8/9] Revert API subpackage move --- docs/index.rst | 4 ++-- docs/opentelemetry.api.loader.rst | 4 ---- docs/opentelemetry.api.trace.rst | 4 ---- docs/opentelemetry.loader.rst | 4 ++++ docs/opentelemetry.trace.rst | 4 ++++ opentelemetry-api/setup.py | 5 ++--- .../src/opentelemetry/api/__init__.py | 19 ------------------- .../{api => }/context/__init__.py | 0 .../{api => }/distributedcontext/__init__.py | 0 .../src/opentelemetry/{api => }/loader.py | 14 +++++++------- .../opentelemetry/{api => }/logs/__init__.py | 0 .../{api => }/metrics/__init__.py | 0 .../{api => }/resources/__init__.py | 0 .../opentelemetry/{api => }/trace/__init__.py | 4 ++-- .../src/opentelemetry/{api => }/version.py | 0 opentelemetry-api/tests/test_loader.py | 4 ++-- .../src/opentelemetry/sdk/trace/__init__.py | 5 ++--- opentelemetry-sdk/tests/trace/test_trace.py | 4 ++-- 18 files changed, 27 insertions(+), 48 deletions(-) delete mode 100644 docs/opentelemetry.api.loader.rst delete mode 100644 docs/opentelemetry.api.trace.rst create mode 100644 docs/opentelemetry.loader.rst create mode 100644 docs/opentelemetry.trace.rst delete mode 100644 opentelemetry-api/src/opentelemetry/api/__init__.py rename opentelemetry-api/src/opentelemetry/{api => }/context/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{api => }/distributedcontext/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{api => }/loader.py (92%) rename opentelemetry-api/src/opentelemetry/{api => }/logs/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{api => }/metrics/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{api => }/resources/__init__.py (100%) rename opentelemetry-api/src/opentelemetry/{api => }/trace/__init__.py (99%) rename opentelemetry-api/src/opentelemetry/{api => }/version.py (100%) diff --git a/docs/index.rst b/docs/index.rst index dc3b6b1f4a0..90385dba4a9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,8 +15,8 @@ abstract types for OpenTelemetry implementations. :maxdepth: 1 :caption: Contents: - opentelemetry.api.trace - opentelemetry.api.loader + opentelemetry.trace + opentelemetry.loader Indices and tables diff --git a/docs/opentelemetry.api.loader.rst b/docs/opentelemetry.api.loader.rst deleted file mode 100644 index 3c9c8bd3973..00000000000 --- a/docs/opentelemetry.api.loader.rst +++ /dev/null @@ -1,4 +0,0 @@ -opentelemetry.api.loader module -=============================== - -.. automodule:: opentelemetry.api.loader diff --git a/docs/opentelemetry.api.trace.rst b/docs/opentelemetry.api.trace.rst deleted file mode 100644 index 08905534910..00000000000 --- a/docs/opentelemetry.api.trace.rst +++ /dev/null @@ -1,4 +0,0 @@ -opentelemetry.api.trace package -=============================== - -.. automodule:: opentelemetry.api.trace diff --git a/docs/opentelemetry.loader.rst b/docs/opentelemetry.loader.rst new file mode 100644 index 00000000000..bd6dd698f8b --- /dev/null +++ b/docs/opentelemetry.loader.rst @@ -0,0 +1,4 @@ +opentelemetry.loader module +=========================== + +.. automodule:: opentelemetry.loader diff --git a/docs/opentelemetry.trace.rst b/docs/opentelemetry.trace.rst new file mode 100644 index 00000000000..cec44bd8178 --- /dev/null +++ b/docs/opentelemetry.trace.rst @@ -0,0 +1,4 @@ +opentelemetry.trace package +=========================== + +.. automodule:: opentelemetry.trace diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index 746483d0490..abf71aa63d5 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -16,8 +16,7 @@ import setuptools BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "api", - "version.py") +VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "version.py") PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) @@ -48,7 +47,7 @@ license="Apache-2.0", package_dir={"": "src"}, packages=setuptools.find_namespace_packages(where="src", - include="opentelemetry.api.*"), + include="opentelemetry.*"), url=("https://github.com/open-telemetry/opentelemetry-python" "/tree/master/opentelemetry-api"), zip_safe=False, diff --git a/opentelemetry-api/src/opentelemetry/api/__init__.py b/opentelemetry-api/src/opentelemetry/api/__init__.py deleted file mode 100644 index 4978ec7226b..00000000000 --- a/opentelemetry-api/src/opentelemetry/api/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2019, OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from . import trace - -__all__ = [ - "trace", -] diff --git a/opentelemetry-api/src/opentelemetry/api/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/context/__init__.py rename to opentelemetry-api/src/opentelemetry/context/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/api/distributedcontext/__init__.py b/opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/distributedcontext/__init__.py rename to opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/api/loader.py b/opentelemetry-api/src/opentelemetry/loader.py similarity index 92% rename from opentelemetry-api/src/opentelemetry/api/loader.py rename to opentelemetry-api/src/opentelemetry/loader.py index ff3cea85bb5..cf2069edb42 100644 --- a/opentelemetry-api/src/opentelemetry/api/loader.py +++ b/opentelemetry-api/src/opentelemetry/loader.py @@ -15,7 +15,7 @@ """ The OpenTelemetry loader module is mainly used internally to load the -implementation for global objects like :func:`opentelemetry.api.trace.tracer`. +implementation for global objects like :func:`opentelemetry.trace.tracer`. .. _loader-factory: @@ -27,9 +27,9 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]: That function is called with e.g., the type of the global object it should create as an argument (e.g. the type object -:class:`opentelemetry.api.trace.Tracer`) and should return an instance of that -type (such that ``instanceof(my_factory_for_t(T), T)`` is true). Alternatively, -it may return ``None`` to indicate that the no-op default should be used. +:class:`opentelemetry.trace.Tracer`) and should return an instance of that type +(such that ``instanceof(my_factory_for_t(T), T)`` is true). Alternatively, it +may return ``None`` to indicate that the no-op default should be used. When loading an implementation, the following algorithm is used to find a factory function or other means to create the global object: @@ -43,9 +43,9 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]: variable ``OPENTELEMETRY_PYTHON_IMPLEMENTATION_DEFAULT``. 3. Otherwise, if a :samp:`set_preferred_{}_implementation` was called (e.g. - :func:`opentelemetry.api.trace.set_preferred_tracer_implementation`), - the callback set there is used (that is, the environment variables - override the callback set in code). + :func:`opentelemetry.trace.set_preferred_tracer_implementation`), the + callback set there is used (that is, the environment variables override + the callback set in code). 4. Otherwise, if :func:`set_preferred_default_implementation` was called, the callback set there is used. 5. Otherwise, an attempt is made to import and use the OpenTelemetry SDK. diff --git a/opentelemetry-api/src/opentelemetry/api/logs/__init__.py b/opentelemetry-api/src/opentelemetry/logs/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/logs/__init__.py rename to opentelemetry-api/src/opentelemetry/logs/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/api/metrics/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/metrics/__init__.py rename to opentelemetry-api/src/opentelemetry/metrics/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/api/resources/__init__.py b/opentelemetry-api/src/opentelemetry/resources/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/resources/__init__.py rename to opentelemetry-api/src/opentelemetry/resources/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/api/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py similarity index 99% rename from opentelemetry-api/src/opentelemetry/api/trace/__init__.py rename to opentelemetry-api/src/opentelemetry/trace/__init__.py index 2a31186ddf4..d5fd5446a48 100644 --- a/opentelemetry-api/src/opentelemetry/api/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -65,7 +65,7 @@ from contextlib import contextmanager import typing -from opentelemetry.api import loader +from opentelemetry import loader class Span: @@ -328,7 +328,7 @@ def set_preferred_tracer_implementation( ) -> None: """Set the factory to be used to create the tracer. - See :mod:`opentelemetry.api.loader` for details. + See :mod:`opentelemetry.loader` for details. This function may not be called after a tracer is already loaded. diff --git a/opentelemetry-api/src/opentelemetry/api/version.py b/opentelemetry-api/src/opentelemetry/version.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/api/version.py rename to opentelemetry-api/src/opentelemetry/version.py diff --git a/opentelemetry-api/tests/test_loader.py b/opentelemetry-api/tests/test_loader.py index 904c8dcc801..68809468f5d 100644 --- a/opentelemetry-api/tests/test_loader.py +++ b/opentelemetry-api/tests/test_loader.py @@ -17,8 +17,8 @@ import sys import unittest -from opentelemetry.api import loader -from opentelemetry.api import trace +from opentelemetry import loader +from opentelemetry import trace DUMMY_TRACER = None diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 97bda720f15..ca6f173dcb7 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opentelemetry import api +from opentelemetry import trace as trace_api -class Tracer(api.trace.Tracer): +class Tracer(trace_api.Tracer): pass - diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index ec1275905e9..7f6380e0ed4 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -14,7 +14,7 @@ import unittest -from opentelemetry import api +from opentelemetry import trace as trace_api from opentelemetry.sdk import trace @@ -22,4 +22,4 @@ class TestTracer(unittest.TestCase): def test_extends_api(self): tracer = trace.Tracer() - self.assertIsInstance(tracer, api.trace.Tracer) + self.assertIsInstance(tracer, trace_api.Tracer) From 3d29bb1adc6540755b50d9b4a3e93a97ad40ccae Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Wed, 17 Jul 2019 13:18:09 -0700 Subject: [PATCH 9/9] Lose api package TODO --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index d5fd5446a48..b6d856bb854 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -30,8 +30,7 @@ created as children of the currently active span, and the newly-created span becomes the new active span:: - # TODO (#15): which module holds the global tracer? - from opentelemetry.api.trace import tracer + from opentelemetry.trace import tracer # Create a new root span, set it as the current span in context with tracer.start_span("parent"):