Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Configuration #1523

Merged
merged 30 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
ocelotl marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also add a changelog note about the changing variable names

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also contain a note about the changing args in opentelemetry-instrument

## [0.17b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.17b0) - 2021-01-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OpenTelemetry Python API
:maxdepth: 1

baggage
configuration
context
metrics
trace
environment_variables
10 changes: 0 additions & 10 deletions docs/api/configuration.rst

This file was deleted.

7 changes: 7 additions & 0 deletions docs/api/environment_variables.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opentelemetry.environment_variables package
===========================================

Module contents
---------------

.. automodule:: opentelemetry.environment_variables
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
12 changes: 12 additions & 0 deletions docs/sdk/environment_variables.rst
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions docs/sdk/sdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ OpenTelemetry Python SDK
resources
trace
error_handler
environment_variables
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,14 @@
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.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"
DEFAULT_AGENT_PORT = 6831
Expand Down Expand Up @@ -142,30 +137,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,10 +13,14 @@
# limitations under the License.

import logging
from os import environ

from grpc import ChannelCredentials, ssl_channel_credentials

from opentelemetry.configuration import Configuration
from opentelemetry.sdk.environment_variables import (
OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE,
OTEL_PYTHON_EXPORTER_JAEGER_INSECURE,
)

logger = logging.getLogger(__name__)

Expand All @@ -26,7 +30,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_PYTHON_EXPORTER_JAEGER_INSECURE)
if insecure_env is not None:
return insecure_env.lower() == "true"
return DEFAULT_INSECURE
Expand All @@ -45,7 +49,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_PYTHON_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,14 +22,17 @@
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,
VERSION_KEY,
Translate,
)
from opentelemetry.sdk import trace
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_JAEGER_ENDPOINT,
OTEL_PYTHON_EXPORTER_JAEGER_CERTIFICATE,
)
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace.status import Status, StatusCode
Expand All @@ -49,25 +52,21 @@ 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"

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_PYTHON_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(
__file__
)
+ "/certs/cred.cert",
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
# 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
from opentelemetry.sdk import trace
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 import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanKind
Expand All @@ -44,11 +50,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 Expand Up @@ -121,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,
},
)

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,9 +36,15 @@
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.environment_variables import (
OTEL_EXPORTER_OTLP_CERTIFICATE,
OTEL_EXPORTER_OTLP_ENDPOINT,
OTEL_EXPORTER_OTLP_HEADERS,
OTEL_EXPORTER_OTLP_TIMEOUT,
OTEL_PYTHON_EXPORTER_OTLP_INSECURE,
)
from opentelemetry.sdk.resources import Resource as SDKResource

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -159,23 +166,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_PYTHON_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 +195,7 @@ def __init__(
):
compression_algorithm = Compression.Gzip
else:
compression_str = Configuration().EXPORTER_OTLP_INSECURE or None
compression_str = environ.get(OTEL_PYTHON_EXPORTER_OTLP_INSECURE)
if compression_str is None:
compression_algorithm = Compression.NoCompression
elif (
Expand All @@ -210,13 +217,13 @@ def __init__(
# secure mode
if (
credentials is None
and Configuration().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(
Configuration().EXPORTER_OTLP_CERTIFICATE
environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE)
)
self._client = self._stub(
secure_channel(
Expand Down
Loading