Skip to content

Refactor distros #1966

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.4.0-0.23b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.4.0-0.23b0) - 2021-07-21

### Added
- Refactored Distros
([#1966](https://github.com/open-telemetry/opentelemetry-python/pull/1966))
- Moved `opentelemetry-instrumentation` to core repository.
([#1959](https://github.com/open-telemetry/opentelemetry-python/pull/1959))
- Dropped attributes/events/links count available exposed on ReadableSpans.
Expand Down
23 changes: 23 additions & 0 deletions configurator/opentelemetry-configurator-default/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
OpenTelemetry Default Configurator
==================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-configurator.svg
:target: https://pypi.org/project/opentelemetry-configurator/

Installation
------------

::

pip install opentelemetry-configurator-default


This package provides a default configuration for OpenTelemetry users.

References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
* `Example using opentelemetry-configurator <https://opentelemetry-python.readthedocs.io/en/latest/examples/configurator/README.html>`_
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.
#
[metadata]
name = opentelemetry-distro
description = OpenTelemetry Python Distro
name = opentelemetry-configurator-default
description = OpenTelemetry Python Default Configurator
long_description = file: README.rst
long_description_content_type = text/x-rst
author = OpenTelemetry Authors
author_email = [email protected]
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-distro
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-configurator-default
platforms = any
license = Apache-2.0
classifiers =
Expand Down Expand Up @@ -49,10 +49,8 @@ install_requires =
where = src

[options.entry_points]
opentelemetry_distro =
distro = opentelemetry.distro:OpenTelemetryDistro
opentelemetry_configurator =
configurator = opentelemetry.distro:Configurator
opentelemetry-configurator =
default = opentelemetry.configurator.default.DefaultConfigurator

[options.extras_require]
test =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "distro", "version.py"
BASE_DIR, "src", "opentelemetry", "configurator", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright The 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.configurator import BaseConfigurator


class DefaultConfigurator(BaseConfigurator):
def configure(self):
# FIXME move old configuration code here
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright The 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.
# type: ignore

from unittest import TestCase


class TestConfigurator(TestCase):
def test_case(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
.. envvar:: OTEL_PYTHON_CONTEXT
"""

OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"
"""
.. envvar:: OTEL_PYTHON_DISABLED_INSTRUMENTATIONS
"""

OTEL_PYTHON_ID_GENERATOR = "OTEL_PYTHON_ID_GENERATOR"
"""
.. envvar:: OTEL_PYTHON_ID_GENERATOR
Expand Down
7 changes: 7 additions & 0 deletions opentelemetry-configurator/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prune tests
graft src
global-exclude *.pyc
global-exclude *.pyo
global-exclude __pycache__/*
include MANIFEST.in
include README.rst
23 changes: 23 additions & 0 deletions opentelemetry-configurator/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
OpenTelemetry Configurator
==========================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-configurator.svg
:target: https://pypi.org/project/opentelemetry-configurator/

Installation
------------

::

pip install opentelemetry-configurator


This package provides entrypoints to configure OpenTelemetry.

References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
* `Example using opentelemetry-configurator <https://opentelemetry-python.readthedocs.io/en/latest/examples/configurator/README.html>`_
58 changes: 58 additions & 0 deletions opentelemetry-configurator/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright The 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.
#
[metadata]
name = opentelemetry-configurator
description = OpenTelemetry Python Configurator
long_description = file: README.rst
long_description_content_type = text/x-rst
author = OpenTelemetry Authors
author_email = [email protected]
url = https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-configurator
platforms = any
license = Apache-2.0
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Typing :: Typed

[options]
python_requires = >=3.6
package_dir=
=src
packages=find_namespace:
zip_safe = False
include_package_data = True
install_requires =
opentelemetry-api ~= 1.3
opentelemetry-instrumentation == 0.23b0
opentelemetry-sdk == 1.4.0

[options.packages.find]
where = src

[options.entry_points]
opentelemetry-pre-instrument =
configurator = opentelemetry.configurator._configure

[options.extras_require]
test =
otlp =
opentelemetry-exporter-otlp == 1.4.0
29 changes: 29 additions & 0 deletions opentelemetry-configurator/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright The 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 os

import setuptools

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "configurator", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(
version=PACKAGE_INFO["__version__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright The 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 abc import ABC, abstractmethod
from os import environ

from pkg_resources import iter_entry_points

from opentelemetry.configurator.environment_variables import (
OTEL_PYTHON_CONFIGURATORS,
)


def _configure():

installed_configurators = {
entry_point.name: entry_point
for entry_point in iter_entry_points("opentelemetry-configurator")
}

configured_configurator_names = environ.get(
OTEL_PYTHON_CONFIGURATORS, ""
).split()

if len(installed_configurators) > 1 and not (
configured_configurator_names
):

raise Exception(
"More than 1 configurator is available:\n\n\t{}\n"
"Select the ones that are to be used by setting "
"{}.".format(
"\n\t".join(list(installed_configurators.keys())),
OTEL_PYTHON_CONFIGURATORS,
)
)

for configured_configurator_name in environ.get(
OTEL_PYTHON_CONFIGURATORS, ""
).split():

if configured_configurator_name in installed_configurators.keys():

installed_configurators[
configured_configurator_name
].load()().configure()


class BaseConfigurator(ABC):
@abstractmethod
def configure(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright The 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.

OTEL_PYTHON_CONFIGURATORS = "OTEL_PYTHON_CONFIGURATORS"
"""
.. envvar:: OTEL_PYTHON_CONFIGURATORS

Space-separated string of `opentelemetry-configurator` entry point names.

Example: ``firstconfigurator secondconfigurator``

This environment variable needs to be set only if there is more than one
installed configurator. The configurators will be executed in the order defined
in this environment variable.
"""
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright The 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.

__version__ = "0.23b0"
Empty file.
Loading