Skip to content

Commit 2fd68a2

Browse files
authored
Remove Configuration from instrumentations (open-telemetry#285)
1 parent f0adb23 commit 2fd68a2

File tree

41 files changed

+359
-110
lines changed

Some content is hidden

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

41 files changed

+359
-110
lines changed

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: f3ee81243b4266729ba5196a7883ce897549aaba
9+
CORE_REPO_SHA: 09b010cfcc85e2aa07326e9204541b80a7dd52f0
1010

1111
jobs:
1212
build:

Diff for: .pylintrc

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ disable=missing-docstring,
7979
super-init-not-called, # temp-pylint-upgrade
8080
invalid-overridden-method, # temp-pylint-upgrade
8181
missing-module-docstring, # temp-pylint-upgrade
82+
import-error, # needed as a workaround as reported here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/290
8283

8384
# Enable the message, report, category or checker with the given id(s). You can
8485
# either give multiple identifier separated by comma (,) or put this option

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7575
- Update TraceState to adhere to specs
7676
([#276](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/276))
7777

78+
### Removed
79+
- Remove Configuration
80+
([#285](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/285))
81+
7882
## [0.16b1](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b1) - 2020-11-26
7983

8084
## [0.16b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b0) - 2020-11-25

Diff for: docs/nitpick-exceptions.ini

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class_references=
44
opentelemetry.trace.propagation.textmap.TextMapPropagator
55
; - AwsXRayFormat
66
opentelemetry.trace.propagation.textmap.DictGetter
7-
; - instrumentation.asgi.CarrierGetter
87
; API
98
opentelemetry.trace.propagation.textmap.Getter
109
; - DatadogFormat

Diff for: eachdist.ini

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ignore=
77
opentelemetry-python-core
88

99
sortfirst=
10+
util/opentelemetry-util-http
1011
instrumentation/opentelemetry-instrumentation-wsgi
1112
instrumentation/opentelemetry-instrumentation-dbapi
1213
instrumentation/opentelemetry-instrumentation-asgi

Diff for: instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
timing through OpenTelemetry.
1919
"""
2020

21-
import operator
2221
import typing
2322
import urllib
2423
from functools import wraps

Diff for: instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ def _instrument(self, **kwargs):
8484
# For exemple EC2 uses AWSQueryConnection and S3 uses
8585
# AWSAuthConnection
8686

87-
# FIXME should the tracer provider be accessed via Configuration
88-
# instead?
8987
# pylint: disable=attribute-defined-outside-init
9088
self._tracer = get_tracer(
9189
__name__, __version__, kwargs.get("tracer_provider")

Diff for: instrumentation/opentelemetry-instrumentation-django/setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ package_dir=
4040
packages=find_namespace:
4141
install_requires =
4242
django >= 1.10
43+
opentelemetry-util-http == 0.18.dev0
4344
opentelemetry-instrumentation-wsgi == 0.18.dev0
4445
opentelemetry-instrumentation == 0.18.dev0
4546
opentelemetry-api == 0.18.dev0

Diff for: instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
# limitations under the License.
1414

1515
from logging import getLogger
16+
from os import environ
1617

1718
from django.conf import settings
1819

19-
from opentelemetry.configuration import Configuration
20+
from opentelemetry.instrumentation.django.environment_variables import (
21+
OTEL_PYTHON_DJANGO_INSTRUMENT,
22+
)
2023
from opentelemetry.instrumentation.django.middleware import _DjangoMiddleware
2124
from opentelemetry.instrumentation.django.version import __version__
2225
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
@@ -43,11 +46,7 @@ def _instrument(self, **kwargs):
4346

4447
# FIXME this is probably a pattern that will show up in the rest of the
4548
# ext. Find a better way of implementing this.
46-
# FIXME Probably the evaluation of strings into boolean values can be
47-
# built inside the Configuration class itself with the magic method
48-
# __bool__
49-
50-
if Configuration().DJANGO_INSTRUMENT is False:
49+
if environ.get(OTEL_PYTHON_DJANGO_INSTRUMENT) == "False":
5150
return
5251

5352
# This can not be solved, but is an inherent problem of this approach:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
OTEL_PYTHON_DJANGO_INSTRUMENT = "OTEL_PYTHON_DJANGO_INSTRUMENT"

Diff for: instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import time
1615
from logging import getLogger
16+
from time import time
1717

1818
from django.conf import settings
1919

20-
from opentelemetry.configuration import Configuration
2120
from opentelemetry.context import attach, detach
2221
from opentelemetry.instrumentation.django.version import __version__
2322
from opentelemetry.instrumentation.utils import extract_attributes_from_object
@@ -28,6 +27,7 @@
2827
)
2928
from opentelemetry.propagators import extract
3029
from opentelemetry.trace import SpanKind, get_tracer
30+
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs
3131

3232
try:
3333
from django.core.urlresolvers import ( # pylint: disable=no-name-in-module
@@ -61,9 +61,8 @@ class _DjangoMiddleware(MiddlewareMixin):
6161
_environ_span_key = "opentelemetry-instrumentor-django.span_key"
6262
_environ_exception_key = "opentelemetry-instrumentor-django.exception_key"
6363

64-
_excluded_urls = Configuration()._excluded_urls("django")
65-
66-
_traced_request_attrs = Configuration()._traced_request_attrs("django")
64+
_traced_request_attrs = get_traced_request_attrs("DJANGO")
65+
_excluded_urls = get_excluded_urls("DJANGO")
6766

6867
@staticmethod
6968
def _get_span_name(request):
@@ -111,23 +110,23 @@ def process_request(self, request):
111110
return
112111

113112
# pylint:disable=W0212
114-
request._otel_start_time = time.time()
113+
request._otel_start_time = time()
115114

116-
environ = request.META
115+
request_meta = request.META
117116

118-
token = attach(extract(carrier_getter, environ))
117+
token = attach(extract(carrier_getter, request_meta))
119118

120119
tracer = get_tracer(__name__, __version__)
121120

122121
span = tracer.start_span(
123122
self._get_span_name(request),
124123
kind=SpanKind.SERVER,
125-
start_time=environ.get(
124+
start_time=request_meta.get(
126125
"opentelemetry-instrumentor-django.starttime_key"
127126
),
128127
)
129128

130-
attributes = collect_request_attributes(environ)
129+
attributes = collect_request_attributes(request_meta)
131130
# pylint:disable=W0212
132131
request._otel_labels = self._get_metric_labels_from_attributes(
133132
attributes
@@ -215,7 +214,7 @@ def process_response(self, request, response):
215214
if metric_recorder is not None:
216215
# pylint:disable=W0212
217216
metric_recorder.record_server_duration_range(
218-
request._otel_start_time, time.time(), request._otel_labels
217+
request._otel_start_time, time(), request._otel_labels
219218
)
220219
except Exception as ex: # pylint: disable=W0703
221220
_logger.warning("Error recording duration metrics: %s", ex)

Diff for: instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from django.test import Client
2222
from django.test.utils import setup_test_environment, teardown_test_environment
2323

24-
from opentelemetry.configuration import Configuration
2524
from opentelemetry.instrumentation.django import DjangoInstrumentor
2625
from opentelemetry.sdk.util import get_dict_as_key
2726
from opentelemetry.test.test_base import TestBase
2827
from opentelemetry.test.wsgitestutil import WsgiTestBase
2928
from opentelemetry.trace import SpanKind
3029
from opentelemetry.trace.status import StatusCode
30+
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs
3131

3232
# pylint: disable=import-error
3333
from .views import (
@@ -64,7 +64,6 @@ def setUp(self):
6464
super().setUp()
6565
setup_test_environment()
6666
_django_instrumentor.instrument()
67-
Configuration._reset() # pylint: disable=protected-access
6867
self.env_patch = patch.dict(
6968
"os.environ",
7069
{
@@ -75,11 +74,11 @@ def setUp(self):
7574
self.env_patch.start()
7675
self.exclude_patch = patch(
7776
"opentelemetry.instrumentation.django.middleware._DjangoMiddleware._excluded_urls",
78-
Configuration()._excluded_urls("django"),
77+
get_excluded_urls("DJANGO"),
7978
)
8079
self.traced_patch = patch(
8180
"opentelemetry.instrumentation.django.middleware._DjangoMiddleware._traced_request_attrs",
82-
Configuration()._traced_request_attrs("django"),
81+
get_traced_request_attrs("DJANGO"),
8382
)
8483
self.exclude_patch.start()
8584
self.traced_patch.start()

Diff for: instrumentation/opentelemetry-instrumentation-falcon/setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ packages=find_namespace:
4242
install_requires =
4343
falcon ~= 2.0
4444
opentelemetry-instrumentation-wsgi == 0.18.dev0
45+
opentelemetry-util-http == 0.18.dev0
4546
opentelemetry-instrumentation == 0.18.dev0
4647
opentelemetry-api == 0.18.dev0
4748

Diff for: instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ def on_get(self, req, resp):
4343
---
4444
"""
4545

46-
import sys
4746
from logging import getLogger
47+
from sys import exc_info
4848

4949
import falcon
5050

5151
import opentelemetry.instrumentation.wsgi as otel_wsgi
52-
from opentelemetry import configuration, context, propagators, trace
53-
from opentelemetry.configuration import Configuration
52+
from opentelemetry import context, propagators, trace
5453
from opentelemetry.instrumentation.falcon.version import __version__
5554
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5655
from opentelemetry.instrumentation.utils import (
@@ -59,6 +58,7 @@ def on_get(self, req, resp):
5958
)
6059
from opentelemetry.trace.status import Status
6160
from opentelemetry.util import time_ns
61+
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs
6262

6363
_logger = getLogger(__name__)
6464

@@ -68,8 +68,9 @@ def on_get(self, req, resp):
6868
_ENVIRON_TOKEN = "opentelemetry-falcon.token"
6969
_ENVIRON_EXC = "opentelemetry-falcon.exc"
7070

71-
cfg = configuration.Configuration()
72-
_excluded_urls = cfg._excluded_urls("falcon")
71+
72+
_excluded_urls = get_excluded_urls("FALCON")
73+
_traced_request_attrs = get_traced_request_attrs("FALCON")
7374

7475

7576
class FalconInstrumentor(BaseInstrumentor):
@@ -149,7 +150,7 @@ class _TraceMiddleware:
149150

150151
def __init__(self, tracer=None, traced_request_attrs=None):
151152
self.tracer = tracer
152-
self._traced_request_attrs = cfg._traced_request_attrs("falcon")
153+
self._traced_request_attrs = _traced_request_attrs
153154

154155
def process_request(self, req, resp):
155156
span = req.env.get(_ENVIRON_SPAN_KEY)
@@ -186,7 +187,7 @@ def process_response(
186187
status = "404"
187188
reason = "NotFound"
188189

189-
exc_type, exc, _ = sys.exc_info()
190+
exc_type, exc, _ = exc_info()
190191
if exc_type and not req_succeeded:
191192
if "HTTPNotFound" in exc_type.__name__:
192193
status = "404"

Diff for: instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
from falcon import testing
1818

19-
from opentelemetry.configuration import Configuration
2019
from opentelemetry.instrumentation.falcon import FalconInstrumentor
2120
from opentelemetry.test.test_base import TestBase
2221
from opentelemetry.trace.status import StatusCode
22+
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs
2323

2424
from .app import make_app
2525

@@ -30,7 +30,6 @@ def setUp(self):
3030
FalconInstrumentor().instrument()
3131
self.app = make_app()
3232
# pylint: disable=protected-access
33-
Configuration()._reset()
3433
self.env_patch = patch.dict(
3534
"os.environ",
3635
{
@@ -41,15 +40,15 @@ def setUp(self):
4140
self.env_patch.start()
4241
self.exclude_patch = patch(
4342
"opentelemetry.instrumentation.falcon._excluded_urls",
44-
Configuration()._excluded_urls("falcon"),
43+
get_excluded_urls("FALCON"),
4544
)
4645
middleware = self.app._middleware[0][ # pylint:disable=W0212
4746
0
4847
].__self__
4948
self.traced_patch = patch.object(
5049
middleware,
5150
"_traced_request_attrs",
52-
Configuration()._traced_request_attrs("falcon"),
51+
get_traced_request_attrs("FALCON"),
5352
)
5453
self.exclude_patch.start()
5554
self.traced_patch.start()

Diff for: instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ packages=find_namespace:
4040
install_requires =
4141
opentelemetry-api == 0.18.dev0
4242
opentelemetry-instrumentation-asgi == 0.18.dev0
43+
opentelemetry-util-http == 0.18.dev0
4344

4445
[options.entry_points]
4546
opentelemetry_instrumentor =

Diff for: instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Optional
1514

1615
import fastapi
1716
from starlette.routing import Match
1817

19-
from opentelemetry.configuration import Configuration
2018
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
21-
from opentelemetry.instrumentation.fastapi.version import __version__ # noqa
2219
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
20+
from opentelemetry.util.http import get_excluded_urls
2321

24-
_excluded_urls = Configuration()._excluded_urls("fastapi")
22+
_excluded_urls = get_excluded_urls("FASTAPI")
2523

2624

2725
class FastAPIInstrumentor(BaseInstrumentor):

Diff for: instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from fastapi.testclient import TestClient
2020

2121
import opentelemetry.instrumentation.fastapi as otel_fastapi
22-
from opentelemetry.configuration import Configuration
2322
from opentelemetry.test.test_base import TestBase
23+
from opentelemetry.util.http import get_excluded_urls
2424

2525

2626
class TestFastAPIManualInstrumentation(TestBase):
@@ -31,15 +31,14 @@ def _create_app(self):
3131

3232
def setUp(self):
3333
super().setUp()
34-
Configuration()._reset()
3534
self.env_patch = patch.dict(
3635
"os.environ",
3736
{"OTEL_PYTHON_FASTAPI_EXCLUDED_URLS": "/exclude/123,healthzz"},
3837
)
3938
self.env_patch.start()
4039
self.exclude_patch = patch(
4140
"opentelemetry.instrumentation.fastapi._excluded_urls",
42-
Configuration()._excluded_urls("fastapi"),
41+
get_excluded_urls("FASTAPI"),
4342
)
4443
self.exclude_patch.start()
4544
self._instrumentor = otel_fastapi.FastAPIInstrumentor()

Diff for: instrumentation/opentelemetry-instrumentation-flask/setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ package_dir=
4040
packages=find_namespace:
4141
install_requires =
4242
flask ~= 1.0
43-
opentelemetry-instrumentation-wsgi == 0.18.dev0
43+
opentelemetry-util-http == 0.18.dev0
4444
opentelemetry-instrumentation == 0.18.dev0
45+
opentelemetry-instrumentation-wsgi == 0.18.dev0
4546
opentelemetry-api == 0.18.dev0
4647

4748
[options.extras_require]

0 commit comments

Comments
 (0)