Skip to content

Commit

Permalink
Remove Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jan 12, 2021
1 parent 09ac955 commit 5a584e8
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -142,30 +130,36 @@ 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(
host_name=self.agent_host_name, port=self.agent_port
)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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 Translate
from opentelemetry.sdk import trace
Expand All @@ -45,16 +44,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -159,23 +159,23 @@ def __init__(

endpoint = (
endpoint
or Configuration().EXPORTER_OTLP_ENDPOINT
or environ.get("OTEL_EXPORTER_OTLP_ENDPOINT")
or "localhost:55680"
)

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
Expand All @@ -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 (
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 5a584e8

Please sign in to comment.