Skip to content

Commit c4a36ad

Browse files
committed
Fix lint
1 parent 432ae70 commit c4a36ad

File tree

13 files changed

+65
-62
lines changed

13 files changed

+65
-62
lines changed

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

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

15-
from time import time
1615
from logging import getLogger
1716
from os import environ
18-
from re import compile as re_compile, search
17+
from re import compile as re_compile
18+
from re import search
19+
from time import time
1920

2021
from django.conf import settings
2122

@@ -63,6 +64,7 @@ def __init__(self, excluded_urls):
6364
def url_disabled(self, url: str) -> bool:
6465
return bool(self._excluded_urls and search(self._regex, url))
6566

67+
6668
_root = r"OTEL_PYTHON_{}"
6769

6870

@@ -85,8 +87,7 @@ def _get_excluded_urls():
8587

8688
if excluded_urls:
8789
excluded_urls = [
88-
excluded_url.strip()
89-
for excluded_url in excluded_urls.split(",")
90+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
9091
]
9192

9293
return _ExcludeList(excluded_urls)
@@ -153,21 +154,21 @@ def process_request(self, request):
153154
# pylint:disable=W0212
154155
request._otel_start_time = time()
155156

156-
environ = request.META
157+
request_meta = request.META
157158

158-
token = attach(extract(carrier_getter, environ))
159+
token = attach(extract(carrier_getter, request_meta))
159160

160161
tracer = get_tracer(__name__, __version__)
161162

162163
span = tracer.start_span(
163164
self._get_span_name(request),
164165
kind=SpanKind.SERVER,
165-
start_time=environ.get(
166+
start_time=request_meta.get(
166167
"opentelemetry-instrumentor-django.starttime_key"
167168
),
168169
)
169170

170-
attributes = collect_request_attributes(environ)
171+
attributes = collect_request_attributes(request_meta)
171172
# pylint:disable=W0212
172173
request._otel_labels = self._get_metric_labels_from_attributes(
173174
attributes

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
from opentelemetry.instrumentation.django import DjangoInstrumentor
2525
from opentelemetry.instrumentation.django.middleware import (
26-
_get_excluded_urls, _get_traced_request_attrs
26+
_get_excluded_urls,
27+
_get_traced_request_attrs,
2728
)
2829
from opentelemetry.sdk.util import get_dict_as_key
2930
from opentelemetry.test.test_base import TestBase

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ def on_get(self, req, resp):
4343
---
4444
"""
4545

46-
from sys import exc_info
4746
from logging import getLogger
48-
from re import compile as re_compile, search
4947
from os import environ
48+
from re import compile as re_compile
49+
from re import search
50+
from sys import exc_info
5051

5152
import falcon
5253

@@ -81,6 +82,7 @@ def __init__(self, excluded_urls):
8182
def url_disabled(self, url: str) -> bool:
8283
return bool(self._excluded_urls and search(self._regex, url))
8384

85+
8486
_root = r"OTEL_PYTHON_{}"
8587

8688

@@ -103,8 +105,7 @@ def _get_excluded_urls():
103105

104106
if excluded_urls:
105107
excluded_urls = [
106-
excluded_url.strip()
107-
for excluded_url in excluded_urls.split(",")
108+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
108109
]
109110

110111
return _ExcludeList(excluded_urls)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from falcon import testing
1818

1919
from opentelemetry.instrumentation.falcon import (
20-
FalconInstrumentor, _get_excluded_urls, _get_traced_request_attrs
20+
FalconInstrumentor,
21+
_get_excluded_urls,
22+
_get_traced_request_attrs,
2123
)
2224
from opentelemetry.test.test_base import TestBase
2325
from opentelemetry.trace.status import StatusCode
@@ -47,9 +49,7 @@ def setUp(self):
4749
0
4850
].__self__
4951
self.traced_patch = patch.object(
50-
middleware,
51-
"_traced_request_attrs",
52-
_get_traced_request_attrs(),
52+
middleware, "_traced_request_attrs", _get_traced_request_attrs(),
5353
)
5454
self.exclude_patch.start()
5555
self.traced_patch.start()

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

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

15-
from re import compile as re_compile, search
1615
from os import environ
16+
from re import compile as re_compile
17+
from re import search
1718

18-
from starlette.routing import Match
1919
import fastapi
20+
from starlette.routing import Match
2021

2122
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
2223
from opentelemetry.instrumentation.fastapi.version import __version__ # noqa
@@ -40,8 +41,7 @@ def _get_excluded_urls():
4041

4142
if excluded_urls:
4243
excluded_urls = [
43-
excluded_url.strip()
44-
for excluded_url in excluded_urls.split(",")
44+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
4545
]
4646

4747
return _ExcludeList(excluded_urls)

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

+17-13
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ def hello():
4848
"""
4949

5050
from logging import getLogger
51-
from re import compile as re_compile, search
5251
from os import environ
52+
from re import compile as re_compile
53+
from re import search
5354

5455
import flask
5556

@@ -84,8 +85,7 @@ def _get_excluded_urls():
8485

8586
if excluded_urls:
8687
excluded_urls = [
87-
excluded_url.strip()
88-
for excluded_url in excluded_urls.split(",")
88+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
8989
]
9090

9191
return _ExcludeList(excluded_urls)
@@ -104,12 +104,12 @@ def get_default_span_name():
104104

105105

106106
def _rewrapped_app(wsgi_app):
107-
def _wrapped_app(environ, start_response):
107+
def _wrapped_app(wrapped_app_environ, start_response):
108108
# We want to measure the time for route matching, etc.
109109
# In theory, we could start the span here and use
110110
# update_name later but that API is "highly discouraged" so
111111
# we better avoid it.
112-
environ[_ENVIRON_STARTTIME_KEY] = time_ns()
112+
wrapped_app_environ[_ENVIRON_STARTTIME_KEY] = time_ns()
113113

114114
def _start_response(status, response_headers, *args, **kwargs):
115115
if not _excluded_urls.url_disabled(flask.request.url):
@@ -128,7 +128,7 @@ def _start_response(status, response_headers, *args, **kwargs):
128128

129129
return start_response(status, response_headers, *args, **kwargs)
130130

131-
return wsgi_app(environ, _start_response)
131+
return wsgi_app(wrapped_app_environ, _start_response)
132132

133133
return _wrapped_app
134134

@@ -138,21 +138,25 @@ def _before_request():
138138
if _excluded_urls.url_disabled(flask.request.url):
139139
return
140140

141-
environ = flask.request.environ
141+
flask_request_environ = flask.request.environ
142142
span_name = name_callback()
143143
token = context.attach(
144-
propagators.extract(otel_wsgi.carrier_getter, environ)
144+
propagators.extract(
145+
otel_wsgi.carrier_getter, flask_request_environ
146+
)
145147
)
146148

147149
tracer = trace.get_tracer(__name__, __version__)
148150

149151
span = tracer.start_span(
150152
span_name,
151153
kind=trace.SpanKind.SERVER,
152-
start_time=environ.get(_ENVIRON_STARTTIME_KEY),
154+
start_time=flask_request_environ.get(_ENVIRON_STARTTIME_KEY),
153155
)
154156
if span.is_recording():
155-
attributes = otel_wsgi.collect_request_attributes(environ)
157+
attributes = otel_wsgi.collect_request_attributes(
158+
flask_request_environ
159+
)
156160
if flask.request.url_rule:
157161
# For 404 that result from no route found, etc, we
158162
# don't have a url_rule.
@@ -162,9 +166,9 @@ def _before_request():
162166

163167
activation = tracer.use_span(span, end_on_exit=True)
164168
activation.__enter__()
165-
environ[_ENVIRON_ACTIVATION_KEY] = activation
166-
environ[_ENVIRON_SPAN_KEY] = span
167-
environ[_ENVIRON_TOKEN] = token
169+
flask_request_environ[_ENVIRON_ACTIVATION_KEY] = activation
170+
flask_request_environ[_ENVIRON_SPAN_KEY] = span
171+
flask_request_environ[_ENVIRON_TOKEN] = token
168172

169173
return _before_request
170174

Diff for: instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818

1919
class InstrumentationTest:
20-
def setUp(self): # pylint: disable=invalid-name
21-
super().setUp() # pylint: disable=no-member
22-
2320
@staticmethod
2421
def _hello_endpoint(helloid):
2522
if helloid == 500:

Diff for: instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
from opentelemetry import trace
2020
from opentelemetry.instrumentation.flask import (
21-
FlaskInstrumentor, _get_excluded_urls
21+
FlaskInstrumentor,
22+
_get_excluded_urls,
2223
)
2324
from opentelemetry.test.test_base import TestBase
2425
from opentelemetry.test.wsgitestutil import WsgiTestBase

Diff for: instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from logging import getLogger
2-
from re import compile as re_compile, search
32
from os import environ
3+
from re import compile as re_compile
4+
from re import search
45

56
from pyramid.events import BeforeTraversal
67
from pyramid.httpexceptions import HTTPException
@@ -41,12 +42,12 @@ def _get_excluded_urls():
4142

4243
if excluded_urls:
4344
excluded_urls = [
44-
excluded_url.strip()
45-
for excluded_url in excluded_urls.split(",")
45+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
4646
]
4747

4848
return _ExcludeList(excluded_urls)
4949

50+
5051
_excluded_urls = _get_excluded_urls()
5152

5253

@@ -69,10 +70,10 @@ def _insert_tween(config):
6970

7071
def _before_traversal(event):
7172
request = event.request
72-
environ = request.environ
73-
span_name = otel_wsgi.get_default_span_name(environ)
73+
request_environ = request.environ
74+
span_name = otel_wsgi.get_default_span_name(request_environ)
7475

75-
enabled = environ.get(_ENVIRON_ENABLED_KEY)
76+
enabled = request_environ.get(_ENVIRON_ENABLED_KEY)
7677
if enabled is None:
7778
_logger.warning(
7879
"Opentelemetry pyramid tween 'opentelemetry.instrumentation.pyramid.trace_tween_factory'"
@@ -85,34 +86,34 @@ def _before_traversal(event):
8586
# Tracing not enabled, return
8687
return
8788

88-
start_time = environ.get(_ENVIRON_STARTTIME_KEY)
89+
start_time = request_environ.get(_ENVIRON_STARTTIME_KEY)
8990

9091
token = context.attach(
91-
propagators.extract(otel_wsgi.carrier_getter, environ)
92+
propagators.extract(otel_wsgi.carrier_getter, request_environ)
9293
)
9394
tracer = trace.get_tracer(__name__, __version__)
9495

9596
if request.matched_route:
9697
span_name = request.matched_route.pattern
9798
else:
98-
span_name = otel_wsgi.get_default_span_name(environ)
99+
span_name = otel_wsgi.get_default_span_name(request_environ)
99100

100101
span = tracer.start_span(
101102
span_name, kind=trace.SpanKind.SERVER, start_time=start_time,
102103
)
103104

104105
if span.is_recording():
105-
attributes = otel_wsgi.collect_request_attributes(environ)
106+
attributes = otel_wsgi.collect_request_attributes(request_environ)
106107
if request.matched_route:
107108
attributes["http.route"] = request.matched_route.pattern
108109
for key, value in attributes.items():
109110
span.set_attribute(key, value)
110111

111112
activation = tracer.use_span(span, end_on_exit=True)
112113
activation.__enter__()
113-
environ[_ENVIRON_ACTIVATION_KEY] = activation
114-
environ[_ENVIRON_SPAN_KEY] = span
115-
environ[_ENVIRON_TOKEN] = token
114+
request_environ[_ENVIRON_ACTIVATION_KEY] = activation
115+
request_environ[_ENVIRON_SPAN_KEY] = span
116+
request_environ[_ENVIRON_TOKEN] = token
116117

117118

118119
def trace_tween_factory(handler, registry):

Diff for: instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020

2121
class InstrumentationTest:
22-
def setUp(self): # pylint: disable=invalid-name
23-
super().setUp() # pylint: disable=no-member
24-
2522
@staticmethod
2623
def _hello_endpoint(request):
2724
helloid = int(request.matchdict["helloid"])

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

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

15-
from re import compile as re_compile, search
1615
from os import environ
16+
from re import compile as re_compile
17+
from re import search
1718

1819
from starlette import applications
1920
from starlette.routing import Match
@@ -40,8 +41,7 @@ def _get_excluded_urls():
4041

4142
if excluded_urls:
4243
excluded_urls = [
43-
excluded_url.strip()
44-
for excluded_url in excluded_urls.split(",")
44+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
4545
]
4646

4747
return _ExcludeList(excluded_urls)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def get(self):
3939
from functools import partial
4040
from logging import getLogger
4141
from os import environ
42-
from re import compile as re_compile, search
42+
from re import compile as re_compile
43+
from re import search
4344

4445
import tornado.web
4546
import wrapt
@@ -99,8 +100,7 @@ def _get_excluded_urls():
99100

100101
if excluded_urls:
101102
excluded_urls = [
102-
excluded_url.strip()
103-
for excluded_url in excluded_urls.split(",")
103+
excluded_url.strip() for excluded_url in excluded_urls.split(",")
104104
]
105105

106106
return _ExcludeList(excluded_urls)

Diff for: instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from opentelemetry import trace
2121
from opentelemetry.instrumentation.tornado import (
2222
TornadoInstrumentor,
23+
_get_excluded_urls,
24+
_get_traced_request_attrs,
2325
patch_handler_class,
2426
unpatch_handler_class,
25-
_get_traced_request_attrs,
26-
_get_excluded_urls,
2727
)
2828
from opentelemetry.test.test_base import TestBase
2929
from opentelemetry.trace import SpanKind

0 commit comments

Comments
 (0)