Skip to content

Commit b512bf4

Browse files
committed
Refactor distros
1 parent be75fcd commit b512bf4

File tree

26 files changed

+345
-425
lines changed

26 files changed

+345
-425
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
## [1.4.0-0.23b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.4.0-0.23b0) - 2021-07-21
1010

1111
### Added
12+
- Refactored Distros
13+
([#1966](https://github.com/open-telemetry/opentelemetry-python/pull/1966))
1214
- Moved `opentelemetry-instrumentation` to core repository.
1315
([#1959](https://github.com/open-telemetry/opentelemetry-python/pull/1959))
1416
- Dropped attributes/events/links count available exposed on ReadableSpans.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
OpenTelemetry Default Configurator
2+
==================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-configurator.svg
7+
:target: https://pypi.org/project/opentelemetry-configurator/
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install opentelemetry-configurator-default
15+
16+
17+
This package provides a default configuration for OpenTelemetry users.
18+
19+
References
20+
----------
21+
22+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
23+
* `Example using opentelemetry-configurator <https://opentelemetry-python.readthedocs.io/en/latest/examples/configurator/README.html>`_

opentelemetry-distro/setup.cfg renamed to configurator/opentelemetry-configurator-default/setup.cfg

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
# limitations under the License.
1414
#
1515
[metadata]
16-
name = opentelemetry-distro
17-
description = OpenTelemetry Python Distro
16+
name = opentelemetry-configurator-default
17+
description = OpenTelemetry Python Default Configurator
1818
long_description = file: README.rst
1919
long_description_content_type = text/x-rst
2020
author = OpenTelemetry Authors
2121
author_email = [email protected]
22-
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-distro
22+
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-configurator-default
2323
platforms = any
2424
license = Apache-2.0
2525
classifiers =
@@ -49,10 +49,8 @@ install_requires =
4949
where = src
5050

5151
[options.entry_points]
52-
opentelemetry_distro =
53-
distro = opentelemetry.distro:OpenTelemetryDistro
54-
opentelemetry_configurator =
55-
configurator = opentelemetry.distro:Configurator
52+
opentelemetry-configurator =
53+
default = opentelemetry.configurator.default.DefaultConfigurator
5654

5755
[options.extras_require]
5856
test =

opentelemetry-distro/setup.py renamed to configurator/opentelemetry-configurator-default/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
BASE_DIR = os.path.dirname(__file__)
2020
VERSION_FILENAME = os.path.join(
21-
BASE_DIR, "src", "opentelemetry", "distro", "version.py"
21+
BASE_DIR, "src", "opentelemetry", "configurator", "version.py"
2222
)
2323
PACKAGE_INFO = {}
2424
with open(VERSION_FILENAME) as f:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright The 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+
16+
from opentelemetry.configurator import BaseConfigurator
17+
18+
19+
class DefaultConfigurator(BaseConfigurator):
20+
def configure(self):
21+
# FIXME move old configuration code here
22+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright The 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+
# type: ignore
15+
16+
from unittest import TestCase
17+
18+
19+
class TestConfigurator(TestCase):
20+
def test_case(self):
21+
pass

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

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
.. envvar:: OTEL_PYTHON_CONTEXT
2323
"""
2424

25-
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"
26-
"""
27-
.. envvar:: OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
28-
"""
29-
3025
OTEL_PYTHON_ID_GENERATOR = "OTEL_PYTHON_ID_GENERATOR"
3126
"""
3227
.. envvar:: OTEL_PYTHON_ID_GENERATOR
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
prune tests
2+
graft src
3+
global-exclude *.pyc
4+
global-exclude *.pyo
5+
global-exclude __pycache__/*
6+
include MANIFEST.in
7+
include README.rst

opentelemetry-configurator/README.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
OpenTelemetry Configurator
2+
==========================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-configurator.svg
7+
:target: https://pypi.org/project/opentelemetry-configurator/
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install opentelemetry-configurator
15+
16+
17+
This package provides entrypoints to configure OpenTelemetry.
18+
19+
References
20+
----------
21+
22+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
23+
* `Example using opentelemetry-configurator <https://opentelemetry-python.readthedocs.io/en/latest/examples/configurator/README.html>`_

opentelemetry-configurator/setup.cfg

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright The 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+
[metadata]
16+
name = opentelemetry-configurator
17+
description = OpenTelemetry Python Configurator
18+
long_description = file: README.rst
19+
long_description_content_type = text/x-rst
20+
author = OpenTelemetry Authors
21+
author_email = [email protected]
22+
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-configurator
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 4 - Beta
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.6
32+
Programming Language :: Python :: 3.7
33+
Programming Language :: Python :: 3.8
34+
Typing :: Typed
35+
36+
[options]
37+
python_requires = >=3.6
38+
package_dir=
39+
=src
40+
packages=find_namespace:
41+
zip_safe = False
42+
include_package_data = True
43+
install_requires =
44+
opentelemetry-api ~= 1.3
45+
opentelemetry-instrumentation == 0.23b0
46+
opentelemetry-sdk == 1.4.0
47+
48+
[options.packages.find]
49+
where = src
50+
51+
[options.entry_points]
52+
opentelemetry-pre-instrument =
53+
configurator = opentelemetry.configurator._configure
54+
55+
[options.extras_require]
56+
test =
57+
otlp =
58+
opentelemetry-exporter-otlp == 1.4.0

opentelemetry-configurator/setup.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright The 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 os
16+
17+
import setuptools
18+
19+
BASE_DIR = os.path.dirname(__file__)
20+
VERSION_FILENAME = os.path.join(
21+
BASE_DIR, "src", "opentelemetry", "configurator", "version.py"
22+
)
23+
PACKAGE_INFO = {}
24+
with open(VERSION_FILENAME) as f:
25+
exec(f.read(), PACKAGE_INFO)
26+
27+
setuptools.setup(
28+
version=PACKAGE_INFO["__version__"],
29+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright The 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+
16+
from abc import ABC, abstractmethod
17+
from os import environ
18+
19+
from pkg_resources import iter_entry_points
20+
21+
from opentelemetry.configurator.environment_variables import (
22+
OTEL_PYTHON_CONFIGURATORS,
23+
)
24+
25+
26+
def _configure():
27+
28+
installed_configurators = {
29+
entry_point.name: entry_point
30+
for entry_point in iter_entry_points("opentelemetry-configurator")
31+
}
32+
33+
configured_configurator_names = environ.get(
34+
OTEL_PYTHON_CONFIGURATORS, ""
35+
).split()
36+
37+
if len(installed_configurators) > 1 and not (
38+
configured_configurator_names
39+
):
40+
41+
raise Exception(
42+
"More than 1 configurator is available:\n\n\t{}\n"
43+
"Select the ones that are to be used by setting "
44+
"{}.".format(
45+
"\n\t".join(list(installed_configurators.keys())),
46+
OTEL_PYTHON_CONFIGURATORS,
47+
)
48+
)
49+
50+
for configured_configurator_name in environ.get(
51+
OTEL_PYTHON_CONFIGURATORS, ""
52+
).split():
53+
54+
if configured_configurator_name in installed_configurators.keys():
55+
56+
installed_configurators[
57+
configured_configurator_name
58+
].load()().configure()
59+
60+
61+
class BaseConfigurator(ABC):
62+
@abstractmethod
63+
def configure(self):
64+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright The 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+
OTEL_PYTHON_CONFIGURATORS = "OTEL_PYTHON_CONFIGURATORS"
16+
"""
17+
.. envvar:: OTEL_PYTHON_CONFIGURATORS
18+
19+
Space-separated string of `opentelemetry-configurator` entry point names.
20+
21+
Example: ``firstconfigurator secondconfigurator``
22+
23+
This environment variable needs to be set only if there is more than one
24+
installed configurator. The configurators will be executed in the order defined
25+
in this environment variable.
26+
"""

opentelemetry-configurator/src/opentelemetry/configurator/py.typed

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright The 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+
__version__ = "0.23b0"

opentelemetry-configurator/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)