From 7a7a20798e403a5339fb9efa7a77a07cd8edcd86 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Wed, 17 Jul 2019 16:05:59 -0700 Subject: [PATCH] Add stub tracer SDK (#55) --- opentelemetry-api/setup.py | 10 ++++---- .../src/opentelemetry/trace/__init__.py | 3 +-- .../opentelemetry/{internal => }/version.py | 0 opentelemetry-sdk/setup.py | 20 +++++++++------ .../src/opentelemetry/sdk/__init__.py | 6 ++++- .../src/opentelemetry/sdk/trace/__init__.py | 19 ++++++++++++++ .../tests}/__init__.py | 0 .../tests/trace}/__init__.py | 6 ----- opentelemetry-sdk/tests/trace/test_trace.py | 25 +++++++++++++++++++ tox.ini | 22 ++++++++++------ 10 files changed, 82 insertions(+), 29 deletions(-) rename opentelemetry-api/src/opentelemetry/{internal => }/version.py (100%) create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py rename {opentelemetry-api/src/opentelemetry => opentelemetry-sdk/tests}/__init__.py (100%) rename {opentelemetry-api/src/opentelemetry/internal => opentelemetry-sdk/tests/trace}/__init__.py (89%) create mode 100644 opentelemetry-sdk/tests/trace/test_trace.py diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index d2a27a0d442..abf71aa63d5 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -16,15 +16,14 @@ import setuptools BASE_DIR = os.path.dirname(__file__) -VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "internal", "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) #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 +46,8 @@ 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.*"), url=("https://github.com/open-telemetry/opentelemetry-python" "/tree/master/opentelemetry-api"), zip_safe=False, 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"): diff --git a/opentelemetry-api/src/opentelemetry/internal/version.py b/opentelemetry-api/src/opentelemetry/version.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/internal/version.py rename to opentelemetry-api/src/opentelemetry/version.py diff --git a/opentelemetry-sdk/setup.py b/opentelemetry-sdk/setup.py index b95fecb27a9..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"), - 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, ) 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", +] 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..ca6f173dcb7 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -0,0 +1,19 @@ +# 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 trace as trace_api + + +class Tracer(trace_api.Tracer): + pass diff --git a/opentelemetry-api/src/opentelemetry/__init__.py b/opentelemetry-sdk/tests/__init__.py similarity index 100% rename from opentelemetry-api/src/opentelemetry/__init__.py rename to opentelemetry-sdk/tests/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/internal/__init__.py b/opentelemetry-sdk/tests/trace/__init__.py similarity index 89% rename from opentelemetry-api/src/opentelemetry/internal/__init__.py rename to opentelemetry-sdk/tests/trace/__init__.py index 83ac009440a..d853a7bcf65 100644 --- a/opentelemetry-api/src/opentelemetry/internal/__init__.py +++ b/opentelemetry-sdk/tests/trace/__init__.py @@ -11,9 +11,3 @@ # 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-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py new file mode 100644 index 00000000000..7f6380e0ed4 --- /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 trace as trace_api +from opentelemetry.sdk import trace + + +class TestTracer(unittest.TestCase): + + def test_extends_api(self): + tracer = trace.Tracer() + self.assertIsInstance(tracer, trace_api.Tracer) diff --git a/tox.ini b/tox.ini index 085d260c260..f9761bcc01e 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 = @@ -11,17 +11,22 @@ deps = mypy: mypy~=0.711 setenv = - PYTHONPATH={toxinidir}/opentelemetry-api/src/ - mypy: MYPYPATH={env:PYTHONPATH} + mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/ 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/ + 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 - test: python -m unittest discover + mypy: mypy --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/ + test-{api,sdk}: python -m unittest discover [testenv:lint] deps = @@ -29,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.