diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index a8dd39c53ab..7f56cdb216b 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -157,3 +157,9 @@ def detach(token: object) -> None: _RUNTIME_CONTEXT.detach(token) # type: ignore except Exception: # pylint: disable=broad-except logger.error("Failed to detach context") + + +# FIXME This is a temporary location for the suppress instrumentation key. +# Once the decision around how to suppress instrumentation is made in the +# spec, this key should be moved accordingly. +_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation") diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/configurator.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/configurator.py deleted file mode 100644 index 3efa71e89e9..00000000000 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/configurator.py +++ /dev/null @@ -1,53 +0,0 @@ -# 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 - -""" -OpenTelemetry Base Configurator -""" - -from abc import ABC, abstractmethod -from logging import getLogger - -_LOG = getLogger(__name__) - - -class BaseConfigurator(ABC): - """An ABC for configurators - - Configurators are used to configure - SDKs (i.e. TracerProvider, MeterProvider, Processors...) - to reduce the amount of manual configuration required. - """ - - _instance = None - _is_instrumented = False - - def __new__(cls, *args, **kwargs): - - if cls._instance is None: - cls._instance = object.__new__(cls, *args, **kwargs) - - return cls._instance - - @abstractmethod - def _configure(self, **kwargs): - """Configure the SDK""" - - def configure(self, **kwargs): - """Configure the SDK""" - self._configure(**kwargs) - - -__all__ = ["BaseConfigurator"] diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py index 16f75aae6c8..5f63b4af5e3 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py @@ -16,14 +16,10 @@ from wrapt import ObjectProxy -from opentelemetry.context import create_key +# pylint: disable=unused-import +from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY # noqa: F401 from opentelemetry.trace import StatusCode -# FIXME This is a temporary location for the suppress instrumentation key. -# Once the decision around how to suppress instrumentation is made in the -# spec, this key should be moved accordingly. -_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation") - def extract_attributes_from_object( obj: any, attributes: Sequence[str], existing: Dict[str, str] = None diff --git a/opentelemetry-sdk/setup.cfg b/opentelemetry-sdk/setup.cfg index c84e79f5d8d..bf063a237f7 100644 --- a/opentelemetry-sdk/setup.cfg +++ b/opentelemetry-sdk/setup.cfg @@ -44,7 +44,6 @@ include_package_data = True install_requires = opentelemetry-api == 1.6.0 opentelemetry-semantic-conventions == 0.25b0 - opentelemetry-instrumentation == 0.25b0 [options.packages.find] where = src diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 79445a7a357..f2ebd317493 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -17,6 +17,7 @@ OpenTelemetry SDK Configurator for Easy Instrumentation with Distros """ +from abc import ABC, abstractmethod from os import environ from typing import Sequence, Tuple @@ -27,7 +28,6 @@ OTEL_PYTHON_ID_GENERATOR, OTEL_TRACES_EXPORTER, ) -from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter from opentelemetry.sdk.trace.id_generator import IdGenerator @@ -140,7 +140,34 @@ def _initialize_components(): _init_tracing(trace_exporters, id_generator) -class _OTelSDKConfigurator(BaseConfigurator): +class _BaseConfigurator(ABC): + """An ABC for configurators + + Configurators are used to configure + SDKs (i.e. TracerProvider, MeterProvider, Processors...) + to reduce the amount of manual configuration required. + """ + + _instance = None + _is_instrumented = False + + def __new__(cls, *args, **kwargs): + + if cls._instance is None: + cls._instance = object.__new__(cls, *args, **kwargs) + + return cls._instance + + @abstractmethod + def _configure(self, **kwargs): + """Configure the SDK""" + + def configure(self, **kwargs): + """Configure the SDK""" + self._configure(**kwargs) + + +class _OTelSDKConfigurator(_BaseConfigurator): """A basic Configurator by OTel Python for initalizing OTel SDK components Initializes several crucial OTel SDK components (i.e. TracerProvider, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 369821239b0..4f0cc817c9f 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -21,8 +21,13 @@ from os import environ, linesep from typing import Optional -from opentelemetry.context import Context, attach, detach, set_value -from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY +from opentelemetry.context import ( + _SUPPRESS_INSTRUMENTATION_KEY, + Context, + attach, + detach, + set_value, +) from opentelemetry.sdk.environment_variables import ( OTEL_BSP_EXPORT_TIMEOUT, OTEL_BSP_MAX_EXPORT_BATCH_SIZE,