11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
-
14
+ #
15
+ import os
15
16
from logging import getLogger
16
17
from typing import Sequence , Tuple
17
18
20
21
from opentelemetry import trace
21
22
from opentelemetry .configuration import Configuration
22
23
from opentelemetry .instrumentation .configurator import BaseConfigurator
24
+ from opentelemetry .instrumentation .distro import BaseDistro
23
25
from opentelemetry .sdk .metrics .export import MetricsExporter
24
26
from opentelemetry .sdk .resources import Resource
25
27
from opentelemetry .sdk .trace import TracerProvider
31
33
32
34
logger = getLogger (__file__ )
33
35
36
+
34
37
EXPORTER_OTLP = "otlp"
35
38
EXPORTER_OTLP_SPAN = "otlp_span"
36
39
EXPORTER_OTLP_METRIC = "otlp_metric"
37
- _DEFAULT_EXPORTER = EXPORTER_OTLP
38
40
39
41
RANDOM_IDS_GENERATOR = "random"
40
42
_DEFAULT_IDS_GENERATOR = RANDOM_IDS_GENERATOR
@@ -49,7 +51,7 @@ def _get_service_name() -> str:
49
51
50
52
51
53
def _get_exporter_names () -> Sequence [str ]:
52
- exporter = Configuration ().EXPORTER or _DEFAULT_EXPORTER
54
+ exporter = Configuration ().EXPORTER or EXPORTER_OTLP
53
55
if exporter .lower ().strip () == "none" :
54
56
return []
55
57
@@ -87,11 +89,6 @@ def _init_tracing(
87
89
)
88
90
89
91
90
- def _init_metrics (exporters : Sequence [MetricsExporter ]):
91
- if exporters :
92
- logger .warning ("automatic metric initialization is not supported yet." )
93
-
94
-
95
92
def _import_tracer_provider_config_components (
96
93
selected_components , entry_point_name
97
94
) -> Sequence [Tuple [str , object ]]:
@@ -158,13 +155,27 @@ def _initialize_components():
158
155
ids_generator_name = _get_ids_generator ()
159
156
ids_generator = _import_ids_generator (ids_generator_name )
160
157
_init_tracing (trace_exporters , ids_generator )
161
-
162
158
# We don't support automatic initialization for metric yet but have added
163
159
# some boilerplate in order to make sure current implementation does not
164
160
# lock us out of supporting metrics later without major surgery.
165
161
_init_metrics (metric_exporters )
166
162
167
163
164
+ def _init_metrics (exporters : Sequence [MetricsExporter ]):
165
+ if exporters :
166
+ logger .warning ("automatic metric initialization is not supported yet." )
167
+
168
+
168
169
class Configurator (BaseConfigurator ):
169
170
def _configure (self , ** kwargs ):
170
171
_initialize_components ()
172
+
173
+
174
+ class OpenTelemetryDistro (BaseDistro ):
175
+ """
176
+ The OpenTelemetry provided Distro configures a default set of
177
+ configuration out of the box.
178
+ """
179
+
180
+ def _configure (self , ** kwargs ):
181
+ os .environ .setdefault ("OTEL_EXPORTER" , "otlp" )
0 commit comments