Skip to content

Commit ade44b1

Browse files
authored
Move BaseConfigurator to SDK (#2188)
* Move _SUPPRESS_INTRUMENTATION key from instrumentation to api This will continue to be part of the internal API but live in the API context package. * Move BaseConfigurator from isntrumentation to SDK This allows SDK to not depend on instrumentation package anymore.
1 parent e1c4a5b commit ade44b1

File tree

6 files changed

+44
-64
lines changed

6 files changed

+44
-64
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ def detach(token: object) -> None:
157157
_RUNTIME_CONTEXT.detach(token) # type: ignore
158158
except Exception: # pylint: disable=broad-except
159159
logger.error("Failed to detach context")
160+
161+
162+
# FIXME This is a temporary location for the suppress instrumentation key.
163+
# Once the decision around how to suppress instrumentation is made in the
164+
# spec, this key should be moved accordingly.
165+
_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation")

opentelemetry-instrumentation/src/opentelemetry/instrumentation/configurator.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616

1717
from wrapt import ObjectProxy
1818

19-
from opentelemetry.context import create_key
19+
# pylint: disable=unused-import
20+
from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY # noqa: F401
2021
from opentelemetry.trace import StatusCode
2122

22-
# FIXME This is a temporary location for the suppress instrumentation key.
23-
# Once the decision around how to suppress instrumentation is made in the
24-
# spec, this key should be moved accordingly.
25-
_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation")
26-
2723

2824
def extract_attributes_from_object(
2925
obj: any, attributes: Sequence[str], existing: Dict[str, str] = None

opentelemetry-sdk/setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ include_package_data = True
4444
install_requires =
4545
opentelemetry-api == 1.6.0
4646
opentelemetry-semantic-conventions == 0.25b0
47-
opentelemetry-instrumentation == 0.25b0
4847

4948
[options.packages.find]
5049
where = src

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
OpenTelemetry SDK Configurator for Easy Instrumentation with Distros
1818
"""
1919

20+
from abc import ABC, abstractmethod
2021
from os import environ
2122
from typing import Sequence, Tuple
2223

@@ -27,7 +28,6 @@
2728
OTEL_PYTHON_ID_GENERATOR,
2829
OTEL_TRACES_EXPORTER,
2930
)
30-
from opentelemetry.instrumentation.configurator import BaseConfigurator
3131
from opentelemetry.sdk.trace import TracerProvider
3232
from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter
3333
from opentelemetry.sdk.trace.id_generator import IdGenerator
@@ -140,7 +140,34 @@ def _initialize_components():
140140
_init_tracing(trace_exporters, id_generator)
141141

142142

143-
class _OTelSDKConfigurator(BaseConfigurator):
143+
class _BaseConfigurator(ABC):
144+
"""An ABC for configurators
145+
146+
Configurators are used to configure
147+
SDKs (i.e. TracerProvider, MeterProvider, Processors...)
148+
to reduce the amount of manual configuration required.
149+
"""
150+
151+
_instance = None
152+
_is_instrumented = False
153+
154+
def __new__(cls, *args, **kwargs):
155+
156+
if cls._instance is None:
157+
cls._instance = object.__new__(cls, *args, **kwargs)
158+
159+
return cls._instance
160+
161+
@abstractmethod
162+
def _configure(self, **kwargs):
163+
"""Configure the SDK"""
164+
165+
def configure(self, **kwargs):
166+
"""Configure the SDK"""
167+
self._configure(**kwargs)
168+
169+
170+
class _OTelSDKConfigurator(_BaseConfigurator):
144171
"""A basic Configurator by OTel Python for initalizing OTel SDK components
145172
146173
Initializes several crucial OTel SDK components (i.e. TracerProvider,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
from os import environ, linesep
2222
from typing import Optional
2323

24-
from opentelemetry.context import Context, attach, detach, set_value
25-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
24+
from opentelemetry.context import (
25+
_SUPPRESS_INSTRUMENTATION_KEY,
26+
Context,
27+
attach,
28+
detach,
29+
set_value,
30+
)
2631
from opentelemetry.sdk.environment_variables import (
2732
OTEL_BSP_EXPORT_TIMEOUT,
2833
OTEL_BSP_MAX_EXPORT_BATCH_SIZE,

0 commit comments

Comments
 (0)