Skip to content

Commit 7a7a207

Browse files
authored
Add stub tracer SDK (#55)
1 parent 3d0046a commit 7a7a207

File tree

10 files changed

+82
-29
lines changed

10 files changed

+82
-29
lines changed

opentelemetry-api/setup.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
import setuptools
1717

1818
BASE_DIR = os.path.dirname(__file__)
19-
VERSION_FILENAME = os.path.join(
20-
BASE_DIR, "src", "opentelemetry", "internal", "version.py")
19+
VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "version.py")
2120
PACKAGE_INFO = {}
2221
with open(VERSION_FILENAME) as f:
23-
exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used
22+
exec(f.read(), PACKAGE_INFO)
2423

2524
setuptools.setup(
2625
name="opentelemetry-api",
27-
version=PACKAGE_INFO["__version__"], # noqa
26+
version=PACKAGE_INFO["__version__"],
2827
author="OpenTelemetry Authors",
2928
author_email="[email protected]",
3029
classifiers=[
@@ -47,7 +46,8 @@
4746
extras_require={},
4847
license="Apache-2.0",
4948
package_dir={"": "src"},
50-
packages=setuptools.find_namespace_packages(where="src"),
49+
packages=setuptools.find_namespace_packages(where="src",
50+
include="opentelemetry.*"),
5151
url=("https://github.com/open-telemetry/opentelemetry-python"
5252
"/tree/master/opentelemetry-api"),
5353
zip_safe=False,

opentelemetry-api/src/opentelemetry/trace/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
created as children of the currently active span, and the newly-created span
3131
becomes the new active span::
3232
33-
# TODO (#15): which module holds the global tracer?
34-
from opentelemetry.api.trace import tracer
33+
from opentelemetry.trace import tracer
3534
3635
# Create a new root span, set it as the current span in context
3736
with tracer.start_span("parent"):

opentelemetry-sdk/setup.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
import os
1616
import setuptools
1717

18-
base_dir = os.path.dirname(__file__)
19-
20-
package_info = {}
21-
with open(os.path.join(base_dir, "src", "opentelemetry", "sdk", "version.py")) as f:
22-
exec(f.read(), package_info)
18+
BASE_DIR = os.path.dirname(__file__)
19+
VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "sdk",
20+
"version.py")
21+
PACKAGE_INFO = {}
22+
with open(VERSION_FILENAME) as f:
23+
exec(f.read(), PACKAGE_INFO)
2324

2425
setuptools.setup(
2526
name="opentelemetry-sdk",
26-
version=package_info["__version__"], # noqa
27+
version=PACKAGE_INFO["__version__"],
2728
author="OpenTelemetry Authors",
2829
author_email="[email protected]",
2930
classifiers=[
@@ -41,11 +42,14 @@
4142
include_package_data=True,
4243
long_description=open("README.rst").read(),
4344
install_requires=[
45+
"opentelemetry-api==0.1.dev0"
4446
],
4547
extras_require={},
4648
license="Apache-2.0",
4749
package_dir={"": "src"},
48-
packages=setuptools.find_namespace_packages(where="src"),
49-
url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-sdk",
50+
packages=setuptools.find_namespace_packages(where="src",
51+
include="opentelemetry.sdk.*"),
52+
url=("https://github.com/open-telemetry/opentelemetry-python"
53+
"/tree/master/opentelemetry-sdk"),
5054
zip_safe=False,
5155
)

opentelemetry-sdk/src/opentelemetry/sdk/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .version import __version__
15+
from . import trace
16+
17+
__all__ = [
18+
"trace",
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2019, OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from opentelemetry import trace as trace_api
16+
17+
18+
class Tracer(trace_api.Tracer):
19+
pass

opentelemetry-api/src/opentelemetry/internal/__init__.py renamed to opentelemetry-sdk/tests/trace/__init__.py

-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
from .version import __version__
16-
17-
__all__ = [
18-
"__version__",
19-
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2019, OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from opentelemetry import trace as trace_api
18+
from opentelemetry.sdk import trace
19+
20+
21+
class TestTracer(unittest.TestCase):
22+
23+
def test_extends_api(self):
24+
tracer = trace.Tracer()
25+
self.assertIsInstance(tracer, trace_api.Tracer)

tox.ini

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
skipsdist = True
3-
envlist = py{34,35,36,37}-test, lint, py37-mypy, docs
3+
envlist = py{34,35,36,37}-test-{api,sdk}, lint, py37-mypy, docs
44

55
[travis]
66
python =
@@ -11,24 +11,32 @@ deps =
1111
mypy: mypy~=0.711
1212

1313
setenv =
14-
PYTHONPATH={toxinidir}/opentelemetry-api/src/
15-
mypy: MYPYPATH={env:PYTHONPATH}
14+
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/
1615

1716
changedir =
18-
test: opentelemetry-api/tests
17+
test-api: opentelemetry-api/tests
18+
test-sdk: opentelemetry-sdk/tests
19+
20+
commands_pre =
21+
test-api: pip install -e {toxinidir}/opentelemetry-api
22+
test-sdk: pip install -e {toxinidir}/opentelemetry-api
23+
test-sdk: pip install -e {toxinidir}/opentelemetry-sdk
1924

2025
commands =
21-
py37-mypy: mypy opentelemetry-api/src/opentelemetry/
26+
mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
2227
; For test code, we don't want to enforce the full mypy strictness
23-
py37-mypy: mypy --config-file=mypy-relaxed.ini opentelemetry-api/tests/ opentelemetry-api/setup.py
24-
test: python -m unittest discover
28+
mypy: mypy --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/
29+
test-{api,sdk}: python -m unittest discover
2530

2631
[testenv:lint]
2732
deps =
2833
pylint~=2.3
2934
flake8~=3.7
3035
isort~=4.3
3136

37+
commands_pre =
38+
pip install -e {toxinidir}/opentelemetry-api
39+
3240
commands =
3341
; Prefer putting everything in one pylint command to profit from duplication
3442
; warnings.

0 commit comments

Comments
 (0)