Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 731f32c

Browse files
authored
Remove Configuration (open-telemetry#1523)
1 parent 05ab4a7 commit 731f32c

File tree

49 files changed

+447
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+447
-681
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
# Otherwise, set variable to the commit of your branch on
1111
# opentelemetry-python-contrib which is compatible with these Core repo
1212
# changes.
13-
CONTRIB_REPO_SHA: a67a23d0a0a4dd7c3c06c7050c220fa3b3689a77
13+
CONTRIB_REPO_SHA: f005d90ed3bc75ee6eb7297f9e3a6b55a55b22aa
1414

1515
jobs:
1616
build:
@@ -109,7 +109,7 @@ jobs:
109109
run: pip install -U tox
110110
- name: Cache tox environment
111111
# Preserves .tox directory between runs for faster installs
112-
uses: actions/cache@v2
112+
uses: actions/cache@v1
113113
with:
114114
path: .tox
115115
key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Allow missing carrier headers to continue without raising AttributeError
1717
([#1545](https://github.com/open-telemetry/opentelemetry-python/pull/1545))
1818

19+
### Removed
20+
- Remove Configuration
21+
([#1523](https://github.com/open-telemetry/opentelemetry-python/pull/1523))
22+
1923
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.17b0) - 2021-01-20
2024

2125
### Added

docs/api/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ OpenTelemetry Python API
77
:maxdepth: 1
88

99
baggage
10-
configuration
1110
context
1211
metrics
1312
trace
13+
environment_variables

docs/api/configuration.rst

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

docs/api/environment_variables.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
opentelemetry.environment_variables package
2+
===========================================
3+
4+
Module contents
5+
---------------
6+
7+
.. automodule:: opentelemetry.environment_variables

docs/examples/auto-instrumentation/server_instrumented.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from flask import Flask, request
1616

1717
from opentelemetry import propagators, trace
18-
from opentelemetry.instrumentation.wsgi import collect_request_attributes
1918
from opentelemetry.sdk.trace import TracerProvider
2019
from opentelemetry.sdk.trace.export import (
2120
ConsoleSpanExporter,
2221
SimpleExportSpanProcessor,
2322
)
2423
from opentelemetry.trace.propagation.textmap import DictGetter
24+
from opentelemetry.util.http.wsgi import collect_request_attributes
2525

2626
app = Flask(__name__)
2727

docs/sdk/environment_variables.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
opentelemetry.sdk.environment_variables
2+
=======================================
3+
4+
.. TODO: what is the SDK
5+
6+
.. toctree::
7+
:maxdepth: 1
8+
9+
.. automodule:: opentelemetry.sdk.environment_variables
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:

docs/sdk/sdk.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ OpenTelemetry Python SDK
1010
resources
1111
trace
1212
error_handler
13+
environment_variables

exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,14 @@
6565
"""
6666
# pylint: disable=protected-access
6767

68-
import base64
6968
import logging
70-
import socket
71-
from typing import Optional, Union
72-
73-
from grpc import (
74-
ChannelCredentials,
75-
insecure_channel,
76-
secure_channel,
77-
ssl_channel_credentials,
78-
)
79-
from thrift.protocol import TBinaryProtocol, TCompactProtocol
80-
from thrift.transport import THttpClient, TTransport
69+
from os import environ
70+
from typing import Optional
71+
72+
from grpc import ChannelCredentials, insecure_channel, secure_channel
8173

82-
from opentelemetry.configuration import Configuration
8374
from opentelemetry.exporter.jaeger import util
8475
from opentelemetry.exporter.jaeger.gen import model_pb2
85-
from opentelemetry.exporter.jaeger.gen.agent import Agent as agent
8676
from opentelemetry.exporter.jaeger.gen.collector_pb2 import PostSpansRequest
8777
from opentelemetry.exporter.jaeger.gen.collector_pb2_grpc import (
8878
CollectorServiceStub,
@@ -92,9 +82,14 @@
9282
from opentelemetry.exporter.jaeger.translate import Translate
9383
from opentelemetry.exporter.jaeger.translate.protobuf import ProtobufTranslator
9484
from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator
95-
from opentelemetry.sdk.trace.export import Span, SpanExporter, SpanExportResult
96-
from opentelemetry.trace import SpanKind
97-
from opentelemetry.trace.status import StatusCode
85+
from opentelemetry.sdk.environment_variables import (
86+
OTEL_EXPORTER_JAEGER_AGENT_HOST,
87+
OTEL_EXPORTER_JAEGER_AGENT_PORT,
88+
OTEL_EXPORTER_JAEGER_ENDPOINT,
89+
OTEL_EXPORTER_JAEGER_PASSWORD,
90+
OTEL_EXPORTER_JAEGER_USER,
91+
)
92+
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
9893

9994
DEFAULT_AGENT_HOST_NAME = "localhost"
10095
DEFAULT_AGENT_PORT = 6831
@@ -142,30 +137,36 @@ def __init__(
142137
self.service_name = service_name
143138
self.agent_host_name = _parameter_setter(
144139
param=agent_host_name,
145-
env_variable=Configuration().EXPORTER_JAEGER_AGENT_HOST,
140+
env_variable=environ.get(OTEL_EXPORTER_JAEGER_AGENT_HOST),
146141
default=DEFAULT_AGENT_HOST_NAME,
147142
)
143+
144+
environ_agent_port = environ.get(OTEL_EXPORTER_JAEGER_AGENT_PORT)
145+
environ_agent_port = (
146+
int(environ_agent_port) if environ_agent_port is not None else None
147+
)
148+
148149
self.agent_port = _parameter_setter(
149150
param=agent_port,
150-
env_variable=Configuration().EXPORTER_JAEGER_AGENT_PORT,
151+
env_variable=environ_agent_port,
151152
default=DEFAULT_AGENT_PORT,
152153
)
153154
self._agent_client = AgentClientUDP(
154155
host_name=self.agent_host_name, port=self.agent_port
155156
)
156157
self.collector_endpoint = _parameter_setter(
157158
param=collector_endpoint,
158-
env_variable=Configuration().EXPORTER_JAEGER_ENDPOINT,
159+
env_variable=environ.get(OTEL_EXPORTER_JAEGER_ENDPOINT),
159160
default=None,
160161
)
161162
self.username = _parameter_setter(
162163
param=username,
163-
env_variable=Configuration().EXPORTER_JAEGER_USER,
164+
env_variable=environ.get(OTEL_EXPORTER_JAEGER_USER),
164165
default=None,
165166
)
166167
self.password = _parameter_setter(
167168
param=password,
168-
env_variable=Configuration().EXPORTER_JAEGER_PASSWORD,
169+
env_variable=environ.get(OTEL_EXPORTER_JAEGER_PASSWORD),
169170
default=None,
170171
)
171172
self._collector = None

exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
# limitations under the License.
1414

1515
import logging
16+
from os import environ
1617

1718
from grpc import ChannelCredentials, ssl_channel_credentials
1819

19-
from opentelemetry.configuration import Configuration
20+
from opentelemetry.sdk.environment_variables import (
21+
OTEL_EXPORTER_JAEGER_CERTIFICATE,
22+
OTEL_EXPORTER_JAEGER_INSECURE,
23+
)
2024

2125
logger = logging.getLogger(__name__)
2226

@@ -26,7 +30,7 @@
2630
def _get_insecure(param):
2731
if param is not None:
2832
return param
29-
insecure_env = Configuration().get("EXPORTER_JAEGER_INSECURE", None)
33+
insecure_env = environ.get(OTEL_EXPORTER_JAEGER_INSECURE)
3034
if insecure_env is not None:
3135
return insecure_env.lower() == "true"
3236
return DEFAULT_INSECURE
@@ -45,7 +49,7 @@ def _load_credential_from_file(path) -> ChannelCredentials:
4549
def _get_credentials(param):
4650
if param is not None:
4751
return param
48-
creds_env = Configuration().get("EXPORTER_JAEGER_CERTIFICATE", None)
52+
creds_env = environ.get(OTEL_EXPORTER_JAEGER_CERTIFICATE)
4953
if creds_env:
5054
return _load_credential_from_file(creds_env)
5155
return ssl_channel_credentials()

exporter/opentelemetry-exporter-jaeger/tests/test_jarget_exporter_protobuf.py renamed to exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_protobuf.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
import opentelemetry.exporter.jaeger.gen.model_pb2 as model_pb2
2323
import opentelemetry.exporter.jaeger.translate.protobuf as pb_translator
2424
from opentelemetry import trace as trace_api
25-
from opentelemetry.configuration import Configuration
2625
from opentelemetry.exporter.jaeger import JaegerSpanExporter
2726
from opentelemetry.exporter.jaeger.translate import (
2827
NAME_KEY,
2928
VERSION_KEY,
3029
Translate,
3130
)
3231
from opentelemetry.sdk import trace
32+
from opentelemetry.sdk.environment_variables import (
33+
OTEL_EXPORTER_JAEGER_CERTIFICATE,
34+
OTEL_EXPORTER_JAEGER_ENDPOINT,
35+
)
3336
from opentelemetry.sdk.trace import Resource
3437
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
3538
from opentelemetry.trace.status import Status, StatusCode
@@ -49,25 +52,19 @@ def setUp(self):
4952
self._test_span.start()
5053
self._test_span.end()
5154
# pylint: disable=protected-access
52-
Configuration._reset()
53-
54-
def tearDown(self):
55-
# pylint: disable=protected-access
56-
Configuration._reset()
5755

5856
def test_constructor_by_environment_variables(self):
5957
"""Test using Environment Variables."""
6058
# pylint: disable=protected-access
61-
Configuration._reset()
6259
service = "my-opentelemetry-jaeger"
6360

6461
collector_endpoint = "localhost:14250"
6562

6663
env_patch = patch.dict(
6764
"os.environ",
6865
{
69-
"OTEL_EXPORTER_JAEGER_ENDPOINT": collector_endpoint,
70-
"OTEL_EXPORTER_JAEGER_CERTIFICATE": os.path.dirname(__file__)
66+
OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint,
67+
OTEL_EXPORTER_JAEGER_CERTIFICATE: os.path.dirname(__file__)
7168
+ "/certs/cred.cert",
7269
},
7370
)

exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter_thrift.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@
2020
# pylint:disable=import-error
2121
import opentelemetry.exporter.jaeger as jaeger_exporter
2222
from opentelemetry import trace as trace_api
23-
from opentelemetry.configuration import Configuration
2423
from opentelemetry.exporter.jaeger.gen.jaeger import ttypes as jaeger
2524
from opentelemetry.exporter.jaeger.translate import Translate
2625
from opentelemetry.exporter.jaeger.translate.thrift import ThriftTranslator
2726
from opentelemetry.sdk import trace
27+
from opentelemetry.sdk.environment_variables import (
28+
OTEL_EXPORTER_JAEGER_AGENT_HOST,
29+
OTEL_EXPORTER_JAEGER_AGENT_PORT,
30+
OTEL_EXPORTER_JAEGER_ENDPOINT,
31+
OTEL_EXPORTER_JAEGER_PASSWORD,
32+
OTEL_EXPORTER_JAEGER_USER,
33+
)
2834
from opentelemetry.sdk.trace import Resource
2935
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
3036
from opentelemetry.trace import SpanKind
@@ -44,11 +50,6 @@ def setUp(self):
4450
self._test_span.start()
4551
self._test_span.end()
4652
# pylint: disable=protected-access
47-
Configuration._reset()
48-
49-
def tearDown(self):
50-
# pylint: disable=protected-access
51-
Configuration._reset()
5253

5354
def test_constructor_default(self):
5455
# pylint: disable=protected-access
@@ -121,11 +122,11 @@ def test_constructor_by_environment_variables(self):
121122
environ_patcher = mock.patch.dict(
122123
"os.environ",
123124
{
124-
"OTEL_EXPORTER_JAEGER_AGENT_HOST": agent_host_name,
125-
"OTEL_EXPORTER_JAEGER_AGENT_PORT": agent_port,
126-
"OTEL_EXPORTER_JAEGER_ENDPOINT": collector_endpoint,
127-
"OTEL_EXPORTER_JAEGER_USER": username,
128-
"OTEL_EXPORTER_JAEGER_PASSWORD": password,
125+
OTEL_EXPORTER_JAEGER_AGENT_HOST: agent_host_name,
126+
OTEL_EXPORTER_JAEGER_AGENT_PORT: agent_port,
127+
OTEL_EXPORTER_JAEGER_ENDPOINT: collector_endpoint,
128+
OTEL_EXPORTER_JAEGER_USER: username,
129+
OTEL_EXPORTER_JAEGER_PASSWORD: password,
129130
},
130131
)
131132

exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
from abc import ABC, abstractmethod
2020
from collections.abc import Mapping, Sequence
21+
from os import environ
2122
from time import sleep
2223
from typing import Any, Callable, Dict, Generic, List, Optional
2324
from typing import Sequence as TypingSequence
@@ -35,9 +36,15 @@
3536
ssl_channel_credentials,
3637
)
3738

38-
from opentelemetry.configuration import Configuration
3939
from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
4040
from opentelemetry.proto.resource.v1.resource_pb2 import Resource
41+
from opentelemetry.sdk.environment_variables import (
42+
OTEL_EXPORTER_OTLP_CERTIFICATE,
43+
OTEL_EXPORTER_OTLP_ENDPOINT,
44+
OTEL_EXPORTER_OTLP_HEADERS,
45+
OTEL_EXPORTER_OTLP_INSECURE,
46+
OTEL_EXPORTER_OTLP_TIMEOUT,
47+
)
4148
from opentelemetry.sdk.resources import Resource as SDKResource
4249

4350
logger = logging.getLogger(__name__)
@@ -159,23 +166,23 @@ def __init__(
159166

160167
endpoint = (
161168
endpoint
162-
or Configuration().EXPORTER_OTLP_ENDPOINT
169+
or environ.get(OTEL_EXPORTER_OTLP_ENDPOINT)
163170
or "localhost:4317"
164171
)
165172

166173
if insecure is None:
167-
insecure = Configuration().EXPORTER_OTLP_INSECURE
174+
insecure = environ.get(OTEL_EXPORTER_OTLP_INSECURE)
168175
if insecure is None:
169176
insecure = False
170177

171-
self._headers = headers or Configuration().EXPORTER_OTLP_HEADERS
178+
self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS)
172179
if isinstance(self._headers, str):
173180
self._headers = tuple(
174181
tuple(item.split("=")) for item in self._headers.split(",")
175182
)
176183
self._timeout = (
177184
timeout
178-
or Configuration().EXPORTER_OTLP_TIMEOUT
185+
or int(environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 0))
179186
or 10 # default: 10 seconds
180187
)
181188
self._collector_span_kwargs = None
@@ -188,7 +195,7 @@ def __init__(
188195
):
189196
compression_algorithm = Compression.Gzip
190197
else:
191-
compression_str = Configuration().EXPORTER_OTLP_INSECURE or None
198+
compression_str = environ.get(OTEL_EXPORTER_OTLP_INSECURE)
192199
if compression_str is None:
193200
compression_algorithm = Compression.NoCompression
194201
elif (
@@ -210,13 +217,13 @@ def __init__(
210217
# secure mode
211218
if (
212219
credentials is None
213-
and Configuration().EXPORTER_OTLP_CERTIFICATE is None
220+
and environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE) is None
214221
):
215222
# use the default location chosen by gRPC runtime
216223
credentials = ssl_channel_credentials()
217224
else:
218225
credentials = credentials or _load_credential_from_file(
219-
Configuration().EXPORTER_OTLP_CERTIFICATE
226+
environ.get(OTEL_EXPORTER_OTLP_CERTIFICATE)
220227
)
221228
self._client = self._stub(
222229
secure_channel(

0 commit comments

Comments
 (0)