From 7e1c95bbc0be425a0bd2411cf3061f18dedda3d5 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 11 Jan 2021 00:22:36 -0600 Subject: [PATCH 01/29] Remove Configuration --- .../opentelemetry/exporter/jaeger/__init__.py | 38 ++-- .../src/opentelemetry/exporter/jaeger/util.py | 7 +- ...uf.py => test_jaeger_exporter_protobuf.py} | 7 - .../tests/test_jaeger_exporter_thrift.py | 6 - .../opentelemetry/exporter/otlp/exporter.py | 18 +- .../otlp/metrics_exporter/__init__.py | 21 +- .../exporter/otlp/trace_exporter/__init__.py | 20 +- .../tests/test_otlp_metric_exporter.py | 5 - .../tests/test_otlp_trace_exporter.py | 4 - .../opentelemetry/exporter/zipkin/__init__.py | 8 +- .../tests/test_zipkin_exporter.py | 2 - .../opentelemetry/configuration/__init__.py | 198 ------------------ .../src/opentelemetry/configuration/py.typed | 0 .../src/opentelemetry/propagators/__init__.py | 10 +- .../src/opentelemetry/util/__init__.py | 9 +- .../tests/configuration/__init__.py | 0 .../tests/configuration/test_configuration.py | 177 ---------------- .../tests/configuration/test_exclude_list.py | 60 ------ .../tests/propagators/test_propagators.py | 4 - .../src/opentelemetry/distro/__init__.py | 8 +- .../tests/test_configurator.py | 4 - .../auto_instrumentation/sitecustomize.py | 10 +- .../instrumentation/instrumentor.py | 12 +- .../src/opentelemetry/sdk/trace/__init__.py | 11 +- .../sdk/trace/export/__init__.py | 20 +- .../tests/trace/export/test_export.py | 6 - opentelemetry-sdk/tests/trace/test_trace.py | 11 - 27 files changed, 95 insertions(+), 581 deletions(-) rename exporter/opentelemetry-exporter-jaeger/tests/{test_jarget_exporter_protobuf.py => test_jaeger_exporter_protobuf.py} (98%) delete mode 100644 opentelemetry-api/src/opentelemetry/configuration/__init__.py delete mode 100644 opentelemetry-api/src/opentelemetry/configuration/py.typed delete mode 100644 opentelemetry-api/tests/configuration/__init__.py delete mode 100644 opentelemetry-api/tests/configuration/test_configuration.py delete mode 100644 opentelemetry-api/tests/configuration/test_exclude_list.py diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py index 297c1e2b264..aabcd8ac993 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py @@ -65,24 +65,14 @@ """ # pylint: disable=protected-access -import base64 import logging -import socket -from typing import Optional, Union - -from grpc import ( - ChannelCredentials, - insecure_channel, - secure_channel, - ssl_channel_credentials, -) -from thrift.protocol import TBinaryProtocol, TCompactProtocol -from thrift.transport import THttpClient, TTransport +from os import environ +from typing import Optional + +from grpc import ChannelCredentials, insecure_channel, secure_channel -from opentelemetry.configuration import Configuration from opentelemetry.exporter.jaeger import util from opentelemetry.exporter.jaeger.gen import model_pb2 -from opentelemetry.exporter.jaeger.gen.agent import Agent as agent from opentelemetry.exporter.jaeger.gen.collector_pb2 import PostSpansRequest from opentelemetry.exporter.jaeger.gen.collector_pb2_grpc import ( CollectorServiceStub, @@ -92,9 +82,7 @@ from opentelemetry.exporter.jaeger.translate import Translate from opentelemetry.exporter.jaeger.translate.protobuf import ProtobufTranslator from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator -from opentelemetry.sdk.trace.export import Span, SpanExporter, SpanExportResult -from opentelemetry.trace import SpanKind -from opentelemetry.trace.status import StatusCode +from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult DEFAULT_AGENT_HOST_NAME = "localhost" DEFAULT_AGENT_PORT = 6831 @@ -142,12 +130,18 @@ def __init__( self.service_name = service_name self.agent_host_name = _parameter_setter( param=agent_host_name, - env_variable=Configuration().EXPORTER_JAEGER_AGENT_HOST, + env_variable=environ.get("OTEL_EXPORTER_JAEGER_AGENT_HOST"), default=DEFAULT_AGENT_HOST_NAME, ) + + environ_agent_port = environ.get("OTEL_EXPORTER_JAEGER_AGENT_PORT") + environ_agent_port = ( + int(environ_agent_port) if environ_agent_port is not None else None + ) + self.agent_port = _parameter_setter( param=agent_port, - env_variable=Configuration().EXPORTER_JAEGER_AGENT_PORT, + env_variable=environ_agent_port, default=DEFAULT_AGENT_PORT, ) self._agent_client = AgentClientUDP( @@ -155,17 +149,17 @@ def __init__( ) self.collector_endpoint = _parameter_setter( param=collector_endpoint, - env_variable=Configuration().EXPORTER_JAEGER_ENDPOINT, + env_variable=environ.get("OTEL_EXPORTER_JAEGER_ENDPOINT"), default=None, ) self.username = _parameter_setter( param=username, - env_variable=Configuration().EXPORTER_JAEGER_USER, + env_variable=environ.get("OTEL_EXPORTER_JAEGER_USER"), default=None, ) self.password = _parameter_setter( param=password, - env_variable=Configuration().EXPORTER_JAEGER_PASSWORD, + env_variable=environ.get("OTEL_EXPORTER_JAEGER_PASSWORD"), default=None, ) self._collector = None diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py index 6be9d509ac8..f5cb6a742da 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py @@ -13,11 +13,10 @@ # limitations under the License. import logging +from os import environ from grpc import ChannelCredentials, ssl_channel_credentials -from opentelemetry.configuration import Configuration - logger = logging.getLogger(__name__) DEFAULT_INSECURE = False @@ -26,7 +25,7 @@ def _get_insecure(param): if param is not None: return param - insecure_env = Configuration().get("EXPORTER_JAEGER_INSECURE", None) + insecure_env = environ.get("OTEL_EXPORTER_JAEGER_INSECURE") if insecure_env is not None: return insecure_env.lower() == "true" return DEFAULT_INSECURE @@ -45,7 +44,7 @@ def _load_credential_from_file(path) -> ChannelCredentials: def _get_credentials(param): if param is not None: return param - creds_env = Configuration().get("EXPORTER_JAEGER_CERTIFICATE", None) + creds_env = environ.get("OTEL_EXPORTER_JAEGER_CERTIFICATE") if creds_env: return _load_credential_from_file(creds_env) return ssl_channel_credentials() diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jarget_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py similarity index 98% rename from exporter/opentelemetry-exporter-jaeger/tests/test_jarget_exporter_protobuf.py rename to exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py index 2af228a6b78..0ba03f6d3db 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jarget_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py @@ -22,7 +22,6 @@ import opentelemetry.exporter.jaeger.gen.model_pb2 as model_pb2 import opentelemetry.exporter.jaeger.translate.protobuf as pb_translator from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.exporter.jaeger import JaegerSpanExporter from opentelemetry.exporter.jaeger.translate import ( NAME_KEY, @@ -49,16 +48,10 @@ def setUp(self): self._test_span.start() self._test_span.end() # pylint: disable=protected-access - Configuration._reset() - - def tearDown(self): - # pylint: disable=protected-access - Configuration._reset() def test_constructor_by_environment_variables(self): """Test using Environment Variables.""" # pylint: disable=protected-access - Configuration._reset() service = "my-opentelemetry-jaeger" collector_endpoint = "localhost:14250" diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py index 379dd9a1e7d..1d95da5cf7f 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py @@ -20,7 +20,6 @@ # pylint:disable=import-error import opentelemetry.exporter.jaeger as jaeger_exporter from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.exporter.jaeger.gen.jaeger import ttypes as jaeger from opentelemetry.exporter.jaeger.translate import Translate from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator @@ -44,11 +43,6 @@ def setUp(self): self._test_span.start() self._test_span.end() # pylint: disable=protected-access - Configuration._reset() - - def tearDown(self): - # pylint: disable=protected-access - Configuration._reset() def test_constructor_default(self): # pylint: disable=protected-access diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index a4ae1edcfbb..16496150ed3 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -18,6 +18,7 @@ import logging from abc import ABC, abstractmethod from collections.abc import Mapping, Sequence +from os import environ from time import sleep from typing import Any, Callable, Dict, Generic, List, Optional from typing import Sequence as TypingSequence @@ -35,7 +36,6 @@ ssl_channel_credentials, ) -from opentelemetry.configuration import Configuration from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import Resource from opentelemetry.sdk.resources import Resource as SDKResource @@ -159,23 +159,23 @@ def __init__( endpoint = ( endpoint - or Configuration().EXPORTER_OTLP_ENDPOINT + or environ.get("OTEL_EXPORTER_OTLP_ENDPOINT") or "localhost:4317" ) if insecure is None: - insecure = Configuration().EXPORTER_OTLP_INSECURE + insecure = environ.get("OTEL_EXPORTER_OTLP_INSECURE") if insecure is None: insecure = False - self._headers = headers or Configuration().EXPORTER_OTLP_HEADERS + self._headers = headers or environ.get("OTEL_EXPORTER_OTLP_HEADERS") if isinstance(self._headers, str): self._headers = tuple( tuple(item.split("=")) for item in self._headers.split(",") ) self._timeout = ( timeout - or Configuration().EXPORTER_OTLP_TIMEOUT + or int(environ.get("OTEL_EXPORTER_OTLP_TIMEOUT", 0)) or 10 # default: 10 seconds ) self._collector_span_kwargs = None @@ -188,7 +188,9 @@ def __init__( ): compression_algorithm = Compression.Gzip else: - compression_str = Configuration().EXPORTER_OTLP_INSECURE or None + compression_str = ( + environ.get("OTLP_EXPORTER_OTLP_INSECURE") or None + ) if compression_str is None: compression_algorithm = Compression.NoCompression elif ( @@ -210,13 +212,13 @@ def __init__( # secure mode if ( credentials is None - and Configuration().EXPORTER_OTLP_CERTIFICATE is None + and environ.get("OTLP_EXPORTER_OTLP_CERTIFICATE") is None ): # use the default location chosen by gRPC runtime credentials = ssl_channel_credentials() else: credentials = credentials or _load_credential_from_file( - Configuration().EXPORTER_OTLP_CERTIFICATE + environ.get("OTLP_EXPORTER_OTLP_CERTIFICATE") ) self._client = self._stub( secure_channel( diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index c371c177e9c..9d98bca4552 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -15,11 +15,11 @@ """OTLP Metrics Exporter""" import logging +from os import environ from typing import List, Optional, Sequence, Type, TypeVar from grpc import ChannelCredentials -from opentelemetry.configuration import Configuration from opentelemetry.exporter.otlp.exporter import ( OTLPExporterMixin, _get_resource_data, @@ -143,26 +143,31 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = Configuration().EXPORTER_OTLP_METRIC_INSECURE + insecure = environ.get("OTEL_EXPORTER_OTLP_METRIC_INSECURE") if ( not insecure - and Configuration().EXPORTER_OTLP_METRIC_CERTIFICATE is not None + and environ.get("OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE") + is not None ): credentials = credentials or _load_credential_from_file( - Configuration().EXPORTER_OTLP_METRIC_CERTIFICATE + environ.get("OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE") ) + environ_timeout = environ.get("OTEL_EXPORTER_OTLP_METRIC_TIMEOUT") + environ_timeout = ( + int(environ_timeout) if environ_timeout is not None else None + ) + super().__init__( **{ "endpoint": endpoint - or Configuration().EXPORTER_OTLP_METRIC_ENDPOINT, + or environ.get("OTEL_EXPORTER_OTLP_METRIC_ENDPOINT"), "insecure": insecure, "credentials": credentials, "headers": headers - or Configuration().EXPORTER_OTLP_METRIC_HEADERS, - "timeout": timeout - or Configuration().EXPORTER_OTLP_METRIC_TIMEOUT, + or environ.get("OTEL_EXPORTER_OTLP_METRIC_HEADERS"), + "timeout": timeout or environ_timeout, } ) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py index b872b624a1a..77d617f55a4 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py @@ -14,11 +14,11 @@ """OTLP Span Exporter""" import logging +from os import environ from typing import Optional, Sequence from grpc import ChannelCredentials -from opentelemetry.configuration import Configuration from opentelemetry.exporter.otlp.exporter import ( OTLPExporterMixin, _get_resource_data, @@ -73,26 +73,30 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = Configuration().EXPORTER_OTLP_SPAN_INSECURE + insecure = environ.get("OTEL_EXPORTER_OTLP_SPAN_INSECURE") if ( not insecure - and Configuration().EXPORTER_OTLP_SPAN_CERTIFICATE is not None + and environ.get("OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE") is not None ): credentials = credentials or _load_credential_from_file( - Configuration().EXPORTER_OTLP_SPAN_CERTIFICATE + environ.get("OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE") ) + environ_timeout = environ.get("OTEL_EXPORTER_OTLP_SPAN_TIMEOUT") + environ_timeout = ( + int(environ_timeout) if environ_timeout is not None else None + ) + super().__init__( **{ "endpoint": endpoint - or Configuration().EXPORTER_OTLP_SPAN_ENDPOINT, + or environ.get("OTEL_EXPORTER_OTLP_SPAN_ENDPOINT"), "insecure": insecure, "credentials": credentials, "headers": headers - or Configuration().EXPORTER_OTLP_SPAN_HEADERS, - "timeout": timeout - or Configuration().EXPORTER_OTLP_SPAN_TIMEOUT, + or environ.get("OTEL_EXPORTER_OTLP_SPAN_HEADERS"), + "timeout": timeout or environ_timeout, } ) diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py index 946a313a440..82ef7652919 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py @@ -19,7 +19,6 @@ from grpc import ChannelCredentials -from opentelemetry.configuration import Configuration from opentelemetry.exporter.otlp.metrics_exporter import OTLPMetricsExporter from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( ExportMetricsServiceRequest, @@ -62,10 +61,6 @@ def setUp(self): # pylint: disable=arguments-differ self.meter = MeterProvider(resource=self.resource,).get_meter( "name", "version" ) - Configuration._reset() # pylint: disable=protected-access - - def tearDown(self): - Configuration._reset() # pylint: disable=protected-access @patch.dict( "os.environ", diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py index 5dde0c97722..18c63394e64 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py @@ -22,7 +22,6 @@ from google.rpc.error_details_pb2 import RetryInfo from grpc import ChannelCredentials, StatusCode, server -from opentelemetry.configuration import Configuration from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import ( ExportTraceServiceRequest, @@ -160,11 +159,8 @@ def setUp(self): self.span.start() self.span.end() - Configuration._reset() # pylint: disable=protected-access - def tearDown(self): self.server.stop(None) - Configuration._reset() # pylint: disable=protected-access @patch.dict( "os.environ", diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index 387e33d5944..209ea6140b5 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -73,12 +73,12 @@ import json import logging +from os import environ from typing import Optional, Sequence, Union from urllib.parse import urlparse import requests -from opentelemetry.configuration import Configuration from opentelemetry.exporter.zipkin.gen import zipkin_pb2 from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace import Span, SpanContext, SpanKind @@ -142,7 +142,9 @@ def __init__( ): self.service_name = service_name if url is None: - self.url = Configuration().EXPORTER_ZIPKIN_ENDPOINT or DEFAULT_URL + self.url = ( + environ.get("OTEL_EXPORTER_ZIPKIN_ENDPOINT") or DEFAULT_URL + ) else: self.url = url @@ -155,7 +157,7 @@ def __init__( if transport_format is None: self.transport_format = ( - Configuration().EXPORTER_ZIPKIN_TRANSPORT_FORMAT + environ.get("OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT") or TRANSPORT_FORMAT_JSON ) else: diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index 30837106c1a..b25505705b0 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -18,7 +18,6 @@ from unittest.mock import MagicMock, patch from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.exporter.zipkin import ( NAME_KEY, SPAN_KIND_MAP_JSON, @@ -62,7 +61,6 @@ def tearDown(self): del os.environ["OTEL_EXPORTER_ZIPKIN_ENDPOINT"] if "OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" in os.environ: del os.environ["OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT"] - Configuration()._reset() # pylint: disable=protected-access def test_constructor_env_var(self): """Test the default values assigned by constructor.""" diff --git a/opentelemetry-api/src/opentelemetry/configuration/__init__.py b/opentelemetry-api/src/opentelemetry/configuration/__init__.py deleted file mode 100644 index 5e3d3667dc1..00000000000 --- a/opentelemetry-api/src/opentelemetry/configuration/__init__.py +++ /dev/null @@ -1,198 +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. - -""" -Simple configuration manager - -This is a configuration manager for OpenTelemetry. It reads configuration -values from environment variables prefixed with ``OTEL_`` (for environment -variables that apply to any OpenTelemetry implementation) or with -``OTEL_PYTHON_`` (for environment variables that are specific to the Python -implementation of OpenTelemetry) whose characters are only alphanumeric -characters and unserscores, except for the first character after ``OTEL_`` or -``OTEL_PYTHON_`` which must not be a number. - -For example, these environment variables will be read: - -1. ``OTEL_SOMETHING`` -2. ``OTEL_SOMETHING_ELSE_`` -3. ``OTEL_SOMETHING_ELSE_AND__ELSE`` -4. ``OTEL_SOMETHING_ELSE_AND_else`` -5. ``OTEL_SOMETHING_ELSE_AND_else2`` - -These won't: - -1. ``OPENTELEMETRY_PYTH_SOMETHING`` -2. ``OTEL_2_SOMETHING_AND__ELSE`` -3. ``OTEL_SOMETHING_%_ELSE`` - -The values stored in the environment variables can be found in an instance of -``opentelemetry.configuration.Configuration``. This class can be instantiated -freely because instantiating it returns always the same object. - -For example, if the environment variable -``OTEL_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then -``Configuration().METER_PROVIDER == "my_meter_provider"`` would be ``True``. - -Non defined attributes will always return ``None``. This is intended to make it -easier to use the ``Configuration`` object in actual code, because it won't be -necessary to check for the attribute to be defined first. - -Environment variables used by OpenTelemetry -------------------------------------------- - -1. OTEL_PYTHON_METER_PROVIDER -2. OTEL_PYTHON_TRACER_PROVIDER - -The value of these environment variables should be the name of the entry point -that points to the class that implements either provider. This OpenTelemetry -API package provides one entry point for each, which can be found in the -setup.py file:: - - entry_points={ - ... - "opentelemetry_meter_provider": [ - "default_meter_provider = " - "opentelemetry.metrics:DefaultMeterProvider" - ], - "opentelemetry_tracer_provider": [ - "default_tracer_provider = " - "opentelemetry.trace:DefaultTracerProvider" - ], - } - -To use the meter provider above, then the -``OTEL_PYTHON_METER_PROVIDER`` should be set to -``"default_meter_provider"`` (this is not actually necessary since the -OpenTelemetry API provided providers are the default ones used if no -configuration is found in the environment variables). - -Configuration values that are exactly ``"True"`` or ``"False"`` will be -converted to its boolean values of ``True`` and ``False`` respectively. - -Configuration values that can be casted to integers or floats will be casted. - -This object can be used by any OpenTelemetry component, native or external. -For that reason, the ``Configuration`` object is designed to be immutable. -If a component would change the value of one of the ``Configuration`` object -attributes then another component that relied on that value may break, leading -to bugs that are very hard to debug. To avoid this situation, the preferred -approach for components that need a different value than the one provided by -the ``Configuration`` object is to implement a mechanism that allows the user -to override this value instead of changing it. -""" - -import re -from os import environ -from typing import ClassVar, Dict, List, Optional, Sequence, TypeVar, Union - -ConfigValue = Union[str, bool, int, float] -_T = TypeVar("_T", ConfigValue, Optional[ConfigValue]) - - -class ExcludeList: - """Class to exclude certain paths (given as a list of regexes) from tracing requests""" - - def __init__(self, excluded_urls: Sequence[str]): - self._non_empty = len(excluded_urls) > 0 - if self._non_empty: - self._regex = re.compile("|".join(excluded_urls)) - - def url_disabled(self, url: str) -> bool: - return bool(self._non_empty and re.search(self._regex, url)) - - -class Configuration: - _instance = None # type: ClassVar[Optional[Configuration]] - _config_map = {} # type: ClassVar[Dict[str, ConfigValue]] - - def __new__(cls) -> "Configuration": - if cls._instance is not None: - instance = cls._instance - else: - - instance = super().__new__(cls) - for key, value_str in environ.items(): - - match = re.fullmatch(r"OTEL_(PYTHON_)?([A-Za-z_][\w_]*)", key) - - if match is not None: - - key = match.group(2) - value = value_str # type: ConfigValue - - if value_str == "True": - value = True - elif value_str == "False": - value = False - else: - try: - value = int(value_str) - except ValueError: - try: - value = float(value_str) - except ValueError: - pass - - instance._config_map[key] = value - - cls._instance = instance - - return instance - - def __getattr__(self, name: str) -> Optional[ConfigValue]: - return self._config_map.get(name) - - def __setattr__(self, name: str, value: ConfigValue) -> None: - if name not in self._config_map.keys(): - self._config_map[name] = value - else: - raise AttributeError(name) - - def get(self, name: str, default: _T) -> _T: - """Use this typed method for dynamic access instead of `getattr` - - :rtype: str or bool or int or float or None - """ - return self._config_map.get(name, default) - - @classmethod - def _reset(cls) -> None: - """ - This method "resets" the global configuration attributes - - It is not intended to be used by production code but by testing code - only. - """ - - if cls._instance: - cls._instance._config_map.clear() # pylint: disable=protected-access - cls._instance = None - - def _traced_request_attrs(self, instrumentation: str) -> List[str]: - """Returns list of traced request attributes for instrumentation.""" - key = "{}_TRACED_REQUEST_ATTRS".format(instrumentation.upper()) - value = self._config_map.get(key, "") - - request_attrs = ( - [attr.strip() for attr in str.split(value, ",")] if value else [] # type: ignore - ) - return request_attrs - - def _excluded_urls(self, instrumentation: str) -> ExcludeList: - key = "{}_EXCLUDED_URLS".format(instrumentation.upper()) - value = self._config_map.get(key, "") - - urls = str.split(value, ",") if value else [] # type: ignore - return ExcludeList(urls) diff --git a/opentelemetry-api/src/opentelemetry/configuration/py.typed b/opentelemetry-api/src/opentelemetry/configuration/py.typed deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/opentelemetry-api/src/opentelemetry/propagators/__init__.py b/opentelemetry-api/src/opentelemetry/propagators/__init__.py index fb2863ac8ad..4d8a1bc4270 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagators/__init__.py @@ -70,10 +70,10 @@ def example_route(): import typing from logging import getLogger +from os import environ from pkg_resources import iter_entry_points -from opentelemetry.configuration import Configuration from opentelemetry.context.context import Context from opentelemetry.propagators import composite from opentelemetry.trace.propagation import textmap @@ -125,10 +125,12 @@ def inject( propagators = [] - for propagator in ( # type: ignore - Configuration().get("PROPAGATORS", "tracecontext,baggage").split(",") # type: ignore - ): + # Single use variable here to hack black and make lint pass + environ_propagators = environ.get( + "OTEL_PROPAGATORS", "tracecontext,baggage", + ) + for propagator in environ_propagators.split(","): propagators.append( # type: ignore next( # type: ignore iter_entry_points("opentelemetry_propagator", propagator) # type: ignore diff --git a/opentelemetry-api/src/opentelemetry/util/__init__.py b/opentelemetry-api/src/opentelemetry/util/__init__.py index c1c5a77f098..c49ba1b353c 100644 --- a/opentelemetry-api/src/opentelemetry/util/__init__.py +++ b/opentelemetry-api/src/opentelemetry/util/__init__.py @@ -11,15 +11,14 @@ # 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 re + import time from logging import getLogger -from typing import TYPE_CHECKING, Sequence, Union, cast +from os import environ +from typing import TYPE_CHECKING, Union, cast from pkg_resources import iter_entry_points -from opentelemetry.configuration import Configuration - if TYPE_CHECKING: from opentelemetry.metrics import MeterProvider from opentelemetry.trace import TracerProvider @@ -47,7 +46,7 @@ def _load_provider(provider: str) -> Provider: "opentelemetry_{}".format(provider), name=cast( str, - Configuration().get( + environ.get( provider.upper(), "default_{}".format(provider), ), ), diff --git a/opentelemetry-api/tests/configuration/__init__.py b/opentelemetry-api/tests/configuration/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/opentelemetry-api/tests/configuration/test_configuration.py b/opentelemetry-api/tests/configuration/test_configuration.py deleted file mode 100644 index b36d93412b7..00000000000 --- a/opentelemetry-api/tests/configuration/test_configuration.py +++ /dev/null @@ -1,177 +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. -# pylint: disable-all - -from sys import platform -from unittest import TestCase -from unittest.mock import patch - -from opentelemetry.configuration import Configuration - - -class TestConfiguration(TestCase): - - # These calls reset the attributes of the Configuration class so that each - # test is executed in the same conditions. - def setUp(self) -> None: - Configuration._reset() - - def test_singleton(self) -> None: - self.assertIsInstance(Configuration(), Configuration) - self.assertIs(Configuration(), Configuration()) - - @patch.dict( - "os.environ", # type: ignore - { - "OTEL_PYTHON_METER_PROVIDER": "meter_provider", - "OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider", - "OTEL_OTHER" if platform == "windows" else "OTEL_OThER": "other", - "OTEL_OTHER_7": "other_7", - "OPENTELEMETRY_PTHON_TRACEX_PROVIDER": "tracex_provider", - }, - ) - def test_environment_variables(self) -> None: - self.assertEqual( - Configuration().METER_PROVIDER, "meter_provider" - ) # pylint: disable=no-member - self.assertEqual( - Configuration().TRACER_PROVIDER, "tracer_provider" - ) # pylint: disable=no-member - self.assertEqual( - Configuration().OThER, "other" - ) # pylint: disable=no-member - self.assertEqual( - Configuration().OTHER_7, "other_7" - ) # pylint: disable=no-member - self.assertIsNone(Configuration().TRACEX_PROVIDER) - - @patch.dict( - "os.environ", # type: ignore - {"OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider"}, - ) - def test_property(self) -> None: - with self.assertRaises(AttributeError): - Configuration().TRACER_PROVIDER = "new_tracer_provider" - - def test_set_once(self) -> None: - - Configuration().XYZ = "xyz" - - with self.assertRaises(AttributeError): - Configuration().XYZ = "abc" # pylint: disable=assigning-non-slot - - def test_getattr(self) -> None: - # literal access - self.assertIsNone(Configuration().XYZ) - - # dynamic access - self.assertIsNone(getattr(Configuration(), "XYZ")) - self.assertIsNone(Configuration().get("XYZ", None)) - - def test_reset(self) -> None: - environ_patcher = patch.dict( - "os.environ", {"OTEL_PYTHON_TRACER_PROVIDER": "tracer_provider"}, - ) - - environ_patcher.start() - - self.assertEqual( - Configuration().TRACER_PROVIDER, "tracer_provider" - ) # pylint: disable=no-member - - environ_patcher.stop() - - Configuration._reset() - - self.assertIsNone( - Configuration().TRACER_PROVIDER - ) # pylint: disable=no-member - - @patch.dict( - "os.environ", # type: ignore - {"OTEL_TRUE": "True", "OTEL_FALSE": "False"}, - ) - def test_boolean(self) -> None: - self.assertIsInstance( - Configuration().TRUE, bool - ) # pylint: disable=no-member - self.assertIsInstance( - Configuration().FALSE, bool - ) # pylint: disable=no-member - self.assertTrue(Configuration().TRUE) # pylint: disable=no-member - self.assertFalse(Configuration().FALSE) # pylint: disable=no-member - - @patch.dict( - "os.environ", # type: ignore - { - "OTEL_POSITIVE_INTEGER": "123", - "OTEL_NEGATIVE_INTEGER": "-123", - "OTEL_NON_INTEGER": "-12z3", - }, - ) - def test_integer(self) -> None: - # pylint: disable=no-member - self.assertIsInstance(Configuration().POSITIVE_INTEGER, int) - self.assertEqual(Configuration().POSITIVE_INTEGER, 123) - self.assertIsInstance(Configuration().NEGATIVE_INTEGER, int) - self.assertEqual(Configuration().NEGATIVE_INTEGER, -123) - self.assertEqual(Configuration().NON_INTEGER, "-12z3") - - @patch.dict( - "os.environ", # type: ignore - { - "OTEL_POSITIVE_FLOAT": "123.123", - "OTEL_NEGATIVE_FLOAT": "-123.123", - "OTEL_NON_FLOAT": "-12z3.123", - }, - ) - def test_float(self) -> None: - self.assertEqual( - Configuration().POSITIVE_FLOAT, 123.123 - ) # pylint: disable=no-member - self.assertEqual( - Configuration().NEGATIVE_FLOAT, -123.123 - ) # pylint: disable=no-member - self.assertEqual( - Configuration().NON_FLOAT, "-12z3.123" - ) # pylint: disable=no-member - - @patch.dict( - "os.environ", # type: ignore - { - "OTEL_PYTHON_WEBFRAMEWORK_TRACED_REQUEST_ATTRS": "content_type,keep_alive", - }, - ) - def test_traced_request_attrs(self) -> None: - cfg = Configuration() - request_attrs = cfg._traced_request_attrs("webframework") - self.assertEqual(len(request_attrs), 2) - self.assertIn("content_type", request_attrs) - self.assertIn("keep_alive", request_attrs) - self.assertNotIn("authorization", request_attrs) - - @patch.dict( - "os.environ", # type: ignore - { - "OTEL_PYTHON_WEBFRAMEWORK_EXCLUDED_URLS": "/healthzz,path,/issues/.*/view", - }, - ) - def test_excluded_urls(self) -> None: - cfg = Configuration() - excluded_urls = cfg._excluded_urls("webframework") - self.assertTrue(excluded_urls.url_disabled("/healthzz")) - self.assertTrue(excluded_urls.url_disabled("/path")) - self.assertTrue(excluded_urls.url_disabled("/issues/123/view")) - self.assertFalse(excluded_urls.url_disabled("/issues")) - self.assertFalse(excluded_urls.url_disabled("/hello")) diff --git a/opentelemetry-api/tests/configuration/test_exclude_list.py b/opentelemetry-api/tests/configuration/test_exclude_list.py deleted file mode 100644 index c7baf842ed7..00000000000 --- a/opentelemetry-api/tests/configuration/test_exclude_list.py +++ /dev/null @@ -1,60 +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. - -import unittest - -from opentelemetry.configuration import ExcludeList - - -class TestExcludeList(unittest.TestCase): - def test_basic(self): - regexes = ExcludeList(["path/123", "http://site.com/other_path"]) - self.assertTrue(regexes.url_disabled("http://site.com/path/123")) - self.assertTrue(regexes.url_disabled("http://site.com/path/123/abc")) - self.assertTrue( - regexes.url_disabled("https://site.com/path/123?arg=other") - ) - - self.assertFalse(regexes.url_disabled("https://site.com/path/abc/123")) - self.assertFalse(regexes.url_disabled("https://site.com/path")) - - self.assertTrue(regexes.url_disabled("http://site.com/other_path")) - self.assertTrue(regexes.url_disabled("http://site.com/other_path?abc")) - - self.assertFalse(regexes.url_disabled("https://site.com/other_path")) - self.assertFalse( - regexes.url_disabled("https://site.com/abc/other_path") - ) - - def test_regex(self): - regexes = ExcludeList( - [r"^https?://site\.com/path/123$", r"^http://.*\?arg=foo"] - ) - - self.assertTrue(regexes.url_disabled("http://site.com/path/123")) - self.assertTrue(regexes.url_disabled("https://site.com/path/123")) - - self.assertFalse(regexes.url_disabled("http://site.com/path/123/abc")) - self.assertFalse(regexes.url_disabled("http://site,com/path/123")) - - self.assertTrue( - regexes.url_disabled("http://site.com/path/123?arg=foo") - ) - self.assertTrue( - regexes.url_disabled("http://site.com/path/123?arg=foo,arg2=foo2") - ) - - self.assertFalse( - regexes.url_disabled("https://site.com/path/123?arg=foo") - ) diff --git a/opentelemetry-api/tests/propagators/test_propagators.py b/opentelemetry-api/tests/propagators/test_propagators.py index 70f4999dff7..487ee24dc54 100644 --- a/opentelemetry-api/tests/propagators/test_propagators.py +++ b/opentelemetry-api/tests/propagators/test_propagators.py @@ -18,7 +18,6 @@ from unittest.mock import Mock, patch from opentelemetry.baggage.propagation import BaggagePropagator -from opentelemetry.configuration import Configuration from opentelemetry.trace.propagation.tracecontext import ( TraceContextTextMapPropagator, ) @@ -50,9 +49,6 @@ def test_propagators(propagators): def test_non_default_propagators( self, mock_iter_entry_points, mock_compositehttppropagator ): - - Configuration._reset() - def iter_entry_points_mock(_, propagator): return iter( [ diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 8a48d256c7c..8d267c545aa 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -14,12 +14,12 @@ # import os from logging import getLogger +from os import environ from typing import Sequence, Tuple from pkg_resources import iter_entry_points from opentelemetry import trace -from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.instrumentation.distro import BaseDistro from opentelemetry.sdk.metrics.export import MetricsExporter @@ -43,15 +43,15 @@ def _get_ids_generator() -> str: - return Configuration().IDS_GENERATOR or _DEFAULT_IDS_GENERATOR + return environ.get("OTEL_IDS_GENERATOR") or _DEFAULT_IDS_GENERATOR def _get_service_name() -> str: - return Configuration().SERVICE_NAME or "" + return environ.get("OTEL_SERVICE_NAME") or "" def _get_exporter_names() -> Sequence[str]: - exporter = Configuration().EXPORTER or EXPORTER_OTLP + exporter = environ.get("OTEL_EXPORTER") or _DEFAULT_EXPORTER if exporter.lower().strip() == "none": return [] diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index 90ee7fe931f..c132d07369b 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -17,7 +17,6 @@ from unittest import TestCase from unittest.mock import patch -from opentelemetry.configuration import Configuration from opentelemetry.distro import ( _get_ids_generator, _import_ids_generator, @@ -100,7 +99,6 @@ def tearDown(self): # pylint: disable=protected-access def test_trace_init_default(self): environ["OTEL_SERVICE_NAME"] = "my-test-service" - Configuration._reset() _init_tracing({"zipkin": Exporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -115,7 +113,6 @@ def test_trace_init_default(self): def test_trace_init_otlp(self): environ["OTEL_SERVICE_NAME"] = "my-otlp-test-service" - Configuration._reset() _init_tracing({"otlp": OTLPExporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -140,7 +137,6 @@ def test_trace_init_custom_ids_generator(self, mock_iter_entry_points): IterEntryPoint("custom_ids_generator", CustomIdsGenerator) ] ) - Configuration._reset() ids_generator_name = _get_ids_generator() ids_generator = _import_ids_generator(ids_generator_name) _init_tracing({}, ids_generator) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py index 72be01fd18c..df98369b72b 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py @@ -12,14 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import sys from logging import getLogger +from os import environ, path from pkg_resources import iter_entry_points -from opentelemetry.configuration import Configuration - logger = getLogger(__file__) @@ -36,7 +34,9 @@ def _load_distros(): def _load_instrumentors(): - package_to_exclude = Configuration().get("DISABLED_INSTRUMENTATIONS", []) + package_to_exclude = environ.get( + "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS", [] + ) if isinstance(package_to_exclude, str): package_to_exclude = package_to_exclude.split(",") # to handle users entering "requests , flask" or "requests, flask" with spaces @@ -85,7 +85,7 @@ def initialize(): if ( hasattr(sys, "argv") - and sys.argv[0].split(os.path.sep)[-1] == "celery" + and sys.argv[0].split(path.sep)[-1] == "celery" and "worker" in sys.argv[1:] ): from celery.signals import worker_process_init # pylint:disable=E0401 diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py index dedeca20036..8cd77a8a5b7 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py @@ -58,19 +58,11 @@ def instrument(self, **kwargs): """Instrument the library This method will be called without any optional arguments by the - ``opentelemetry-instrument`` command. The configuration of - the instrumentation when done in this way should be done by previously - setting the configuration (using environment variables or any other - mechanism) that will be used later by the code in the ``instrument`` - implementation via the global ``Configuration`` object. - - The ``instrument`` methods ``kwargs`` should default to values from the - ``Configuration`` object. + ``opentelemetry-instrument`` command. This means that calling this method directly without passing any optional values should do the very same thing that the - ``opentelemetry-instrument`` command does. This approach is - followed because the ``Configuration`` object is immutable. + ``opentelemetry-instrument`` command does. """ if not self._is_instrumented: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index adafedb3da0..864469f1485 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -22,6 +22,7 @@ import traceback from collections import OrderedDict from contextlib import contextmanager +from os import environ from types import MappingProxyType, TracebackType from typing import ( Any, @@ -38,7 +39,6 @@ from opentelemetry import context as context_api from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.sdk import util from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import sampling @@ -55,11 +55,12 @@ logger = logging.getLogger(__name__) -SPAN_ATTRIBUTE_COUNT_LIMIT = Configuration().get( - "SPAN_ATTRIBUTE_COUNT_LIMIT", 1000 +SPAN_ATTRIBUTE_COUNT_LIMIT = int( + environ.get("OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", 1000) ) -SPAN_EVENT_COUNT_LIMIT = Configuration().get("SPAN_EVENT_COUNT_LIMIT", 1000) -SPAN_LINK_COUNT_LIMIT = Configuration().get("SPAN_LINK_COUNT_LIMIT", 1000) + +SPAN_EVENT_COUNT_LIMIT = int(environ.get("OTEL_SPAN_EVENT_COUNT_LIMIT", 1000)) +SPAN_LINK_COUNT_LIMIT = int(environ.get("OTEL_SPAN_LINK_COUNT_LIMIT", 1000)) VALID_ATTR_VALUE_TYPES = (bool, str, int, float) # pylint: disable=protected-access TRACE_SAMPLER = sampling._get_from_env_or_default() diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index ee63c84375f..71cebcd86da 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -13,16 +13,14 @@ # limitations under the License. import collections -import json import logging -import os import sys import threading import typing from enum import Enum +from os import environ, linesep from typing import Optional -from opentelemetry.configuration import Configuration from opentelemetry.context import Context, attach, detach, set_value from opentelemetry.sdk.trace import Span, SpanProcessor from opentelemetry.util import time_ns @@ -123,21 +121,21 @@ def __init__( ): if max_queue_size is None: - max_queue_size = Configuration().get("BSP_MAX_QUEUE_SIZE", 2048) + max_queue_size = int(environ.get("OTEL_BSP_MAX_QUEUE_SIZE", 2048)) if schedule_delay_millis is None: - schedule_delay_millis = Configuration().get( - "BSP_SCHEDULE_DELAY_MILLIS", 5000 + schedule_delay_millis = int( + environ.get("OTEL_BSP_SCHEDULE_DELAY_MILLIS", 5000) ) if max_export_batch_size is None: - max_export_batch_size = Configuration().get( - "BSP_MAX_EXPORT_BATCH_SIZE", 512 + max_export_batch_size = int( + environ.get("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", 512) ) if export_timeout_millis is None: - export_timeout_millis = Configuration().get( - "BSP_EXPORT_TIMEOUT_MILLIS", 30000 + export_timeout_millis = int( + environ.get("OTEL_BSP_EXPORT_TIMEOUT_MILLIS", 30000) ) if max_queue_size <= 0: @@ -375,7 +373,7 @@ def __init__( service_name: Optional[str] = None, out: typing.IO = sys.stdout, formatter: typing.Callable[[Span], str] = lambda span: span.to_json() - + os.linesep, + + linesep, ): self.out = out self.formatter = formatter diff --git a/opentelemetry-sdk/tests/trace/export/test_export.py b/opentelemetry-sdk/tests/trace/export/test_export.py index 92d4f65d136..8f429a6690e 100644 --- a/opentelemetry-sdk/tests/trace/export/test_export.py +++ b/opentelemetry-sdk/tests/trace/export/test_export.py @@ -21,7 +21,6 @@ from unittest import mock from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.context import Context from opentelemetry.sdk import trace from opentelemetry.sdk.trace import export @@ -155,11 +154,6 @@ def _create_start_and_end_span(name, span_processor): class TestBatchExportSpanProcessor(unittest.TestCase): - def tearDown(self) -> None: - # reset global state of configuration object - # pylint: disable=protected-access - Configuration._reset() - @mock.patch.dict( "os.environ", { diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index d17bd2ef215..28dbf448ff0 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -24,7 +24,6 @@ import pytest from opentelemetry import trace as trace_api -from opentelemetry.configuration import Configuration from opentelemetry.context import Context from opentelemetry.sdk import resources, trace from opentelemetry.sdk.trace import Resource, sampling @@ -1284,16 +1283,6 @@ def test_attributes_to_json(self): class TestSpanLimits(unittest.TestCase): - def setUp(self): - # reset global state of configuration object - # pylint: disable=protected-access - Configuration._reset() - - def tearDown(self): - # reset global state of configuration object - # pylint: disable=protected-access - Configuration._reset() - @mock.patch.dict( "os.environ", { From 1a60ce5786eed918f65230c106ab6d015b63f73c Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 12 Jan 2021 16:47:50 -0600 Subject: [PATCH 02/29] Fix mypy --- opentelemetry-api/src/opentelemetry/propagators/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/propagators/__init__.py b/opentelemetry-api/src/opentelemetry/propagators/__init__.py index 4d8a1bc4270..471857d12d2 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagators/__init__.py @@ -133,7 +133,7 @@ def inject( for propagator in environ_propagators.split(","): propagators.append( # type: ignore next( # type: ignore - iter_entry_points("opentelemetry_propagator", propagator) # type: ignore + iter_entry_points("opentelemetry_propagator", propagator) ).load()() ) From afeef4a5243992e23d2c881c3dd80feb303168dc Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 15 Jan 2021 19:28:09 -0600 Subject: [PATCH 03/29] Fix Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a83dd049e92..179ffea9f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - `opentelemetry-api` Remove ThreadLocalRuntimeContext since python3.4 is not supported. +- Remove Configuration + ([#1523](https://github.com/open-telemetry/opentelemetry-python/pull/1523)) ## [0.16b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.16b1) - 2020-11-26 ### Added From 33278be6048acc04695c4f9b74f12c81c4143eba Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 Jan 2021 08:33:03 -0600 Subject: [PATCH 04/29] Remove configuration from docs --- .github/workflows/test.yml | 2 +- docs/api/api.rst | 1 - docs/api/configuration.rst | 10 ---------- .../src/opentelemetry/distro/__init__.py | 2 +- 4 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 docs/api/configuration.rst diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a473fef774c..c5d15e10bfc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ env: # Otherwise, set variable to the commit of your branch on # opentelemetry-python-contrib which is compatible with these Core repo # changes. - CONTRIB_REPO_SHA: a67a23d0a0a4dd7c3c06c7050c220fa3b3689a77 + CONTRIB_REPO_SHA: 2be6c6e089d6879c782bd134d5f33043d1c6252e jobs: build: diff --git a/docs/api/api.rst b/docs/api/api.rst index ec6d8b03aa3..21eb5af6882 100644 --- a/docs/api/api.rst +++ b/docs/api/api.rst @@ -7,7 +7,6 @@ OpenTelemetry Python API :maxdepth: 1 baggage - configuration context metrics trace diff --git a/docs/api/configuration.rst b/docs/api/configuration.rst deleted file mode 100644 index 06ae4332776..00000000000 --- a/docs/api/configuration.rst +++ /dev/null @@ -1,10 +0,0 @@ -opentelemetry.configuration module -================================== - -Module contents ---------------- - -.. automodule:: opentelemetry.configuration - :members: - :undoc-members: - :show-inheritance: diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 8d267c545aa..a28a013e2d7 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -51,7 +51,7 @@ def _get_service_name() -> str: def _get_exporter_names() -> Sequence[str]: - exporter = environ.get("OTEL_EXPORTER") or _DEFAULT_EXPORTER + exporter = environ.get("OTEL_EXPORTER") or "EXPORTER_OTLP" if exporter.lower().strip() == "none": return [] From c77abbbb41e8e92fe3803e23c1b22b6291769c56 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 21 Jan 2021 18:05:53 -0600 Subject: [PATCH 05/29] Remove wsgi and asgi --- docs/examples/auto-instrumentation/server_instrumented.py | 2 +- .../src/opentelemetry/instrumentation/bootstrap.py | 4 ---- scripts/coverage.sh | 2 +- tox.ini | 4 ++-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/examples/auto-instrumentation/server_instrumented.py b/docs/examples/auto-instrumentation/server_instrumented.py index 6212ec33336..bc331de3ca4 100644 --- a/docs/examples/auto-instrumentation/server_instrumented.py +++ b/docs/examples/auto-instrumentation/server_instrumented.py @@ -15,13 +15,13 @@ from flask import Flask, request from opentelemetry import propagators, trace -from opentelemetry.instrumentation.wsgi import collect_request_attributes from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) from opentelemetry.trace.propagation.textmap import DictGetter +from opentelemetry.util.http.wsgi import collect_request_attributes app = Flask(__name__) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py index 44487a77947..ff2d244aa8f 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py @@ -35,7 +35,6 @@ instrumentations = { "aiohttp-client": "opentelemetry-instrumentation-aiohttp-client>=0.15b0", "aiopg": "opentelemetry-instrumentation-aiopg>=0.15b0", - "asgi": "opentelemetry-instrumentation-asgi>=0.11b0", "asyncpg": "opentelemetry-instrumentation-asyncpg>=0.11b0", "boto": "opentelemetry-instrumentation-boto>=0.11b0", "botocore": "opentelemetry-instrumentation-botocore>=0.11b0", @@ -61,14 +60,12 @@ "sqlite3": "opentelemetry-instrumentation-sqlite3>=0.11b0", "starlette": "opentelemetry-instrumentation-starlette>=0.11b0", "tornado": "opentelemetry-instrumentation-tornado>=0.13b0", - "wsgi": "opentelemetry-instrumentation-wsgi>=0.8b0", } # relevant instrumentors and tracers to uninstall and check for conflicts for target libraries libraries = { "aiohttp-client": ("opentelemetry-instrumentation-aiohttp-client",), "aiopg": ("opentelemetry-instrumentation-aiopg",), - "asgi": ("opentelemetry-instrumentation-asgi",), "asyncpg": ("opentelemetry-instrumentation-asyncpg",), "boto": ("opentelemetry-instrumentation-boto",), "botocore": ("opentelemetry-instrumentation-botocore",), @@ -94,7 +91,6 @@ "sqlite3": ("opentelemetry-instrumentation-sqlite3",), "starlette": ("opentelemetry-instrumentation-starlette",), "tornado": ("opentelemetry-instrumentation-tornado",), - "wsgi": ("opentelemetry-instrumentation-wsgi",), } diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 2b36a3f863d..00d98a0ca82 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -36,7 +36,7 @@ cov instrumentation/opentelemetry-instrumentation-flask cov instrumentation/opentelemetry-instrumentation-requests cov exporter/opentelemetry-exporter-jaeger cov instrumentation/opentelemetry-instrumentation-opentracing-shim -cov instrumentation/opentelemetry-instrumentation-wsgi +cov util/opentelemetry-util-http cov exporter/opentelemetry-exporter-zipkin # aiohttp is only supported on Python 3.5+. diff --git a/tox.ini b/tox.ini index 6f27fa0dcb4..ef5f3f5a65c 100644 --- a/tox.ini +++ b/tox.ini @@ -105,7 +105,7 @@ commands_pre = distro: pip install {toxinidir}/opentelemetry-distro {toxinidir}/opentelemetry-distro instrumentation: pip install {toxinidir}/opentelemetry-instrumentation - getting-started: pip install -e {toxinidir}/opentelemetry-instrumentation -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-requests -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-wsgi -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-flask + getting-started: pip install -e {toxinidir}/opentelemetry-instrumentation -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-requests {toxinidir}/opentelemetry-python-contrib/util/opentelemetry-util-http -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-flask opencensus: pip install {toxinidir}/exporter/opentelemetry-exporter-opencensus @@ -202,7 +202,7 @@ commands_pre = -e {toxinidir}/opentelemetry-instrumentation \ -e {toxinidir}/opentelemetry-sdk \ -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-requests \ - -e {toxinidir}/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-wsgi + -e {toxinidir}/opentelemetry-python-contrib/util/opentelemetry-util-http commands = {toxinidir}/scripts/tracecontext-integration-test.sh From 4ec13848b51635dc0837205504a7fcd569a78636 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 11:08:42 -0600 Subject: [PATCH 06/29] Add environment variable files --- .../opentelemetry/exporter/jaeger/__init__.py | 17 ++++-- .../src/opentelemetry/exporter/jaeger/util.py | 9 +++- .../tests/test_jaeger_exporter_protobuf.py | 8 ++- .../tests/test_jaeger_exporter_thrift.py | 17 ++++-- .../opentelemetry/exporter/otlp/exporter.py | 14 +++-- .../otlp/metrics_exporter/__init__.py | 20 ++++--- .../exporter/otlp/trace_exporter/__init__.py | 19 ++++--- .../tests/test_otlp_metric_exporter.py | 16 ++++-- .../tests/test_otlp_trace_exporter.py | 16 ++++-- .../opentelemetry/exporter/zipkin/__init__.py | 8 ++- .../tests/test_zipkin_exporter.py | 16 +++--- .../src/opentelemetry/context/__init__.py | 3 +- .../opentelemetry/environment_variables.py | 17 ++++++ .../src/opentelemetry/propagators/__init__.py | 3 +- .../tests/propagators/test_propagators.py | 3 +- .../src/opentelemetry/distro/__init__.py | 13 +++-- .../tests/test_configurator.py | 12 +++-- opentelemetry-distro/tests/test_distro.py | 5 +- .../auto_instrumentation/__init__.py | 12 +++-- .../auto_instrumentation/sitecustomize.py | 8 +-- .../tests/test_run.py | 12 +++-- .../sdk/environment_variables.py | 54 +++++++++++++++++++ .../opentelemetry/sdk/resources/__init__.py | 3 +- .../src/opentelemetry/sdk/trace/__init__.py | 11 ++-- .../sdk/trace/export/__init__.py | 14 +++-- .../src/opentelemetry/sdk/trace/sampling.py | 8 ++- opentelemetry-sdk/tests/conftest.py | 6 ++- .../tests/trace/export/test_export.py | 14 +++-- opentelemetry-sdk/tests/trace/test_trace.py | 19 ++++--- 29 files changed, 283 insertions(+), 94 deletions(-) create mode 100644 opentelemetry-api/src/opentelemetry/environment_variables.py create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py index aabcd8ac993..20b4bda3d9f 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py @@ -82,6 +82,13 @@ from opentelemetry.exporter.jaeger.translate import Translate from opentelemetry.exporter.jaeger.translate.protobuf import ProtobufTranslator from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_JAEGER_AGENT_HOST, + OTEL_EXPORTER_JAEGER_AGENT_PORT, + OTEL_EXPORTER_JAEGER_ENDPOINT, + OTEL_EXPORTER_JAEGER_PASSWORD, + OTEL_EXPORTER_JAEGER_USER, +) from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult DEFAULT_AGENT_HOST_NAME = "localhost" @@ -130,11 +137,11 @@ def __init__( self.service_name = service_name self.agent_host_name = _parameter_setter( param=agent_host_name, - env_variable=environ.get("OTEL_EXPORTER_JAEGER_AGENT_HOST"), + env_variable=environ.get(OTEL_EXPORTER_JAEGER_AGENT_HOST), default=DEFAULT_AGENT_HOST_NAME, ) - environ_agent_port = environ.get("OTEL_EXPORTER_JAEGER_AGENT_PORT") + environ_agent_port = environ.get(OTEL_EXPORTER_JAEGER_AGENT_PORT) environ_agent_port = ( int(environ_agent_port) if environ_agent_port is not None else None ) @@ -149,17 +156,17 @@ def __init__( ) self.collector_endpoint = _parameter_setter( param=collector_endpoint, - env_variable=environ.get("OTEL_EXPORTER_JAEGER_ENDPOINT"), + env_variable=environ.get(OTEL_EXPORTER_JAEGER_ENDPOINT), default=None, ) self.username = _parameter_setter( param=username, - env_variable=environ.get("OTEL_EXPORTER_JAEGER_USER"), + env_variable=environ.get(OTEL_EXPORTER_JAEGER_USER), default=None, ) self.password = _parameter_setter( param=password, - env_variable=environ.get("OTEL_EXPORTER_JAEGER_PASSWORD"), + env_variable=environ.get(OTEL_EXPORTER_JAEGER_PASSWORD), default=None, ) self._collector = None diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py index f5cb6a742da..4a72c1817c2 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py @@ -17,6 +17,11 @@ from grpc import ChannelCredentials, ssl_channel_credentials +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_JAEGER_CERTIFICATE, + OTEL_EXPORTER_JAEGER_INSECURE, +) + logger = logging.getLogger(__name__) DEFAULT_INSECURE = False @@ -25,7 +30,7 @@ def _get_insecure(param): if param is not None: return param - insecure_env = environ.get("OTEL_EXPORTER_JAEGER_INSECURE") + insecure_env = environ.get(OTEL_EXPORTER_JAEGER_INSECURE) if insecure_env is not None: return insecure_env.lower() == "true" return DEFAULT_INSECURE @@ -44,7 +49,7 @@ def _load_credential_from_file(path) -> ChannelCredentials: def _get_credentials(param): if param is not None: return param - creds_env = environ.get("OTEL_EXPORTER_JAEGER_CERTIFICATE") + creds_env = environ.get(OTEL_EXPORTER_JAEGER_CERTIFICATE) if creds_env: return _load_credential_from_file(creds_env) return ssl_channel_credentials() diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py index 0ba03f6d3db..26cfc41498e 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py @@ -29,6 +29,10 @@ Translate, ) from opentelemetry.sdk import trace +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_JAEGER_CERTIFICATE, + OTEL_EXPORTER_JAEGER_ENDPOINT, +) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace.status import Status, StatusCode @@ -59,8 +63,8 @@ def test_constructor_by_environment_variables(self): env_patch = patch.dict( "os.environ", { - "OTEL_EXPORTER_JAEGER_ENDPOINT": collector_endpoint, - "OTEL_EXPORTER_JAEGER_CERTIFICATE": os.path.dirname(__file__) + OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint, + OTEL_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(__file__) + "/certs/cred.cert", }, ) diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py index 1d95da5cf7f..47eebd31f05 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py @@ -24,6 +24,13 @@ from opentelemetry.exporter.jaeger.translate import Translate from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator from opentelemetry.sdk import trace +from opentelemetry.sdk.environment_variable import ( + OTEL_EXPORTER_JAEGER_AGENT_HOST, + OTEL_EXPORTER_JAEGER_AGENT_PORT, + OTEL_EXPORTER_JAEGER_ENDPOINT, + OTEL_EXPORTER_JAEGER_PASSWORD, + OTEL_EXPORTER_JAEGER_USER, +) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo from opentelemetry.trace import SpanKind @@ -115,11 +122,11 @@ def test_constructor_by_environment_variables(self): environ_patcher = mock.patch.dict( "os.environ", { - "OTEL_EXPORTER_JAEGER_AGENT_HOST": agent_host_name, - "OTEL_EXPORTER_JAEGER_AGENT_PORT": agent_port, - "OTEL_EXPORTER_JAEGER_ENDPOINT": collector_endpoint, - "OTEL_EXPORTER_JAEGER_USER": username, - "OTEL_EXPORTER_JAEGER_PASSWORD": password, + OTEL_EXPORTER_JAEGER_AGENT_HOST: agent_host_name, + OTEL_EXPORTER_JAEGER_AGENT_PORT: agent_port, + OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint, + OTEL_EXPORTER_JAEGER_USER: username, + OTEL_EXPORTER_JAEGER_PASSWORD: password, }, ) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index 16496150ed3..95e9603a323 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -38,6 +38,12 @@ from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import Resource +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_ENDPOINT, + OTEL_EXPORTER_OTLP_HEADERS, + OTEL_EXPORTER_OTLP_INSECURE, + OTEL_EXPORTER_OTLP_TIMEOUT, +) from opentelemetry.sdk.resources import Resource as SDKResource logger = logging.getLogger(__name__) @@ -159,23 +165,23 @@ def __init__( endpoint = ( endpoint - or environ.get("OTEL_EXPORTER_OTLP_ENDPOINT") + or environ.get(OTEL_EXPORTER_OTLP_ENDPOINT) or "localhost:4317" ) if insecure is None: - insecure = environ.get("OTEL_EXPORTER_OTLP_INSECURE") + insecure = environ.get(OTEL_EXPORTER_OTLP_INSECURE) if insecure is None: insecure = False - self._headers = headers or environ.get("OTEL_EXPORTER_OTLP_HEADERS") + self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): self._headers = tuple( tuple(item.split("=")) for item in self._headers.split(",") ) self._timeout = ( timeout - or int(environ.get("OTEL_EXPORTER_OTLP_TIMEOUT", 0)) + or int(environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 0)) or 10 # default: 10 seconds ) self._collector_span_kwargs = None diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index 9d98bca4552..8e388e9f9e1 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -44,6 +44,13 @@ ) from opentelemetry.proto.metrics.v1.metrics_pb2 import Metric as OTLPMetric from opentelemetry.proto.metrics.v1.metrics_pb2 import ResourceMetrics +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE, + OTEL_EXPORTER_OTLP_METRIC_ENDPOINT, + OTEL_EXPORTER_OTLP_METRIC_HEADERS, + OTEL_EXPORTER_OTLP_METRIC_INSECURE, + OTEL_EXPORTER_OTLP_METRIC_TIMEOUT, +) from opentelemetry.sdk.metrics import ( Counter, SumObserver, @@ -143,18 +150,17 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get("OTEL_EXPORTER_OTLP_METRIC_INSECURE") + insecure = environ.get(OTEL_EXPORTER_OTLP_METRIC_INSECURE) if ( not insecure - and environ.get("OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE") - is not None + and environ.get(OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE) is not None ): credentials = credentials or _load_credential_from_file( - environ.get("OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE") + environ.get(OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE) ) - environ_timeout = environ.get("OTEL_EXPORTER_OTLP_METRIC_TIMEOUT") + environ_timeout = environ.get(OTEL_EXPORTER_OTLP_METRIC_TIMEOUT) environ_timeout = ( int(environ_timeout) if environ_timeout is not None else None ) @@ -162,11 +168,11 @@ def __init__( super().__init__( **{ "endpoint": endpoint - or environ.get("OTEL_EXPORTER_OTLP_METRIC_ENDPOINT"), + or environ.get(OTEL_EXPORTER_OTLP_METRIC_ENDPOINT), "insecure": insecure, "credentials": credentials, "headers": headers - or environ.get("OTEL_EXPORTER_OTLP_METRIC_HEADERS"), + or environ.get(OTEL_EXPORTER_OTLP_METRIC_HEADERS), "timeout": timeout or environ_timeout, } ) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py index 77d617f55a4..96dbbc084b8 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py @@ -38,6 +38,13 @@ ) from opentelemetry.proto.trace.v1.trace_pb2 import Span as CollectorSpan from opentelemetry.proto.trace.v1.trace_pb2 import Status +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE, + OTEL_EXPORTER_OTLP_SPAN_ENDPOINT, + OTEL_EXPORTER_OTLP_SPAN_HEADERS, + OTEL_EXPORTER_OTLP_SPAN_INSECURE, + OTEL_EXPORTER_OTLP_SPAN_TIMEOUT, +) from opentelemetry.sdk.trace import Span as SDKSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace.status import StatusCode @@ -73,17 +80,17 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get("OTEL_EXPORTER_OTLP_SPAN_INSECURE") + insecure = environ.get(OTEL_EXPORTER_OTLP_SPAN_INSECURE) if ( not insecure - and environ.get("OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE") is not None + and environ.get(OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE) is not None ): credentials = credentials or _load_credential_from_file( - environ.get("OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE") + environ.get(OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE) ) - environ_timeout = environ.get("OTEL_EXPORTER_OTLP_SPAN_TIMEOUT") + environ_timeout = environ.get(OTEL_EXPORTER_OTLP_SPAN_TIMEOUT) environ_timeout = ( int(environ_timeout) if environ_timeout is not None else None ) @@ -91,11 +98,11 @@ def __init__( super().__init__( **{ "endpoint": endpoint - or environ.get("OTEL_EXPORTER_OTLP_SPAN_ENDPOINT"), + or environ.get(OTEL_EXPORTER_OTLP_SPAN_ENDPOINT), "insecure": insecure, "credentials": credentials, "headers": headers - or environ.get("OTEL_EXPORTER_OTLP_SPAN_HEADERS"), + or environ.get(OTEL_EXPORTER_OTLP_SPAN_HEADERS), "timeout": timeout or environ_timeout, } ) diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py index 82ef7652919..841dcff03e4 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py @@ -40,6 +40,12 @@ from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as OTLPResource, ) +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE, + OTEL_EXPORTER_OTLP_METRIC_ENDPOINT, + OTEL_EXPORTER_OTLP_METRIC_HEADERS, + OTEL_EXPORTER_OTLP_METRIC_TIMEOUT, +) from opentelemetry.sdk.metrics import ( Counter, MeterProvider, @@ -65,11 +71,11 @@ def setUp(self): # pylint: disable=arguments-differ @patch.dict( "os.environ", { - "OTEL_EXPORTER_OTLP_METRIC_ENDPOINT": "collector:4317", - "OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE": THIS_DIR + OTEL_EXPORTER_OTLP_METRIC_ENDPOINT: "collector:4317", + OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE: THIS_DIR + "/fixtures/test.cert", - "OTEL_EXPORTER_OTLP_METRIC_HEADERS": "key1=value1,key2=value2", - "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT": "10", + OTEL_EXPORTER_OTLP_METRIC_HEADERS: "key1=value1,key2=value2", + OTEL_EXPORTER_OTLP_METRIC_TIMEOUT: "10", }, ) @patch("opentelemetry.exporter.otlp.exporter.OTLPExporterMixin.__init__") @@ -99,7 +105,7 @@ def test_no_credentials_error( @patch.dict( "os.environ", - {"OTEL_EXPORTER_OTLP_METRIC_HEADERS": "key1=value1,key2=value2"}, + {OTEL_EXPORTER_OTLP_METRIC_HEADERS: "key1=value1,key2=value2"}, ) @patch("opentelemetry.exporter.otlp.exporter.ssl_channel_credentials") @patch("opentelemetry.exporter.otlp.exporter.secure_channel") diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py index 18c63394e64..a1dbcfbd63b 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py @@ -45,6 +45,12 @@ ) from opentelemetry.proto.trace.v1.trace_pb2 import Span as OTLPSpan from opentelemetry.proto.trace.v1.trace_pb2 import Status +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE, + OTEL_EXPORTER_OTLP_SPAN_ENDPOINT, + OTEL_EXPORTER_OTLP_SPAN_HEADERS, + OTEL_EXPORTER_OTLP_SPAN_TIMEOUT, +) from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.trace import Status as SDKStatus from opentelemetry.sdk.trace import StatusCode as SDKStatusCode @@ -165,11 +171,11 @@ def tearDown(self): @patch.dict( "os.environ", { - "OTEL_EXPORTER_OTLP_SPAN_ENDPOINT": "collector:4317", - "OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE": THIS_DIR + OTEL_EXPORTER_OTLP_SPAN_ENDPOINT: "collector:4317", + OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE: THIS_DIR + "/fixtures/test.cert", - "OTEL_EXPORTER_OTLP_SPAN_HEADERS": "key1=value1,key2=value2", - "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT": "10", + OTEL_EXPORTER_OTLP_SPAN_HEADERS: "key1=value1,key2=value2", + OTEL_EXPORTER_OTLP_SPAN_TIMEOUT: "10", }, ) @patch("opentelemetry.exporter.otlp.exporter.OTLPExporterMixin.__init__") @@ -197,7 +203,7 @@ def test_no_credentials_error( @patch.dict( "os.environ", - {"OTEL_EXPORTER_OTLP_SPAN_HEADERS": "key1=value1,key2=value2"}, + {OTEL_EXPORTER_OTLP_SPAN_HEADERS: "key1=value1,key2=value2"}, ) @patch("opentelemetry.exporter.otlp.exporter.ssl_channel_credentials") @patch("opentelemetry.exporter.otlp.exporter.secure_channel") diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index 209ea6140b5..30132bba8d5 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -80,6 +80,10 @@ import requests from opentelemetry.exporter.zipkin.gen import zipkin_pb2 +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_ZIPKIN_ENDPOINT, + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, +) from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace import Span, SpanContext, SpanKind from opentelemetry.trace.status import StatusCode @@ -143,7 +147,7 @@ def __init__( self.service_name = service_name if url is None: self.url = ( - environ.get("OTEL_EXPORTER_ZIPKIN_ENDPOINT") or DEFAULT_URL + environ.get(OTEL_EXPORTER_ZIPKIN_ENDPOINT) or DEFAULT_URL ) else: self.url = url @@ -157,7 +161,7 @@ def __init__( if transport_format is None: self.transport_format = ( - environ.get("OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT") + environ.get(OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT) or TRANSPORT_FORMAT_JSON ) else: diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index b25505705b0..5c2e0e7e4d0 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -30,6 +30,10 @@ ) from opentelemetry.exporter.zipkin.gen import zipkin_pb2 from opentelemetry.sdk import trace +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_ZIPKIN_ENDPOINT, + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, +) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.trace.export import SpanExportResult from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -57,17 +61,17 @@ def setUp(self): self._test_span.end() def tearDown(self): - if "OTEL_EXPORTER_ZIPKIN_ENDPOINT" in os.environ: - del os.environ["OTEL_EXPORTER_ZIPKIN_ENDPOINT"] - if "OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" in os.environ: - del os.environ["OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT"] + if OTEL_EXPORTER_ZIPKIN_ENDPOINT in os.environ: + del os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] + if OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT in os.environ: + del os.environ[OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT] def test_constructor_env_var(self): """Test the default values assigned by constructor.""" url = "https://foo:9911/path" - os.environ["OTEL_EXPORTER_ZIPKIN_ENDPOINT"] = url + os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] = url os.environ[ - "OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT ] = TRANSPORT_FORMAT_PROTOBUF service_name = "my-service-name" port = 9911 diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 22441c306b4..2f1249d4d03 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -21,6 +21,7 @@ from pkg_resources import iter_entry_points from opentelemetry.context.context import Context, RuntimeContext +from opentelemetry.environment_variables import OTEL_PYTHON_CONTEXT logger = logging.getLogger(__name__) _RUNTIME_CONTEXT = None # type: typing.Optional[RuntimeContext] @@ -50,7 +51,7 @@ def wrapper( default_context = "contextvars_context" configured_context = environ.get( - "OTEL_CONTEXT", default_context + OTEL_PYTHON_CONTEXT, default_context ) # type: str try: _RUNTIME_CONTEXT = next( diff --git a/opentelemetry-api/src/opentelemetry/environment_variables.py b/opentelemetry-api/src/opentelemetry/environment_variables.py new file mode 100644 index 00000000000..556d19b4a02 --- /dev/null +++ b/opentelemetry-api/src/opentelemetry/environment_variables.py @@ -0,0 +1,17 @@ +# 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_PROPAGATORS = "OTEL_PROPAGATORS" +OTEL_PYTHON_CONTEXT = "OTEL_PYTHON_CONTEXT" +OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS" diff --git a/opentelemetry-api/src/opentelemetry/propagators/__init__.py b/opentelemetry-api/src/opentelemetry/propagators/__init__.py index 471857d12d2..e92830ffab3 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagators/__init__.py @@ -75,6 +75,7 @@ def example_route(): from pkg_resources import iter_entry_points from opentelemetry.context.context import Context +from opentelemetry.environment_variables import OTEL_PROPAGATORS from opentelemetry.propagators import composite from opentelemetry.trace.propagation import textmap @@ -127,7 +128,7 @@ def inject( # Single use variable here to hack black and make lint pass environ_propagators = environ.get( - "OTEL_PROPAGATORS", "tracecontext,baggage", + OTEL_PROPAGATORS, "tracecontext,baggage", ) for propagator in environ_propagators.split(","): diff --git a/opentelemetry-api/tests/propagators/test_propagators.py b/opentelemetry-api/tests/propagators/test_propagators.py index 487ee24dc54..9fceb91a0b7 100644 --- a/opentelemetry-api/tests/propagators/test_propagators.py +++ b/opentelemetry-api/tests/propagators/test_propagators.py @@ -18,6 +18,7 @@ from unittest.mock import Mock, patch from opentelemetry.baggage.propagation import BaggagePropagator +from opentelemetry.environment_variables import OTEL_PROPAGATORS from opentelemetry.trace.propagation.tracecontext import ( TraceContextTextMapPropagator, ) @@ -43,7 +44,7 @@ def test_propagators(propagators): reload(opentelemetry.propagators) - @patch.dict(environ, {"OTEL_PROPAGATORS": "a,b,c"}) + @patch.dict(environ, {OTEL_PROPAGATORS: "a,b,c"}) @patch("opentelemetry.propagators.composite.CompositeHTTPPropagator") @patch("pkg_resources.iter_entry_points") def test_non_default_propagators( diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index a28a013e2d7..8b18194a1b3 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -22,6 +22,11 @@ from opentelemetry import trace from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.instrumentation.distro import BaseDistro +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER, + OTEL_IDS_GENERATOR, + OTEL_SERVICE_NAME, +) from opentelemetry.sdk.metrics.export import MetricsExporter from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider @@ -43,15 +48,15 @@ def _get_ids_generator() -> str: - return environ.get("OTEL_IDS_GENERATOR") or _DEFAULT_IDS_GENERATOR + return environ.get(OTEL_IDS_GENERATOR) or _DEFAULT_IDS_GENERATOR def _get_service_name() -> str: - return environ.get("OTEL_SERVICE_NAME") or "" + return environ.get(OTEL_SERVICE_NAME) or "" def _get_exporter_names() -> Sequence[str]: - exporter = environ.get("OTEL_EXPORTER") or "EXPORTER_OTLP" + exporter = environ.get(OTEL_EXPORTER) or "EXPORTER_OTLP" if exporter.lower().strip() == "none": return [] @@ -178,4 +183,4 @@ class OpenTelemetryDistro(BaseDistro): """ def _configure(self, **kwargs): - os.environ.setdefault("OTEL_EXPORTER", "otlp") + os.environ.setdefault(OTEL_EXPORTER, "otlp") diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index c132d07369b..6b606fe3f79 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -22,6 +22,10 @@ _import_ids_generator, _init_tracing, ) +from opentelemetry.sdk.environment_variables import ( + OTEL_IDS_GENERATOR, + OTEL_SERVICE_NAME, +) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace.ids_generator import ( IdsGenerator, @@ -98,7 +102,7 @@ def tearDown(self): # pylint: disable=protected-access def test_trace_init_default(self): - environ["OTEL_SERVICE_NAME"] = "my-test-service" + environ[OTEL_SERVICE_NAME] = "my-test-service" _init_tracing({"zipkin": Exporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -112,7 +116,7 @@ def test_trace_init_default(self): ) def test_trace_init_otlp(self): - environ["OTEL_SERVICE_NAME"] = "my-otlp-test-service" + environ[OTEL_SERVICE_NAME] = "my-otlp-test-service" _init_tracing({"otlp": OTLPExporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -126,9 +130,9 @@ def test_trace_init_otlp(self): provider.resource.attributes.get("service.name"), "my-otlp-test-service", ) - del environ["OTEL_SERVICE_NAME"] + del environ[OTEL_SERVICE_NAME] - @patch.dict(environ, {"OTEL_IDS_GENERATOR": "custom_ids_generator"}) + @patch.dict(environ, {OTEL_IDS_GENERATOR: "custom_ids_generator"}) @patch("opentelemetry.distro.IdsGenerator", new=IdsGenerator) @patch("opentelemetry.distro.iter_entry_points") def test_trace_init_custom_ids_generator(self, mock_iter_entry_points): diff --git a/opentelemetry-distro/tests/test_distro.py b/opentelemetry-distro/tests/test_distro.py index 62d3a7e5e3f..7a6b505f8de 100644 --- a/opentelemetry-distro/tests/test_distro.py +++ b/opentelemetry-distro/tests/test_distro.py @@ -19,6 +19,7 @@ from pkg_resources import DistributionNotFound, require from opentelemetry.distro import OpenTelemetryDistro +from opentelemetry.sdk.environment_variables import OTEL_EXPORTER class TestDistribution(TestCase): @@ -30,6 +31,6 @@ def test_package_available(self): def test_default_configuration(self): distro = OpenTelemetryDistro() - self.assertIsNone(os.environ.get("OTEL_EXPORTER")) + self.assertIsNone(os.environ.get(OTEL_EXPORTER)) distro.configure() - self.assertEqual("otlp", os.environ.get("OTEL_EXPORTER")) + self.assertEqual("otlp", os.environ.get(OTEL_EXPORTER)) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index 959708de964..a4dca73df68 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -20,6 +20,12 @@ from os.path import abspath, dirname, pathsep from shutil import which +from opentelemetry.environment_variables import ( + OTEL_EXPORTER, + OTEL_IDS_GENERATOR, + OTEL_SERVICE_NAME, +) + logger = getLogger(__file__) @@ -79,11 +85,11 @@ def parse_args(): def load_config_from_cli_args(args): if args.exporter: - environ["OTEL_EXPORTER"] = args.exporter + environ[OTEL_EXPORTER] = args.exporter if args.service_name: - environ["OTEL_SERVICE_NAME"] = args.service_name + environ[OTEL_SERVICE_NAME] = args.service_name if args.ids_generator: - environ["OTEL_IDS_GENERATOR"] = args.ids_generator + environ[OTEL_IDS_GENERATOR] = args.ids_generator def run() -> None: diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py index df98369b72b..ba84bce5858 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py @@ -18,6 +18,10 @@ from pkg_resources import iter_entry_points +from opentelemetry.environment_variables import ( + OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, +) + logger = getLogger(__file__) @@ -34,9 +38,7 @@ def _load_distros(): def _load_instrumentors(): - package_to_exclude = environ.get( - "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS", [] - ) + package_to_exclude = environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, []) if isinstance(package_to_exclude, str): package_to_exclude = package_to_exclude.split(",") # to handle users entering "requests , flask" or "requests, flask" with spaces diff --git a/opentelemetry-instrumentation/tests/test_run.py b/opentelemetry-instrumentation/tests/test_run.py index 9bff8514b14..ceab65a3610 100644 --- a/opentelemetry-instrumentation/tests/test_run.py +++ b/opentelemetry-instrumentation/tests/test_run.py @@ -19,6 +19,10 @@ from unittest.mock import patch from opentelemetry.instrumentation import auto_instrumentation +from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER, + OTEL_SERVICE_NAME, +) class TestRun(TestCase): @@ -107,18 +111,18 @@ class TestArgs(TestCase): def test_exporter(self, _): # pylint: disable=no-self-use with patch("sys.argv", ["instrument", "2"]): auto_instrumentation.run() - self.assertIsNone(environ.get("OTEL_EXPORTER")) + self.assertIsNone(environ.get(OTEL_EXPORTER)) with patch("sys.argv", ["instrument", "-e", "zipkin", "1", "2"]): auto_instrumentation.run() - self.assertEqual(environ.get("OTEL_EXPORTER"), "zipkin") + self.assertEqual(environ.get(OTEL_EXPORTER), "zipkin") @patch("opentelemetry.instrumentation.auto_instrumentation.execl") def test_service_name(self, _): # pylint: disable=no-self-use with patch("sys.argv", ["instrument", "2"]): auto_instrumentation.run() - self.assertIsNone(environ.get("OTEL_SERVICE_NAME")) + self.assertIsNone(environ.get(OTEL_SERVICE_NAME)) with patch("sys.argv", ["instrument", "-s", "my-service", "1", "2"]): auto_instrumentation.run() - self.assertEqual(environ.get("OTEL_SERVICE_NAME"), "my-service") + self.assertEqual(environ.get(OTEL_SERVICE_NAME), "my-service") diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py new file mode 100644 index 00000000000..c11bc4742c3 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py @@ -0,0 +1,54 @@ +# 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_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES" +OTEL_LOG_LEVEL = "OTEL_LOG_LEVEL" +OTEL_TRACE_SAMPLER = "OTEL_TRACE_SAMPLER" +OTEL_TRACE_SAMPLER_ARG = "OTEL_TRACE_SAMPLER_ARG" +OTEL_BSP_SCHEDULE_DELAY = "OTEL_BSP_SCHEDULE_DELAY" +OTEL_BSP_EXPORT_TIMEOUT = "OTEL_BSP_EXPORT_TIMEOUT" +OTEL_BSP_MAX_QUEUE_SIZE = "OTEL_BSP_MAX_QUEUE_SIZE" +OTEL_BSP_MAX_EXPORT_BATCH_SIZE = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE" +OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT" +OTEL_SPAN_EVENT_COUNT_LIMIT = "OTEL_SPAN_EVENT_COUNT_LIMIT" +OTEL_SPAN_LINK_COUNT_LIMIT = "OTEL_SPAN_LINK_COUNT_LIMIT" +OTEL_EXPORTER_JAEGER_AGENT_HOST = "OTEL_EXPORTER_JAEGER_AGENT_HOST" +OTEL_EXPORTER_JAEGER_AGENT_PORT = "OTEL_EXPORTER_JAEGER_AGENT_PORT" +OTEL_EXPORTER_JAEGER_ENDPOINT = "OTEL_EXPORTER_JAEGER_ENDPOINT" +OTEL_EXPORTER_JAEGER_USER = "OTEL_EXPORTER_JAEGER_USER" +OTEL_EXPORTER_JAEGER_PASSWORD = "OTEL_EXPORTER_JAEGER_PASSWORD" +OTEL_EXPORTER_ZIPKIN_ENDPOINT = "OTEL_EXPORTER_ZIPKIN_ENDPOINT" +OTEL_EXPORTER_PROMETHEUS_HOST = "OTEL_EXPORTER_PROMETHEUS_HOST" +OTEL_EXPORTER_PROMETHEUS_PORT = "OTEL_EXPORTER_PROMETHEUS_PORT" +OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" +OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" +OTEL_EXPORTER_ENDPOINT = "OTEL_EXPORTER_ENDPOINT" +OTEL_EXPORTER_OTLP_PROTOCOL = "OTEL_EXPORTER_OTLP_PROTOCOL" +OTEL_EXPORTER_OTLP_CERTIFICATE = "OTEL_EXPORTER_OTLP_CERTIFICATE" +OTEL_EXPORTER_OTLP_HEADERS = "OTEL_EXPORTER_OTLP_HEADERS" +OTEL_EXPORTER_OTLP_COMPRESSION = "OTEL_EXPORTER_OTLP_COMPRESSION" +OTEL_EXPORTER_OTLP_TIMEOUT = "OTEL_EXPORTER_OTLP_TIMEOUT" +OTEL_EXPORTER_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT" +OTEL_EXPORTER_OTLP_SPAN_ENDPOINT = "OTEL_EXPORTER_OTLP_SPAN_ENDPOINT" +OTEL_EXPORTER_OTLP_METRIC_ENDPOINT = "OTEL_EXPORTER_OTLP_METRIC_ENDPOINT" +OTEL_EXPORTER_OTLP_SPAN_PROTOCOL = "OTEL_EXPORTER_OTLP_SPAN_PROTOCOL" +OTEL_EXPORTER_OTLP_METRIC_PROTOCOL = "OTEL_EXPORTER_OTLP_METRIC_PROTOCOL" +OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE = "OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE" +OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE = "OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE" +OTEL_EXPORTER_OTLP_SPAN_HEADERS = "OTEL_EXPORTER_OTLP_SPAN_HEADERS" +OTEL_EXPORTER_OTLP_METRIC_HEADERS = "OTEL_EXPORTER_OTLP_METRIC_HEADERS" +OTEL_EXPORTER_OTLP_SPAN_COMPRESSION = "OTEL_EXPORTER_OTLP_SPAN_COMPRESSION" +OTEL_EXPORTER_OTLP_METRIC_COMPRESSION = "OTEL_EXPORTER_OTLP_METRIC_COMPRESSION" +OTEL_EXPORTER_OTLP_SPAN_TIMEOUT = "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT" +OTEL_EXPORTER_OTLP_METRIC_TIMEOUT = "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT" diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 2b832cff7d0..3bb32555c74 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -86,6 +86,8 @@ import pkg_resources +from opentelemetry.sdk.environment_variables import OTEL_RESOURCE_ATTRIBUTES + LabelValue = typing.Union[str, bool, int, float] Attributes = typing.Dict[str, LabelValue] logger = logging.getLogger(__name__) @@ -151,7 +153,6 @@ OPENTELEMETRY_SDK_VERSION = pkg_resources.get_distribution( "opentelemetry-sdk" ).version -OTEL_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES" class Resource: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 864469f1485..2ecb82a0c3d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -40,6 +40,11 @@ from opentelemetry import context as context_api from opentelemetry import trace as trace_api from opentelemetry.sdk import util +from opentelemetry.sdk.environment_variables import ( + OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, + OTEL_SPAN_EVENT_COUNT_LIMIT, + OTEL_SPAN_LINK_COUNT_LIMIT, +) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import sampling from opentelemetry.sdk.trace.ids_generator import ( @@ -56,11 +61,11 @@ logger = logging.getLogger(__name__) SPAN_ATTRIBUTE_COUNT_LIMIT = int( - environ.get("OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT", 1000) + environ.get(OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, 1000) ) -SPAN_EVENT_COUNT_LIMIT = int(environ.get("OTEL_SPAN_EVENT_COUNT_LIMIT", 1000)) -SPAN_LINK_COUNT_LIMIT = int(environ.get("OTEL_SPAN_LINK_COUNT_LIMIT", 1000)) +SPAN_EVENT_COUNT_LIMIT = int(environ.get(OTEL_SPAN_EVENT_COUNT_LIMIT, 1000)) +SPAN_LINK_COUNT_LIMIT = int(environ.get(OTEL_SPAN_LINK_COUNT_LIMIT, 1000)) VALID_ATTR_VALUE_TYPES = (bool, str, int, float) # pylint: disable=protected-access TRACE_SAMPLER = sampling._get_from_env_or_default() diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 71cebcd86da..f1a93b94f68 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -22,6 +22,12 @@ from typing import Optional from opentelemetry.context import Context, attach, detach, set_value +from opentelemetry.sdk.environment_variables import ( + OTEL_BSP_EXPORT_TIMEOUT_MILLIS, + OTEL_BSP_MAX_EXPORT_BATCH_SIZE, + OTEL_BSP_MAX_QUEUE_SIZE, + OTEL_BSP_SCHEDULE_DELAY_MILLIS, +) from opentelemetry.sdk.trace import Span, SpanProcessor from opentelemetry.util import time_ns @@ -121,21 +127,21 @@ def __init__( ): if max_queue_size is None: - max_queue_size = int(environ.get("OTEL_BSP_MAX_QUEUE_SIZE", 2048)) + max_queue_size = int(environ.get(OTEL_BSP_MAX_QUEUE_SIZE, 2048)) if schedule_delay_millis is None: schedule_delay_millis = int( - environ.get("OTEL_BSP_SCHEDULE_DELAY_MILLIS", 5000) + environ.get(OTEL_BSP_SCHEDULE_DELAY_MILLIS, 5000) ) if max_export_batch_size is None: max_export_batch_size = int( - environ.get("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", 512) + environ.get(OTEL_BSP_MAX_EXPORT_BATCH_SIZE, 512) ) if export_timeout_millis is None: export_timeout_millis = int( - environ.get("OTEL_BSP_EXPORT_TIMEOUT_MILLIS", 30000) + environ.get(OTEL_BSP_EXPORT_TIMEOUT_MILLIS, 30000) ) if max_queue_size <= 0: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py index b6475c4d345..2f449f985b9 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py @@ -104,6 +104,10 @@ # pylint: disable=unused-import from opentelemetry.context import Context +from opentelemetry.sdk.environment_variables import ( + OTEL_TRACE_SAMPLER, + OTEL_TRACE_SAMPLER_ARG, +) from opentelemetry.trace import Link, get_current_span from opentelemetry.trace.span import TraceState from opentelemetry.util.types import Attributes @@ -366,7 +370,7 @@ def __init__(self, rate: float): def _get_from_env_or_default() -> Sampler: trace_sampler = os.getenv( - "OTEL_TRACE_SAMPLER", "parentbased_always_on" + OTEL_TRACE_SAMPLER, "parentbased_always_on" ).lower() if trace_sampler not in _KNOWN_SAMPLERS: _logger.warning("Couldn't recognize sampler %s.", trace_sampler) @@ -374,7 +378,7 @@ def _get_from_env_or_default() -> Sampler: if trace_sampler in ("traceidratio", "parentbased_traceidratio"): try: - rate = float(os.getenv("OTEL_TRACE_SAMPLER_ARG")) + rate = float(os.getenv(OTEL_TRACE_SAMPLER_ARG)) except ValueError: _logger.warning("Could not convert TRACE_SAMPLER_ARG to float.") rate = 1.0 diff --git a/opentelemetry-sdk/tests/conftest.py b/opentelemetry-sdk/tests/conftest.py index 5652fda036c..92fd7a734de 100644 --- a/opentelemetry-sdk/tests/conftest.py +++ b/opentelemetry-sdk/tests/conftest.py @@ -14,12 +14,14 @@ from os import environ +from opentelemetry.environment_variables import OTEL_PYTHON_CONTEXT + def pytest_sessionstart(session): # pylint: disable=unused-argument - environ["OTEL_CONTEXT"] = "contextvars_context" + environ[OTEL_PYTHON_CONTEXT] = "contextvars_context" def pytest_sessionfinish(session): # pylint: disable=unused-argument - environ.pop("OTEL_CONTEXT") + environ.pop(OTEL_PYTHON_CONTEXT) diff --git a/opentelemetry-sdk/tests/trace/export/test_export.py b/opentelemetry-sdk/tests/trace/export/test_export.py index 8f429a6690e..2170b673574 100644 --- a/opentelemetry-sdk/tests/trace/export/test_export.py +++ b/opentelemetry-sdk/tests/trace/export/test_export.py @@ -23,6 +23,12 @@ from opentelemetry import trace as trace_api from opentelemetry.context import Context from opentelemetry.sdk import trace +from opentelemetry.sdk.environment_variables import ( + OTEL_BSP_EXPORT_TIMEOUT_MILLIS, + OTEL_BSP_MAX_EXPORT_BATCH_SIZE, + OTEL_BSP_MAX_QUEUE_SIZE, + OTEL_BSP_SCHEDULE_DELAY_MILLIS, +) from opentelemetry.sdk.trace import export @@ -157,10 +163,10 @@ class TestBatchExportSpanProcessor(unittest.TestCase): @mock.patch.dict( "os.environ", { - "OTEL_BSP_MAX_QUEUE_SIZE": "10", - "OTEL_BSP_SCHEDULE_DELAY_MILLIS": "2", - "OTEL_BSP_MAX_EXPORT_BATCH_SIZE": "3", - "OTEL_BSP_EXPORT_TIMEOUT_MILLIS": "4", + OTEL_BSP_MAX_QUEUE_SIZE: "10", + OTEL_BSP_SCHEDULE_DELAY_MILLIS: "2", + OTEL_BSP_MAX_EXPORT_BATCH_SIZE: "3", + OTEL_BSP_EXPORT_TIMEOUT_MILLIS: "4", }, ) def test_batch_span_processor_environment_variables(self): diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 28dbf448ff0..5099bb49152 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -26,6 +26,13 @@ from opentelemetry import trace as trace_api from opentelemetry.context import Context from opentelemetry.sdk import resources, trace +from opentelemetry.sdk.environment_variables import ( + OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, + OTEL_SPAN_EVENT_COUNT_LIMIT, + OTEL_SPAN_LINK_COUNT_LIMIT, + OTEL_TRACE_SAMPLER, + OTEL_TRACE_SAMPLER_ARG, +) from opentelemetry.sdk.trace import Resource, sampling from opentelemetry.sdk.trace.ids_generator import RandomIdsGenerator from opentelemetry.sdk.util import ns_to_iso_str @@ -187,7 +194,7 @@ def test_sampler_no_sampling(self): trace_api.TraceFlags.DEFAULT, ) - @mock.patch.dict("os.environ", {"OTEL_TRACE_SAMPLER": "always_off"}) + @mock.patch.dict("os.environ", {OTEL_TRACE_SAMPLER: "always_off"}) def test_sampler_with_env(self): # pylint: disable=protected-access reload(trace) @@ -206,8 +213,8 @@ def test_sampler_with_env(self): @mock.patch.dict( "os.environ", { - "OTEL_TRACE_SAMPLER": "parentbased_traceidratio", - "OTEL_TRACE_SAMPLER_ARG": "0.25", + OTEL_TRACE_SAMPLER: "parentbased_traceidratio", + OTEL_TRACE_SAMPLER_ARG: "0.25", }, ) def test_ratio_sampler_with_env(self): @@ -1286,9 +1293,9 @@ class TestSpanLimits(unittest.TestCase): @mock.patch.dict( "os.environ", { - "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT": "10", - "OTEL_SPAN_EVENT_COUNT_LIMIT": "20", - "OTEL_SPAN_LINK_COUNT_LIMIT": "30", + OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: "10", + OTEL_SPAN_EVENT_COUNT_LIMIT: "20", + OTEL_SPAN_LINK_COUNT_LIMIT: "30", }, ) def test_span_environment_limits(self): From 01ffc2812db57911fd276930fbc74618a5c8a622 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 14:33:16 -0600 Subject: [PATCH 07/29] Fixing missing environment variables --- .../src/opentelemetry/exporter/jaeger/util.py | 8 ++++---- .../tests/test_jaeger_exporter_protobuf.py | 6 ++++-- .../opentelemetry/exporter/otlp/exporter.py | 4 ++-- .../exporter/otlp/metrics_exporter/__init__.py | 4 ++-- .../exporter/otlp/trace_exporter/__init__.py | 4 ++-- .../opentelemetry/exporter/zipkin/__init__.py | 8 ++++---- .../tests/test_zipkin_exporter.py | 8 ++++---- .../src/opentelemetry/environment_variables.py | 3 +++ .../src/opentelemetry/distro/__init__.py | 18 +++++++++--------- .../tests/test_configurator.py | 14 +++++++------- opentelemetry-distro/tests/test_distro.py | 6 +++--- opentelemetry-instrumentation/README.rst | 6 +++--- .../auto_instrumentation/__init__.py | 12 ++++++------ .../tests/test_run.py | 18 ++++++++++-------- .../opentelemetry/sdk/environment_variables.py | 14 ++++++++++++++ .../opentelemetry/sdk/trace/export/__init__.py | 8 ++++---- .../tests/trace/export/test_export.py | 8 ++++---- 17 files changed, 85 insertions(+), 64 deletions(-) diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py index 4a72c1817c2..44f93c8363b 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py @@ -18,8 +18,8 @@ from grpc import ChannelCredentials, ssl_channel_credentials from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER_JAEGER_CERTIFICATE, - OTEL_EXPORTER_JAEGER_INSECURE, + OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE, + OTEL_PYTHON_EXPORTER_JAEGER_INSECURE, ) logger = logging.getLogger(__name__) @@ -30,7 +30,7 @@ def _get_insecure(param): if param is not None: return param - insecure_env = environ.get(OTEL_EXPORTER_JAEGER_INSECURE) + insecure_env = environ.get(OTEL_PYTHON_EXPORTER_JAEGER_INSECURE) if insecure_env is not None: return insecure_env.lower() == "true" return DEFAULT_INSECURE @@ -49,7 +49,7 @@ def _load_credential_from_file(path) -> ChannelCredentials: def _get_credentials(param): if param is not None: return param - creds_env = environ.get(OTEL_EXPORTER_JAEGER_CERTIFICATE) + creds_env = environ.get(OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE) if creds_env: return _load_credential_from_file(creds_env) return ssl_channel_credentials() diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py index 26cfc41498e..e1920fe2e4e 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py @@ -30,8 +30,8 @@ ) from opentelemetry.sdk import trace from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER_JAEGER_CERTIFICATE, OTEL_EXPORTER_JAEGER_ENDPOINT, + OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE, ) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -64,7 +64,9 @@ def test_constructor_by_environment_variables(self): "os.environ", { OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint, - OTEL_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(__file__) + OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname( + __file__ + ) + "/certs/cred.cert", }, ) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index 95e9603a323..9396e30cfe6 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -41,8 +41,8 @@ from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, - OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_INSECURE, ) from opentelemetry.sdk.resources import Resource as SDKResource @@ -170,7 +170,7 @@ def __init__( ) if insecure is None: - insecure = environ.get(OTEL_EXPORTER_OTLP_INSECURE) + insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_INSECURE) if insecure is None: insecure = False diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index 8e388e9f9e1..81c3746652e 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -48,8 +48,8 @@ OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE, OTEL_EXPORTER_OTLP_METRIC_ENDPOINT, OTEL_EXPORTER_OTLP_METRIC_HEADERS, - OTEL_EXPORTER_OTLP_METRIC_INSECURE, OTEL_EXPORTER_OTLP_METRIC_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE, ) from opentelemetry.sdk.metrics import ( Counter, @@ -150,7 +150,7 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get(OTEL_EXPORTER_OTLP_METRIC_INSECURE) + insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE) if ( not insecure diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py index 96dbbc084b8..4d47e1622b4 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py @@ -42,8 +42,8 @@ OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE, OTEL_EXPORTER_OTLP_SPAN_ENDPOINT, OTEL_EXPORTER_OTLP_SPAN_HEADERS, - OTEL_EXPORTER_OTLP_SPAN_INSECURE, OTEL_EXPORTER_OTLP_SPAN_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE, ) from opentelemetry.sdk.trace import Span as SDKSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -80,7 +80,7 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get(OTEL_EXPORTER_OTLP_SPAN_INSECURE) + insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE) if ( not insecure diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index 30132bba8d5..01fea11ff9a 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -27,7 +27,7 @@ .. _Specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-environment-variables.md#zipkin-exporter .. envvar:: OTEL_EXPORTER_ZIPKIN_ENDPOINT -.. envvar:: OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT +.. envvar:: OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT .. code:: python @@ -63,7 +63,7 @@ :envvar:`OTEL_EXPORTER_ZIPKIN_ENDPOINT`: target to which the exporter will send data. This may include a path (e.g. http://example.com:9411/api/v2/spans). -:envvar:`OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT`: transport interchange format +:envvar:`OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT`: transport interchange format to use when sending data. Currently only Zipkin's v2 json and protobuf formats are supported, with v2 json being the default. @@ -82,7 +82,7 @@ from opentelemetry.exporter.zipkin.gen import zipkin_pb2 from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_ZIPKIN_ENDPOINT, - OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, + OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, ) from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace import Span, SpanContext, SpanKind @@ -161,7 +161,7 @@ def __init__( if transport_format is None: self.transport_format = ( - environ.get(OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT) + environ.get(OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT) or TRANSPORT_FORMAT_JSON ) else: diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index 5c2e0e7e4d0..ca818871eda 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -32,7 +32,7 @@ from opentelemetry.sdk import trace from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_ZIPKIN_ENDPOINT, - OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, + OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, ) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.trace.export import SpanExportResult @@ -63,15 +63,15 @@ def setUp(self): def tearDown(self): if OTEL_EXPORTER_ZIPKIN_ENDPOINT in os.environ: del os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] - if OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT in os.environ: - del os.environ[OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT] + if OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT in os.environ: + del os.environ[OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT] def test_constructor_env_var(self): """Test the default values assigned by constructor.""" url = "https://foo:9911/path" os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] = url os.environ[ - OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT + OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT ] = TRANSPORT_FORMAT_PROTOBUF service_name = "my-service-name" port = 9911 diff --git a/opentelemetry-api/src/opentelemetry/environment_variables.py b/opentelemetry-api/src/opentelemetry/environment_variables.py index 556d19b4a02..3fd2372165d 100644 --- a/opentelemetry-api/src/opentelemetry/environment_variables.py +++ b/opentelemetry-api/src/opentelemetry/environment_variables.py @@ -15,3 +15,6 @@ OTEL_PROPAGATORS = "OTEL_PROPAGATORS" OTEL_PYTHON_CONTEXT = "OTEL_PYTHON_CONTEXT" OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS" +OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR" +OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" +OTEL_PYTHON_EXPORTER = "OTEL_PYTHON_EXPORTER" diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 8b18194a1b3..7153a9266c7 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -20,13 +20,13 @@ from pkg_resources import iter_entry_points from opentelemetry import trace +from opentelemetry.environment_variables import ( + OTEL_PYTHON_EXPORTER, + OTEL_PYTHON_IDS_GENERATOR, + OTEL_PYTHON_SERVICE_NAME, +) from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.instrumentation.distro import BaseDistro -from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER, - OTEL_IDS_GENERATOR, - OTEL_SERVICE_NAME, -) from opentelemetry.sdk.metrics.export import MetricsExporter from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider @@ -48,15 +48,15 @@ def _get_ids_generator() -> str: - return environ.get(OTEL_IDS_GENERATOR) or _DEFAULT_IDS_GENERATOR + return environ.get(OTEL_PYTHON_IDS_GENERATOR) or _DEFAULT_IDS_GENERATOR def _get_service_name() -> str: - return environ.get(OTEL_SERVICE_NAME) or "" + return environ.get(OTEL_PYTHON_SERVICE_NAME) or "" def _get_exporter_names() -> Sequence[str]: - exporter = environ.get(OTEL_EXPORTER) or "EXPORTER_OTLP" + exporter = environ.get(OTEL_PYTHON_EXPORTER) or "EXPORTER_OTLP" if exporter.lower().strip() == "none": return [] @@ -183,4 +183,4 @@ class OpenTelemetryDistro(BaseDistro): """ def _configure(self, **kwargs): - os.environ.setdefault(OTEL_EXPORTER, "otlp") + os.environ.setdefault(OTEL_PYTHON_EXPORTER, "otlp") diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index 6b606fe3f79..e1a8cfc8ae0 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -22,9 +22,9 @@ _import_ids_generator, _init_tracing, ) -from opentelemetry.sdk.environment_variables import ( - OTEL_IDS_GENERATOR, - OTEL_SERVICE_NAME, +from opentelemetry.environment_variables import ( + OTEL_PYTHON_IDS_GENERATOR, + OTEL_PYTHON_SERVICE_NAME, ) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace.ids_generator import ( @@ -102,7 +102,7 @@ def tearDown(self): # pylint: disable=protected-access def test_trace_init_default(self): - environ[OTEL_SERVICE_NAME] = "my-test-service" + environ[OTEL_PYTHON_SERVICE_NAME] = "my-test-service" _init_tracing({"zipkin": Exporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -116,7 +116,7 @@ def test_trace_init_default(self): ) def test_trace_init_otlp(self): - environ[OTEL_SERVICE_NAME] = "my-otlp-test-service" + environ[OTEL_PYTHON_SERVICE_NAME] = "my-otlp-test-service" _init_tracing({"otlp": OTLPExporter}, RandomIdsGenerator) self.assertEqual(self.set_provider_mock.call_count, 1) @@ -130,9 +130,9 @@ def test_trace_init_otlp(self): provider.resource.attributes.get("service.name"), "my-otlp-test-service", ) - del environ[OTEL_SERVICE_NAME] + del environ[OTEL_PYTHON_SERVICE_NAME] - @patch.dict(environ, {OTEL_IDS_GENERATOR: "custom_ids_generator"}) + @patch.dict(environ, {OTEL_PYTHON_IDS_GENERATOR: "custom_ids_generator"}) @patch("opentelemetry.distro.IdsGenerator", new=IdsGenerator) @patch("opentelemetry.distro.iter_entry_points") def test_trace_init_custom_ids_generator(self, mock_iter_entry_points): diff --git a/opentelemetry-distro/tests/test_distro.py b/opentelemetry-distro/tests/test_distro.py index 7a6b505f8de..4412f26609a 100644 --- a/opentelemetry-distro/tests/test_distro.py +++ b/opentelemetry-distro/tests/test_distro.py @@ -19,7 +19,7 @@ from pkg_resources import DistributionNotFound, require from opentelemetry.distro import OpenTelemetryDistro -from opentelemetry.sdk.environment_variables import OTEL_EXPORTER +from opentelemetry.environment_variables import OTEL_PYTHON_EXPORTER class TestDistribution(TestCase): @@ -31,6 +31,6 @@ def test_package_available(self): def test_default_configuration(self): distro = OpenTelemetryDistro() - self.assertIsNone(os.environ.get(OTEL_EXPORTER)) + self.assertIsNone(os.environ.get(OTEL_PYTHON_EXPORTER)) distro.configure() - self.assertEqual("otlp", os.environ.get(OTEL_EXPORTER)) + self.assertEqual("otlp", os.environ.get(OTEL_PYTHON_EXPORTER)) diff --git a/opentelemetry-instrumentation/README.rst b/opentelemetry-instrumentation/README.rst index 97ebc5e7c49..824aa23e69e 100644 --- a/opentelemetry-instrumentation/README.rst +++ b/opentelemetry-instrumentation/README.rst @@ -48,7 +48,7 @@ this can be overriden when needed. The command supports the following configuration options as CLI arguments and environment vars: -* ``--exporter`` or ``OTEL_EXPORTER`` +* ``--exporter`` or ``OTEL_PYTHON_EXPORTER`` Used to specify which trace exporter to use. Can be set to one or more of the well-known exporter names (see below). @@ -69,11 +69,11 @@ Well known trace exporter names: ``otlp`` is an alias for ``otlp_span,otlp_metric``. -* ``--service-name`` or ``OTEL_SERVICE_NAME`` +* ``--service-name`` or ``OTEL_PYTHON_SERVICE_NAME`` When present the value is passed on to the relevant exporter initializer as ``service_name`` argument. -* ``--ids-generator`` or ``OTEL_IDS_GENERATOR`` +* ``--ids-generator`` or ``OTEL_PYTHON_IDS_GENERATOR`` Used to specify which IDs Generator to use for the global Tracer Provider. By default, it will use the random IDs generator. diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index a4dca73df68..87bf982128f 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -21,9 +21,9 @@ from shutil import which from opentelemetry.environment_variables import ( - OTEL_EXPORTER, - OTEL_IDS_GENERATOR, - OTEL_SERVICE_NAME, + OTEL_PYTHON_EXPORTER, + OTEL_PYTHON_IDS_GENERATOR, + OTEL_PYTHON_SERVICE_NAME, ) logger = getLogger(__file__) @@ -85,11 +85,11 @@ def parse_args(): def load_config_from_cli_args(args): if args.exporter: - environ[OTEL_EXPORTER] = args.exporter + environ[OTEL_PYTHON_EXPORTER] = args.exporter if args.service_name: - environ[OTEL_SERVICE_NAME] = args.service_name + environ[OTEL_PYTHON_SERVICE_NAME] = args.service_name if args.ids_generator: - environ[OTEL_IDS_GENERATOR] = args.ids_generator + environ[OTEL_PYTHON_IDS_GENERATOR] = args.ids_generator def run() -> None: diff --git a/opentelemetry-instrumentation/tests/test_run.py b/opentelemetry-instrumentation/tests/test_run.py index ceab65a3610..57562b449e5 100644 --- a/opentelemetry-instrumentation/tests/test_run.py +++ b/opentelemetry-instrumentation/tests/test_run.py @@ -18,11 +18,11 @@ from unittest import TestCase from unittest.mock import patch -from opentelemetry.instrumentation import auto_instrumentation -from opentelemetry.sdk.environment_variables import ( - OTEL_EXPORTER, - OTEL_SERVICE_NAME, +from opentelemetry.environment_variables import ( + OTEL_PYTHON_EXPORTER, + OTEL_PYTHON_SERVICE_NAME, ) +from opentelemetry.instrumentation import auto_instrumentation class TestRun(TestCase): @@ -111,18 +111,20 @@ class TestArgs(TestCase): def test_exporter(self, _): # pylint: disable=no-self-use with patch("sys.argv", ["instrument", "2"]): auto_instrumentation.run() - self.assertIsNone(environ.get(OTEL_EXPORTER)) + self.assertIsNone(environ.get(OTEL_PYTHON_EXPORTER)) with patch("sys.argv", ["instrument", "-e", "zipkin", "1", "2"]): auto_instrumentation.run() - self.assertEqual(environ.get(OTEL_EXPORTER), "zipkin") + self.assertEqual(environ.get(OTEL_PYTHON_EXPORTER), "zipkin") @patch("opentelemetry.instrumentation.auto_instrumentation.execl") def test_service_name(self, _): # pylint: disable=no-self-use with patch("sys.argv", ["instrument", "2"]): auto_instrumentation.run() - self.assertIsNone(environ.get(OTEL_SERVICE_NAME)) + self.assertIsNone(environ.get(OTEL_PYTHON_SERVICE_NAME)) with patch("sys.argv", ["instrument", "-s", "my-service", "1", "2"]): auto_instrumentation.run() - self.assertEqual(environ.get(OTEL_SERVICE_NAME), "my-service") + self.assertEqual( + environ.get(OTEL_PYTHON_SERVICE_NAME), "my-service" + ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py index c11bc4742c3..5c767f24463 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py @@ -52,3 +52,17 @@ OTEL_EXPORTER_OTLP_METRIC_COMPRESSION = "OTEL_EXPORTER_OTLP_METRIC_COMPRESSION" OTEL_EXPORTER_OTLP_SPAN_TIMEOUT = "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT" OTEL_EXPORTER_OTLP_METRIC_TIMEOUT = "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT" +OTEL_PYTHON_EXPORTER_JAEGER_INSECURE = "OTEL_PYTHON_EXPORTER_JAEGER_INSECURE" +OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE = ( + "OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE" +) +OTEL_PYTHON_EXPORTER_OTLP_INSECURE = "OTEL_PYTHON_EXPORTER_OTLP_INSECURE" +OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE = ( + "OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE" +) +OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE = ( + "OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE" +) +OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT = ( + "OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" +) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index f1a93b94f68..4d4cc70224f 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -23,10 +23,10 @@ from opentelemetry.context import Context, attach, detach, set_value from opentelemetry.sdk.environment_variables import ( - OTEL_BSP_EXPORT_TIMEOUT_MILLIS, + OTEL_BSP_EXPORT_TIMEOUT, OTEL_BSP_MAX_EXPORT_BATCH_SIZE, OTEL_BSP_MAX_QUEUE_SIZE, - OTEL_BSP_SCHEDULE_DELAY_MILLIS, + OTEL_BSP_SCHEDULE_DELAY, ) from opentelemetry.sdk.trace import Span, SpanProcessor from opentelemetry.util import time_ns @@ -131,7 +131,7 @@ def __init__( if schedule_delay_millis is None: schedule_delay_millis = int( - environ.get(OTEL_BSP_SCHEDULE_DELAY_MILLIS, 5000) + environ.get(OTEL_BSP_SCHEDULE_DELAY, 5000) ) if max_export_batch_size is None: @@ -141,7 +141,7 @@ def __init__( if export_timeout_millis is None: export_timeout_millis = int( - environ.get(OTEL_BSP_EXPORT_TIMEOUT_MILLIS, 30000) + environ.get(OTEL_BSP_EXPORT_TIMEOUT, 30000) ) if max_queue_size <= 0: diff --git a/opentelemetry-sdk/tests/trace/export/test_export.py b/opentelemetry-sdk/tests/trace/export/test_export.py index 2170b673574..86cd990cca6 100644 --- a/opentelemetry-sdk/tests/trace/export/test_export.py +++ b/opentelemetry-sdk/tests/trace/export/test_export.py @@ -24,10 +24,10 @@ from opentelemetry.context import Context from opentelemetry.sdk import trace from opentelemetry.sdk.environment_variables import ( - OTEL_BSP_EXPORT_TIMEOUT_MILLIS, + OTEL_BSP_EXPORT_TIMEOUT, OTEL_BSP_MAX_EXPORT_BATCH_SIZE, OTEL_BSP_MAX_QUEUE_SIZE, - OTEL_BSP_SCHEDULE_DELAY_MILLIS, + OTEL_BSP_SCHEDULE_DELAY, ) from opentelemetry.sdk.trace import export @@ -164,9 +164,9 @@ class TestBatchExportSpanProcessor(unittest.TestCase): "os.environ", { OTEL_BSP_MAX_QUEUE_SIZE: "10", - OTEL_BSP_SCHEDULE_DELAY_MILLIS: "2", + OTEL_BSP_SCHEDULE_DELAY: "2", OTEL_BSP_MAX_EXPORT_BATCH_SIZE: "3", - OTEL_BSP_EXPORT_TIMEOUT_MILLIS: "4", + OTEL_BSP_EXPORT_TIMEOUT: "4", }, ) def test_batch_span_processor_environment_variables(self): From b72fe8080e39a2582e01f88a8c8c75edd7be418d Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 15:48:49 -0600 Subject: [PATCH 08/29] Name fix --- .../tests/test_jaeger_exporter_thrift.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py index 47eebd31f05..947597ab469 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py @@ -24,7 +24,7 @@ from opentelemetry.exporter.jaeger.translate import Translate from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator from opentelemetry.sdk import trace -from opentelemetry.sdk.environment_variable import ( +from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_JAEGER_AGENT_HOST, OTEL_EXPORTER_JAEGER_AGENT_PORT, OTEL_EXPORTER_JAEGER_ENDPOINT, From 64f64282d5b5c241ae1cc303ada396b82831d99b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 16:01:15 -0600 Subject: [PATCH 09/29] Fix docs --- docs/api/api.rst | 1 + docs/api/environment_variables.rst | 10 ++++++++++ docs/sdk/environment_variables.rst | 12 ++++++++++++ docs/sdk/sdk.rst | 1 + 4 files changed, 24 insertions(+) create mode 100644 docs/api/environment_variables.rst create mode 100644 docs/sdk/environment_variables.rst diff --git a/docs/api/api.rst b/docs/api/api.rst index 21eb5af6882..d132b78cf81 100644 --- a/docs/api/api.rst +++ b/docs/api/api.rst @@ -10,3 +10,4 @@ OpenTelemetry Python API context metrics trace + environment_variables diff --git a/docs/api/environment_variables.rst b/docs/api/environment_variables.rst new file mode 100644 index 00000000000..5cf1ec1052e --- /dev/null +++ b/docs/api/environment_variables.rst @@ -0,0 +1,10 @@ +opentelemetry.environment_variables +=================================== + +.. toctree:: + :maxdepth: 1 + +.. automodule:: opentelemetry.environment_variables + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/sdk/environment_variables.rst b/docs/sdk/environment_variables.rst new file mode 100644 index 00000000000..084a34b7bea --- /dev/null +++ b/docs/sdk/environment_variables.rst @@ -0,0 +1,12 @@ +opentelemetry.sdk.environment_variables +======================================= + +.. TODO: what is the SDK + +.. toctree:: + :maxdepth: 1 + +.. automodule:: opentelemetry.sdk.environment_variables + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/sdk/sdk.rst b/docs/sdk/sdk.rst index e777aebac65..1c5653e1b30 100644 --- a/docs/sdk/sdk.rst +++ b/docs/sdk/sdk.rst @@ -10,3 +10,4 @@ OpenTelemetry Python SDK resources trace error_handler + environment_variables From 94f302839aa94b52ccdf40215dc9a0e9c8a6a521 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 17:22:00 -0600 Subject: [PATCH 10/29] Var --- docs/api/environment_variables.rst | 11 ++- .../opentelemetry/environment_variables.py | 20 ------ .../sdk/environment_variables.py | 68 ------------------- 3 files changed, 4 insertions(+), 95 deletions(-) delete mode 100644 opentelemetry-api/src/opentelemetry/environment_variables.py delete mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py diff --git a/docs/api/environment_variables.rst b/docs/api/environment_variables.rst index 5cf1ec1052e..284675cf080 100644 --- a/docs/api/environment_variables.rst +++ b/docs/api/environment_variables.rst @@ -1,10 +1,7 @@ -opentelemetry.environment_variables -=================================== +opentelemetry.environment_variables package +=========================================== -.. toctree:: - :maxdepth: 1 +Module contents +--------------- .. automodule:: opentelemetry.environment_variables - :members: - :undoc-members: - :show-inheritance: diff --git a/opentelemetry-api/src/opentelemetry/environment_variables.py b/opentelemetry-api/src/opentelemetry/environment_variables.py deleted file mode 100644 index 3fd2372165d..00000000000 --- a/opentelemetry-api/src/opentelemetry/environment_variables.py +++ /dev/null @@ -1,20 +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. - -OTEL_PROPAGATORS = "OTEL_PROPAGATORS" -OTEL_PYTHON_CONTEXT = "OTEL_PYTHON_CONTEXT" -OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS" -OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR" -OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" -OTEL_PYTHON_EXPORTER = "OTEL_PYTHON_EXPORTER" diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py deleted file mode 100644 index 5c767f24463..00000000000 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables.py +++ /dev/null @@ -1,68 +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. - -OTEL_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES" -OTEL_LOG_LEVEL = "OTEL_LOG_LEVEL" -OTEL_TRACE_SAMPLER = "OTEL_TRACE_SAMPLER" -OTEL_TRACE_SAMPLER_ARG = "OTEL_TRACE_SAMPLER_ARG" -OTEL_BSP_SCHEDULE_DELAY = "OTEL_BSP_SCHEDULE_DELAY" -OTEL_BSP_EXPORT_TIMEOUT = "OTEL_BSP_EXPORT_TIMEOUT" -OTEL_BSP_MAX_QUEUE_SIZE = "OTEL_BSP_MAX_QUEUE_SIZE" -OTEL_BSP_MAX_EXPORT_BATCH_SIZE = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE" -OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT" -OTEL_SPAN_EVENT_COUNT_LIMIT = "OTEL_SPAN_EVENT_COUNT_LIMIT" -OTEL_SPAN_LINK_COUNT_LIMIT = "OTEL_SPAN_LINK_COUNT_LIMIT" -OTEL_EXPORTER_JAEGER_AGENT_HOST = "OTEL_EXPORTER_JAEGER_AGENT_HOST" -OTEL_EXPORTER_JAEGER_AGENT_PORT = "OTEL_EXPORTER_JAEGER_AGENT_PORT" -OTEL_EXPORTER_JAEGER_ENDPOINT = "OTEL_EXPORTER_JAEGER_ENDPOINT" -OTEL_EXPORTER_JAEGER_USER = "OTEL_EXPORTER_JAEGER_USER" -OTEL_EXPORTER_JAEGER_PASSWORD = "OTEL_EXPORTER_JAEGER_PASSWORD" -OTEL_EXPORTER_ZIPKIN_ENDPOINT = "OTEL_EXPORTER_ZIPKIN_ENDPOINT" -OTEL_EXPORTER_PROMETHEUS_HOST = "OTEL_EXPORTER_PROMETHEUS_HOST" -OTEL_EXPORTER_PROMETHEUS_PORT = "OTEL_EXPORTER_PROMETHEUS_PORT" -OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" -OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" -OTEL_EXPORTER_ENDPOINT = "OTEL_EXPORTER_ENDPOINT" -OTEL_EXPORTER_OTLP_PROTOCOL = "OTEL_EXPORTER_OTLP_PROTOCOL" -OTEL_EXPORTER_OTLP_CERTIFICATE = "OTEL_EXPORTER_OTLP_CERTIFICATE" -OTEL_EXPORTER_OTLP_HEADERS = "OTEL_EXPORTER_OTLP_HEADERS" -OTEL_EXPORTER_OTLP_COMPRESSION = "OTEL_EXPORTER_OTLP_COMPRESSION" -OTEL_EXPORTER_OTLP_TIMEOUT = "OTEL_EXPORTER_OTLP_TIMEOUT" -OTEL_EXPORTER_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT" -OTEL_EXPORTER_OTLP_SPAN_ENDPOINT = "OTEL_EXPORTER_OTLP_SPAN_ENDPOINT" -OTEL_EXPORTER_OTLP_METRIC_ENDPOINT = "OTEL_EXPORTER_OTLP_METRIC_ENDPOINT" -OTEL_EXPORTER_OTLP_SPAN_PROTOCOL = "OTEL_EXPORTER_OTLP_SPAN_PROTOCOL" -OTEL_EXPORTER_OTLP_METRIC_PROTOCOL = "OTEL_EXPORTER_OTLP_METRIC_PROTOCOL" -OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE = "OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE" -OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE = "OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE" -OTEL_EXPORTER_OTLP_SPAN_HEADERS = "OTEL_EXPORTER_OTLP_SPAN_HEADERS" -OTEL_EXPORTER_OTLP_METRIC_HEADERS = "OTEL_EXPORTER_OTLP_METRIC_HEADERS" -OTEL_EXPORTER_OTLP_SPAN_COMPRESSION = "OTEL_EXPORTER_OTLP_SPAN_COMPRESSION" -OTEL_EXPORTER_OTLP_METRIC_COMPRESSION = "OTEL_EXPORTER_OTLP_METRIC_COMPRESSION" -OTEL_EXPORTER_OTLP_SPAN_TIMEOUT = "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT" -OTEL_EXPORTER_OTLP_METRIC_TIMEOUT = "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT" -OTEL_PYTHON_EXPORTER_JAEGER_INSECURE = "OTEL_PYTHON_EXPORTER_JAEGER_INSECURE" -OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE = ( - "OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE" -) -OTEL_PYTHON_EXPORTER_OTLP_INSECURE = "OTEL_PYTHON_EXPORTER_OTLP_INSECURE" -OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE = ( - "OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE" -) -OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE = ( - "OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE" -) -OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT = ( - "OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" -) From ddb576a76a348fa45ed2087af476094d723a9047 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 17:23:47 -0600 Subject: [PATCH 11/29] Var --- .../environment_variables/__init__.py | 20 ++++++ .../sdk/environment_variables/__init__.py | 68 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 opentelemetry-api/src/opentelemetry/environment_variables/__init__.py create mode 100644 opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py diff --git a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py new file mode 100644 index 00000000000..3fd2372165d --- /dev/null +++ b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py @@ -0,0 +1,20 @@ +# 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_PROPAGATORS = "OTEL_PROPAGATORS" +OTEL_PYTHON_CONTEXT = "OTEL_PYTHON_CONTEXT" +OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS" +OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR" +OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" +OTEL_PYTHON_EXPORTER = "OTEL_PYTHON_EXPORTER" diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py new file mode 100644 index 00000000000..5c767f24463 --- /dev/null +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -0,0 +1,68 @@ +# 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_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES" +OTEL_LOG_LEVEL = "OTEL_LOG_LEVEL" +OTEL_TRACE_SAMPLER = "OTEL_TRACE_SAMPLER" +OTEL_TRACE_SAMPLER_ARG = "OTEL_TRACE_SAMPLER_ARG" +OTEL_BSP_SCHEDULE_DELAY = "OTEL_BSP_SCHEDULE_DELAY" +OTEL_BSP_EXPORT_TIMEOUT = "OTEL_BSP_EXPORT_TIMEOUT" +OTEL_BSP_MAX_QUEUE_SIZE = "OTEL_BSP_MAX_QUEUE_SIZE" +OTEL_BSP_MAX_EXPORT_BATCH_SIZE = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE" +OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = "OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT" +OTEL_SPAN_EVENT_COUNT_LIMIT = "OTEL_SPAN_EVENT_COUNT_LIMIT" +OTEL_SPAN_LINK_COUNT_LIMIT = "OTEL_SPAN_LINK_COUNT_LIMIT" +OTEL_EXPORTER_JAEGER_AGENT_HOST = "OTEL_EXPORTER_JAEGER_AGENT_HOST" +OTEL_EXPORTER_JAEGER_AGENT_PORT = "OTEL_EXPORTER_JAEGER_AGENT_PORT" +OTEL_EXPORTER_JAEGER_ENDPOINT = "OTEL_EXPORTER_JAEGER_ENDPOINT" +OTEL_EXPORTER_JAEGER_USER = "OTEL_EXPORTER_JAEGER_USER" +OTEL_EXPORTER_JAEGER_PASSWORD = "OTEL_EXPORTER_JAEGER_PASSWORD" +OTEL_EXPORTER_ZIPKIN_ENDPOINT = "OTEL_EXPORTER_ZIPKIN_ENDPOINT" +OTEL_EXPORTER_PROMETHEUS_HOST = "OTEL_EXPORTER_PROMETHEUS_HOST" +OTEL_EXPORTER_PROMETHEUS_PORT = "OTEL_EXPORTER_PROMETHEUS_PORT" +OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" +OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" +OTEL_EXPORTER_ENDPOINT = "OTEL_EXPORTER_ENDPOINT" +OTEL_EXPORTER_OTLP_PROTOCOL = "OTEL_EXPORTER_OTLP_PROTOCOL" +OTEL_EXPORTER_OTLP_CERTIFICATE = "OTEL_EXPORTER_OTLP_CERTIFICATE" +OTEL_EXPORTER_OTLP_HEADERS = "OTEL_EXPORTER_OTLP_HEADERS" +OTEL_EXPORTER_OTLP_COMPRESSION = "OTEL_EXPORTER_OTLP_COMPRESSION" +OTEL_EXPORTER_OTLP_TIMEOUT = "OTEL_EXPORTER_OTLP_TIMEOUT" +OTEL_EXPORTER_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT" +OTEL_EXPORTER_OTLP_SPAN_ENDPOINT = "OTEL_EXPORTER_OTLP_SPAN_ENDPOINT" +OTEL_EXPORTER_OTLP_METRIC_ENDPOINT = "OTEL_EXPORTER_OTLP_METRIC_ENDPOINT" +OTEL_EXPORTER_OTLP_SPAN_PROTOCOL = "OTEL_EXPORTER_OTLP_SPAN_PROTOCOL" +OTEL_EXPORTER_OTLP_METRIC_PROTOCOL = "OTEL_EXPORTER_OTLP_METRIC_PROTOCOL" +OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE = "OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE" +OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE = "OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE" +OTEL_EXPORTER_OTLP_SPAN_HEADERS = "OTEL_EXPORTER_OTLP_SPAN_HEADERS" +OTEL_EXPORTER_OTLP_METRIC_HEADERS = "OTEL_EXPORTER_OTLP_METRIC_HEADERS" +OTEL_EXPORTER_OTLP_SPAN_COMPRESSION = "OTEL_EXPORTER_OTLP_SPAN_COMPRESSION" +OTEL_EXPORTER_OTLP_METRIC_COMPRESSION = "OTEL_EXPORTER_OTLP_METRIC_COMPRESSION" +OTEL_EXPORTER_OTLP_SPAN_TIMEOUT = "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT" +OTEL_EXPORTER_OTLP_METRIC_TIMEOUT = "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT" +OTEL_PYTHON_EXPORTER_JAEGER_INSECURE = "OTEL_PYTHON_EXPORTER_JAEGER_INSECURE" +OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE = ( + "OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE" +) +OTEL_PYTHON_EXPORTER_OTLP_INSECURE = "OTEL_PYTHON_EXPORTER_OTLP_INSECURE" +OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE = ( + "OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE" +) +OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE = ( + "OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE" +) +OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT = ( + "OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" +) From 65e2f88c5aad0c28eb47d9a1a300964cac547887 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 Jan 2021 17:33:39 -0600 Subject: [PATCH 12/29] Test --- docs-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs-requirements.txt b/docs-requirements.txt index 2ce3b654c84..56c2b92f233 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -5,6 +5,7 @@ sphinx-autodoc-typehints~=1.10.2 # Need to install the api/sdk in the venv for autodoc. Modifying sys.path # doesn't work for pkg_resources. ./opentelemetry-api +./opentelemetry-api ./opentelemetry-sdk ./opentelemetry-instrumentation From af1a2a8d6696eb6f51d06f5841737215f3cc3d5e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 14:32:45 -0600 Subject: [PATCH 13/29] Fix changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 179ffea9f16..3f05dd7e832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow missing carrier headers to continue without raising AttributeError ([#1545](https://github.com/open-telemetry/opentelemetry-python/pull/1545)) +### Removed +- Remove Configuration + ([#1523](https://github.com/open-telemetry/opentelemetry-python/pull/1523)) + ## [0.17b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.17b0) - 2021-01-20 ### Added @@ -84,8 +88,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - `opentelemetry-api` Remove ThreadLocalRuntimeContext since python3.4 is not supported. -- Remove Configuration - ([#1523](https://github.com/open-telemetry/opentelemetry-python/pull/1523)) ## [0.16b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.16b1) - 2020-11-26 ### Added From 0d5c7973597cd2b81dfab7b6b4c3402c6f924cb1 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 16:55:35 -0600 Subject: [PATCH 14/29] Split OTEL_PYTHON_EXPORTER --- .../environment_variables/__init__.py | 3 +- .../src/opentelemetry/distro/__init__.py | 56 +++++++++++++------ opentelemetry-distro/tests/test_distro.py | 11 +++- opentelemetry-instrumentation/README.rst | 7 ++- .../auto_instrumentation/__init__.py | 31 +++++++--- .../tests/test_run.py | 11 ++-- 6 files changed, 82 insertions(+), 37 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py index 3fd2372165d..1bd5a6f46d2 100644 --- a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py +++ b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py @@ -17,4 +17,5 @@ OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS" OTEL_PYTHON_IDS_GENERATOR = "OTEL_PYTHON_IDS_GENERATOR" OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" -OTEL_PYTHON_EXPORTER = "OTEL_PYTHON_EXPORTER" +OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" +OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 7153a9266c7..4da5bf27f86 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -21,9 +21,10 @@ from opentelemetry import trace from opentelemetry.environment_variables import ( - OTEL_PYTHON_EXPORTER, + OTEL_METRICS_EXPORTER, OTEL_PYTHON_IDS_GENERATOR, OTEL_PYTHON_SERVICE_NAME, + OTEL_TRACE_EXPORTER, ) from opentelemetry.instrumentation.configurator import BaseConfigurator from opentelemetry.instrumentation.distro import BaseDistro @@ -48,27 +49,47 @@ def _get_ids_generator() -> str: - return environ.get(OTEL_PYTHON_IDS_GENERATOR) or _DEFAULT_IDS_GENERATOR + return environ.get(OTEL_PYTHON_IDS_GENERATOR, _DEFAULT_IDS_GENERATOR) def _get_service_name() -> str: - return environ.get(OTEL_PYTHON_SERVICE_NAME) or "" + return environ.get(OTEL_PYTHON_SERVICE_NAME, "") def _get_exporter_names() -> Sequence[str]: - exporter = environ.get(OTEL_PYTHON_EXPORTER) or "EXPORTER_OTLP" - if exporter.lower().strip() == "none": - return [] - - names = [] - for exp in exporter.split(","): - name = exp.strip() - if name == EXPORTER_OTLP: - names.append(EXPORTER_OTLP_SPAN) - names.append(EXPORTER_OTLP_METRIC) - else: - names.append(name) - return names + trace_exporters = environ.get(OTEL_TRACE_EXPORTER) + metrics_exporters = environ.get(OTEL_METRICS_EXPORTER) + + exporters = {} + + if ( + trace_exporters is not None + or trace_exporters.lower().strip() != "none" + ): + exporters.update( + { + trace_exporter.strip() + for trace_exporter in trace_exporters.split(",") + } + ) + + if ( + metrics_exporters is not None + or metrics_exporters.lower().strip() != "none" + ): + exporters.update( + { + metrics_exporter.strip() + for metrics_exporter in metrics_exporters.split(",") + } + ) + + if EXPORTER_OTLP in exporters: + exporters.pop(EXPORTER_OTLP) + exporters.add(EXPORTER_OTLP_SPAN) + exporters.add(EXPORTER_OTLP_METRIC) + + return list(exporters) def _init_tracing( @@ -183,4 +204,5 @@ class OpenTelemetryDistro(BaseDistro): """ def _configure(self, **kwargs): - os.environ.setdefault(OTEL_PYTHON_EXPORTER, "otlp") + os.environ.setdefault(OTEL_TRACE_EXPORTER, "otel_span") + os.environ.setdefault(OTEL_METRICS_EXPORTER, "otel_metric") diff --git a/opentelemetry-distro/tests/test_distro.py b/opentelemetry-distro/tests/test_distro.py index 4412f26609a..109aead69e8 100644 --- a/opentelemetry-distro/tests/test_distro.py +++ b/opentelemetry-distro/tests/test_distro.py @@ -19,7 +19,10 @@ from pkg_resources import DistributionNotFound, require from opentelemetry.distro import OpenTelemetryDistro -from opentelemetry.environment_variables import OTEL_PYTHON_EXPORTER +from opentelemetry.environment_variables import ( + OTEL_METRICS_EXPORTER, + OTEL_TRACE_EXPORTER, +) class TestDistribution(TestCase): @@ -31,6 +34,8 @@ def test_package_available(self): def test_default_configuration(self): distro = OpenTelemetryDistro() - self.assertIsNone(os.environ.get(OTEL_PYTHON_EXPORTER)) + self.assertIsNone(os.environ.get(OTEL_TRACE_EXPORTER)) + self.assertIsNone(os.environ.get(OTEL_METRICS_EXPORTER)) distro.configure() - self.assertEqual("otlp", os.environ.get(OTEL_PYTHON_EXPORTER)) + self.assertEqual("otlp_span", os.environ.get(OTEL_TRACE_EXPORTER)) + self.assertEqual("otlp_metric", os.environ.get(OTEL_METRICS_EXPORTER)) diff --git a/opentelemetry-instrumentation/README.rst b/opentelemetry-instrumentation/README.rst index 824aa23e69e..1f6dd269e54 100644 --- a/opentelemetry-instrumentation/README.rst +++ b/opentelemetry-instrumentation/README.rst @@ -48,10 +48,11 @@ this can be overriden when needed. The command supports the following configuration options as CLI arguments and environment vars: -* ``--exporter`` or ``OTEL_PYTHON_EXPORTER`` +* ``--trace-exporter`` or ``OTEL_TRACE_EXPORTER`` +* ``--metrics-exporter`` or ``OTEL_METRICS_EXPORTER`` -Used to specify which trace exporter to use. Can be set to one or more -of the well-known exporter names (see below). +Used to specify which trace or metrics exporter to use. Can be set to one or +more of the well-known exporter names (see below). - Defaults to `otlp`. - Can be set to `none` to disable automatic tracer initialization. diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index 87bf982128f..7d827663cba 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -21,9 +21,10 @@ from shutil import which from opentelemetry.environment_variables import ( - OTEL_PYTHON_EXPORTER, + OTEL_METRICS_EXPORTER, OTEL_PYTHON_IDS_GENERATOR, OTEL_PYTHON_SERVICE_NAME, + OTEL_TRACE_EXPORTER, ) logger = getLogger(__file__) @@ -38,18 +39,28 @@ def parse_args(): ) parser.add_argument( - "-e", - "--exporter", + "--metrics-exporter", required=False, help=""" - Uses the specified exporter to export spans or metrics. + Uses the specified exporter to export metrics. Accepts multiple exporters as comma separated values. Examples: - -e=otlp - -e=otlp_span,prometheus - -e=jaeger,otlp_metric + --metrics-exporter=otlp_metric + """, + ) + + parser.add_argument( + "--trace-exporter", + required=False, + help=""" + Uses the specified exporter to export spans. + Accepts multiple exporters as comma separated values. + + Examples: + + --trace-exporter=jaeger """, ) @@ -84,8 +95,10 @@ def parse_args(): def load_config_from_cli_args(args): - if args.exporter: - environ[OTEL_PYTHON_EXPORTER] = args.exporter + if args.metrics_exporter: + environ[OTEL_METRICS_EXPORTER] = args.metrics_exporter + if args.trace_exporter: + environ[OTEL_TRACE_EXPORTER] = args.trace_exporter if args.service_name: environ[OTEL_PYTHON_SERVICE_NAME] = args.service_name if args.ids_generator: diff --git a/opentelemetry-instrumentation/tests/test_run.py b/opentelemetry-instrumentation/tests/test_run.py index 57562b449e5..6b8c097f068 100644 --- a/opentelemetry-instrumentation/tests/test_run.py +++ b/opentelemetry-instrumentation/tests/test_run.py @@ -19,8 +19,9 @@ from unittest.mock import patch from opentelemetry.environment_variables import ( - OTEL_PYTHON_EXPORTER, + OTEL_METRICS_EXPORTER, OTEL_PYTHON_SERVICE_NAME, + OTEL_TRACE_EXPORTER, ) from opentelemetry.instrumentation import auto_instrumentation @@ -111,11 +112,13 @@ class TestArgs(TestCase): def test_exporter(self, _): # pylint: disable=no-self-use with patch("sys.argv", ["instrument", "2"]): auto_instrumentation.run() - self.assertIsNone(environ.get(OTEL_PYTHON_EXPORTER)) + self.assertIsNone(environ.get(OTEL_METRICS_EXPORTER)) - with patch("sys.argv", ["instrument", "-e", "zipkin", "1", "2"]): + with patch( + "sys.argv", ["instrument", "--trace-exporter", "jaeger", "1", "2"] + ): auto_instrumentation.run() - self.assertEqual(environ.get(OTEL_PYTHON_EXPORTER), "zipkin") + self.assertEqual(environ.get(OTEL_TRACE_EXPORTER), "jaeger") @patch("opentelemetry.instrumentation.auto_instrumentation.execl") def test_service_name(self, _): # pylint: disable=no-self-use From 7e29a8b90ae88d3d371f2c175becd5ad3a5c7f5e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 17:03:09 -0600 Subject: [PATCH 15/29] Fix distro test --- opentelemetry-distro/src/opentelemetry/distro/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 4da5bf27f86..9d7d7c7e63a 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -204,5 +204,5 @@ class OpenTelemetryDistro(BaseDistro): """ def _configure(self, **kwargs): - os.environ.setdefault(OTEL_TRACE_EXPORTER, "otel_span") - os.environ.setdefault(OTEL_METRICS_EXPORTER, "otel_metric") + os.environ.setdefault(OTEL_TRACE_EXPORTER, "otlp_span") + os.environ.setdefault(OTEL_METRICS_EXPORTER, "otlp_metric") From 98f7e7fed84382a502c6c41248d990648c0e7c86 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 17:18:30 -0600 Subject: [PATCH 16/29] Import from environment_variables module --- .../src/opentelemetry/exporter/otlp/exporter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index 9396e30cfe6..032b4aa9e38 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -43,6 +43,8 @@ OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_PYTHON_EXPORTER_OTLP_INSECURE, + OTEL_EXPORTER_OTLP_CERTIFICATE + ) from opentelemetry.sdk.resources import Resource as SDKResource @@ -194,9 +196,7 @@ def __init__( ): compression_algorithm = Compression.Gzip else: - compression_str = ( - environ.get("OTLP_EXPORTER_OTLP_INSECURE") or None - ) + compression_str = environ.get(OTEL_PYTHON_EXPORTER_OTLP_INSECURE) if compression_str is None: compression_algorithm = Compression.NoCompression elif ( @@ -218,13 +218,13 @@ def __init__( # secure mode if ( credentials is None - and environ.get("OTLP_EXPORTER_OTLP_CERTIFICATE") is None + and environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE) is None ): # use the default location chosen by gRPC runtime credentials = ssl_channel_credentials() else: credentials = credentials or _load_credential_from_file( - environ.get("OTLP_EXPORTER_OTLP_CERTIFICATE") + environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE) ) self._client = self._stub( secure_channel( From 66739c6ce430cef3847a459a46c85a7451d26da0 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 17:19:42 -0600 Subject: [PATCH 17/29] Remove duplicate entry --- docs-requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs-requirements.txt b/docs-requirements.txt index 56c2b92f233..2ce3b654c84 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -5,7 +5,6 @@ sphinx-autodoc-typehints~=1.10.2 # Need to install the api/sdk in the venv for autodoc. Modifying sys.path # doesn't work for pkg_resources. ./opentelemetry-api -./opentelemetry-api ./opentelemetry-sdk ./opentelemetry-instrumentation From 1cce23662d8bc249259227efca2a867a5b16e61d Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 28 Jan 2021 17:30:53 -0600 Subject: [PATCH 18/29] Fix lint --- .../src/opentelemetry/exporter/otlp/exporter.py | 3 +-- opentelemetry-distro/src/opentelemetry/distro/__init__.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index 032b4aa9e38..68a99c745f8 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -39,12 +39,11 @@ from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue from opentelemetry.proto.resource.v1.resource_pb2 import Resource from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_PYTHON_EXPORTER_OTLP_INSECURE, - OTEL_EXPORTER_OTLP_CERTIFICATE - ) from opentelemetry.sdk.resources import Resource as SDKResource diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 9d7d7c7e63a..c4ac8f5e874 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -60,7 +60,7 @@ def _get_exporter_names() -> Sequence[str]: trace_exporters = environ.get(OTEL_TRACE_EXPORTER) metrics_exporters = environ.get(OTEL_METRICS_EXPORTER) - exporters = {} + exporters = set() if ( trace_exporters is not None From 0aff92e3e32f831119af03ee2b43df124820d564 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 16:25:37 -0600 Subject: [PATCH 19/29] Rename variables to add to spec --- .../src/opentelemetry/exporter/jaeger/util.py | 8 +++---- .../tests/test_jaeger_exporter_protobuf.py | 6 ++--- .../opentelemetry/exporter/otlp/exporter.py | 6 ++--- .../otlp/metrics_exporter/__init__.py | 4 ++-- .../exporter/otlp/trace_exporter/__init__.py | 4 ++-- .../opentelemetry/exporter/zipkin/__init__.py | 8 +++---- .../tests/test_zipkin_exporter.py | 8 +++---- .../sdk/environment_variables/__init__.py | 22 +++++-------------- 8 files changed, 27 insertions(+), 39 deletions(-) diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py index 44f93c8363b..4a72c1817c2 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py @@ -18,8 +18,8 @@ from grpc import ChannelCredentials, ssl_channel_credentials from opentelemetry.sdk.environment_variables import ( - OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE, - OTEL_PYTHON_EXPORTER_JAEGER_INSECURE, + OTEL_EXPORTER_JAEGER_CERTIFICATE, + OTEL_EXPORTER_JAEGER_INSECURE, ) logger = logging.getLogger(__name__) @@ -30,7 +30,7 @@ def _get_insecure(param): if param is not None: return param - insecure_env = environ.get(OTEL_PYTHON_EXPORTER_JAEGER_INSECURE) + insecure_env = environ.get(OTEL_EXPORTER_JAEGER_INSECURE) if insecure_env is not None: return insecure_env.lower() == "true" return DEFAULT_INSECURE @@ -49,7 +49,7 @@ def _load_credential_from_file(path) -> ChannelCredentials: def _get_credentials(param): if param is not None: return param - creds_env = environ.get(OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE) + creds_env = environ.get(OTEL_EXPORTER_JAEGER_CERTIFICATE) if creds_env: return _load_credential_from_file(creds_env) return ssl_channel_credentials() diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py index e1920fe2e4e..26cfc41498e 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py @@ -30,8 +30,8 @@ ) from opentelemetry.sdk import trace from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_JAEGER_CERTIFICATE, OTEL_EXPORTER_JAEGER_ENDPOINT, - OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE, ) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.util.instrumentation import InstrumentationInfo @@ -64,9 +64,7 @@ def test_constructor_by_environment_variables(self): "os.environ", { OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint, - OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname( - __file__ - ) + OTEL_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(__file__) + "/certs/cred.cert", }, ) diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py index 68a99c745f8..6d54970f19f 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py @@ -42,8 +42,8 @@ OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, + OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_INSECURE, ) from opentelemetry.sdk.resources import Resource as SDKResource @@ -171,7 +171,7 @@ def __init__( ) if insecure is None: - insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_INSECURE) + insecure = environ.get(OTEL_EXPORTER_OTLP_INSECURE) if insecure is None: insecure = False @@ -195,7 +195,7 @@ def __init__( ): compression_algorithm = Compression.Gzip else: - compression_str = environ.get(OTEL_PYTHON_EXPORTER_OTLP_INSECURE) + compression_str = environ.get(OTEL_EXPORTER_OTLP_INSECURE) if compression_str is None: compression_algorithm = Compression.NoCompression elif ( diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index 81c3746652e..8e388e9f9e1 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -48,8 +48,8 @@ OTEL_EXPORTER_OTLP_METRIC_CERTIFICATE, OTEL_EXPORTER_OTLP_METRIC_ENDPOINT, OTEL_EXPORTER_OTLP_METRIC_HEADERS, + OTEL_EXPORTER_OTLP_METRIC_INSECURE, OTEL_EXPORTER_OTLP_METRIC_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE, ) from opentelemetry.sdk.metrics import ( Counter, @@ -150,7 +150,7 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE) + insecure = environ.get(OTEL_EXPORTER_OTLP_METRIC_INSECURE) if ( not insecure diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py index 4d47e1622b4..96dbbc084b8 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py @@ -42,8 +42,8 @@ OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE, OTEL_EXPORTER_OTLP_SPAN_ENDPOINT, OTEL_EXPORTER_OTLP_SPAN_HEADERS, + OTEL_EXPORTER_OTLP_SPAN_INSECURE, OTEL_EXPORTER_OTLP_SPAN_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE, ) from opentelemetry.sdk.trace import Span as SDKSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -80,7 +80,7 @@ def __init__( timeout: Optional[int] = None, ): if insecure is None: - insecure = environ.get(OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE) + insecure = environ.get(OTEL_EXPORTER_OTLP_SPAN_INSECURE) if ( not insecure diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index 01fea11ff9a..30132bba8d5 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -27,7 +27,7 @@ .. _Specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-environment-variables.md#zipkin-exporter .. envvar:: OTEL_EXPORTER_ZIPKIN_ENDPOINT -.. envvar:: OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT +.. envvar:: OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT .. code:: python @@ -63,7 +63,7 @@ :envvar:`OTEL_EXPORTER_ZIPKIN_ENDPOINT`: target to which the exporter will send data. This may include a path (e.g. http://example.com:9411/api/v2/spans). -:envvar:`OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT`: transport interchange format +:envvar:`OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT`: transport interchange format to use when sending data. Currently only Zipkin's v2 json and protobuf formats are supported, with v2 json being the default. @@ -82,7 +82,7 @@ from opentelemetry.exporter.zipkin.gen import zipkin_pb2 from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_ZIPKIN_ENDPOINT, - OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, ) from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult from opentelemetry.trace import Span, SpanContext, SpanKind @@ -161,7 +161,7 @@ def __init__( if transport_format is None: self.transport_format = ( - environ.get(OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT) + environ.get(OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT) or TRANSPORT_FORMAT_JSON ) else: diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index ca818871eda..5c2e0e7e4d0 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -32,7 +32,7 @@ from opentelemetry.sdk import trace from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_ZIPKIN_ENDPOINT, - OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT, ) from opentelemetry.sdk.trace import Resource from opentelemetry.sdk.trace.export import SpanExportResult @@ -63,15 +63,15 @@ def setUp(self): def tearDown(self): if OTEL_EXPORTER_ZIPKIN_ENDPOINT in os.environ: del os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] - if OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT in os.environ: - del os.environ[OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT] + if OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT in os.environ: + del os.environ[OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT] def test_constructor_env_var(self): """Test the default values assigned by constructor.""" url = "https://foo:9911/path" os.environ[OTEL_EXPORTER_ZIPKIN_ENDPOINT] = url os.environ[ - OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT + OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT ] = TRANSPORT_FORMAT_PROTOBUF service_name = "my-service-name" port = 9911 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 5c767f24463..9ab85031b79 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -31,8 +31,6 @@ OTEL_EXPORTER_ZIPKIN_ENDPOINT = "OTEL_EXPORTER_ZIPKIN_ENDPOINT" OTEL_EXPORTER_PROMETHEUS_HOST = "OTEL_EXPORTER_PROMETHEUS_HOST" OTEL_EXPORTER_PROMETHEUS_PORT = "OTEL_EXPORTER_PROMETHEUS_PORT" -OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" -OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" OTEL_EXPORTER_ENDPOINT = "OTEL_EXPORTER_ENDPOINT" OTEL_EXPORTER_OTLP_PROTOCOL = "OTEL_EXPORTER_OTLP_PROTOCOL" OTEL_EXPORTER_OTLP_CERTIFICATE = "OTEL_EXPORTER_OTLP_CERTIFICATE" @@ -52,17 +50,9 @@ OTEL_EXPORTER_OTLP_METRIC_COMPRESSION = "OTEL_EXPORTER_OTLP_METRIC_COMPRESSION" OTEL_EXPORTER_OTLP_SPAN_TIMEOUT = "OTEL_EXPORTER_OTLP_SPAN_TIMEOUT" OTEL_EXPORTER_OTLP_METRIC_TIMEOUT = "OTEL_EXPORTER_OTLP_METRIC_TIMEOUT" -OTEL_PYTHON_EXPORTER_JAEGER_INSECURE = "OTEL_PYTHON_EXPORTER_JAEGER_INSECURE" -OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE = ( - "OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE" -) -OTEL_PYTHON_EXPORTER_OTLP_INSECURE = "OTEL_PYTHON_EXPORTER_OTLP_INSECURE" -OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE = ( - "OTEL_PYTHON_EXPORTER_OTLP_SPAN_INSECURE" -) -OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE = ( - "OTEL_PYTHON_EXPORTER_OTLP_METRIC_INSECURE" -) -OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT = ( - "OTEL_PYTHON_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" -) +OTEL_EXPORTER_JAEGER_INSECURE = "OTEL_EXPORTER_JAEGER_INSECURE" +OTEL_EXPORTER_JAEGER_CERTIFICATE = "OTEL_EXPORTER_JAEGER_CERTIFICATE" +OTEL_EXPORTER_OTLP_INSECURE = "OTEL_EXPORTER_OTLP_INSECURE" +OTEL_EXPORTER_OTLP_SPAN_INSECURE = "OTEL_EXPORTER_OTLP_SPAN_INSECURE" +OTEL_EXPORTER_OTLP_METRIC_INSECURE = "OTEL_EXPORTER_OTLP_METRIC_INSECURE" +OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT = "OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT" From d3fe740d42747b3e85df76c0579dd64e70a112cf Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:11:30 -0600 Subject: [PATCH 20/29] Try to remove cache --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5d15e10bfc..b260f457d98 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -107,12 +107,12 @@ jobs: python-version: 3.8 - name: Install tox run: pip install -U tox - - name: Cache tox environment + # - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 - with: - path: .tox - key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core + # uses: actions/cache@v2 + # with: + # path: .tox + # key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core - name: run tox run: tox -e ${{ matrix.tox-environment }} contrib-build: From 05648eabd3597196811501a88e04ca73fadf1d75 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:21:38 -0600 Subject: [PATCH 21/29] Revert "Try to remove cache" This reverts commit d3fe740d42747b3e85df76c0579dd64e70a112cf. --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b260f457d98..c5d15e10bfc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -107,12 +107,12 @@ jobs: python-version: 3.8 - name: Install tox run: pip install -U tox - # - name: Cache tox environment + - name: Cache tox environment # Preserves .tox directory between runs for faster installs - # uses: actions/cache@v2 - # with: - # path: .tox - # key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core + uses: actions/cache@v2 + with: + path: .tox + key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core - name: run tox run: tox -e ${{ matrix.tox-environment }} contrib-build: From 6329a251e3b6eebf75ec3e97fa79cd70a482ea0c Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:30:15 -0600 Subject: [PATCH 22/29] Update contrib sha --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5d15e10bfc..cc4648adaf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ env: # Otherwise, set variable to the commit of your branch on # opentelemetry-python-contrib which is compatible with these Core repo # changes. - CONTRIB_REPO_SHA: 2be6c6e089d6879c782bd134d5f33043d1c6252e + CONTRIB_REPO_SHA: f005d90ed3bc75ee6eb7297f9e3a6b55a55b22aa jobs: build: From a2f0e3fafed559beb7ffd021aa1e356267898a77 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:33:11 -0600 Subject: [PATCH 23/29] Another attempt to clear cache --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc4648adaf8..a26c121726f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -109,7 +109,7 @@ jobs: run: pip install -U tox - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 + uses: actions/cache@v2-0 with: path: .tox key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core From 7e593ad6e50a015c3dc62c66122686d895fda658 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:35:11 -0600 Subject: [PATCH 24/29] And again --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a26c121726f..c61c75cb4c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -109,7 +109,7 @@ jobs: run: pip install -U tox - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2-0 + uses: actions/cache@v3 with: path: .tox key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core From 291179f614c855315f086bfd69666d42ad06d421 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:40:16 -0600 Subject: [PATCH 25/29] Another attempt --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c61c75cb4c6..5fba413e7e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -109,7 +109,7 @@ jobs: run: pip install -U tox - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v3 + uses: actions/cache@v1 with: path: .tox key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core From 6bebd84fc0030ed64f80cb1112ea80161b4fe8d7 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:43:33 -0600 Subject: [PATCH 26/29] Try with v2 again --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5fba413e7e0..cc4648adaf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -109,7 +109,7 @@ jobs: run: pip install -U tox - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: .tox key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core From 09b010cfcc85e2aa07326e9204541b80a7dd52f0 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 17:52:16 -0600 Subject: [PATCH 27/29] Downgrade version to clear cache and make docs tests pass --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc4648adaf8..5fba413e7e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -109,7 +109,7 @@ jobs: run: pip install -U tox - name: Cache tox environment # Preserves .tox directory between runs for faster installs - uses: actions/cache@v2 + uses: actions/cache@v1 with: path: .tox key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core From ffe29dba754ec604b88164fe42d700964442686f Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 19:03:12 -0600 Subject: [PATCH 28/29] Removed wrong path --- tests/w3c_tracecontext_validation_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3c_tracecontext_validation_server.py b/tests/w3c_tracecontext_validation_server.py index f2fb14f206d..b669c20d8d0 100644 --- a/tests/w3c_tracecontext_validation_server.py +++ b/tests/w3c_tracecontext_validation_server.py @@ -25,7 +25,7 @@ from opentelemetry import trace from opentelemetry.instrumentation.requests import RequestsInstrumentor -from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware +from opentelemetry.util.http.wsgi import OpenTelemetryMiddleware from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, From d45bc85c8a2094606dab88e70c2e31c64e95b7dc Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 29 Jan 2021 19:18:43 -0600 Subject: [PATCH 29/29] Fix lint --- tests/w3c_tracecontext_validation_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/w3c_tracecontext_validation_server.py b/tests/w3c_tracecontext_validation_server.py index b669c20d8d0..2d8246c7a06 100644 --- a/tests/w3c_tracecontext_validation_server.py +++ b/tests/w3c_tracecontext_validation_server.py @@ -25,12 +25,12 @@ from opentelemetry import trace from opentelemetry.instrumentation.requests import RequestsInstrumentor -from opentelemetry.util.http.wsgi import OpenTelemetryMiddleware from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ( ConsoleSpanExporter, SimpleExportSpanProcessor, ) +from opentelemetry.util.http.wsgi import OpenTelemetryMiddleware # FIXME This could likely be avoided by integrating this script into the # standard test running mechanisms.