Skip to content

Commit 4ea6fd2

Browse files
committed
fix lint, add dev dependencies
1 parent a80e98d commit 4ea6fd2

File tree

8 files changed

+39
-25
lines changed

8 files changed

+39
-25
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension-pkg-whitelist=cassandra
77

88
# Add list of files or directories to be excluded. They should be base names, not
99
# paths.
10-
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt,mock_collector_service_pb2.py,mock_collector_service_pb2.pyi,mock_collector_service_pb2_grpc.py
10+
ignore=CVS,gen,Dockerfile,docker-compose.yml,README.md,requirements.txt,mock_collector_service_pb2.py,mock_collector_service_pb2.pyi,mock_collector_service_pb2_grpc.py,pyproject.toml,db.sqlite3
1111

1212
# Add files or directories matching the regex patterns to be excluded. The
1313
# regex matches against base names, not paths.

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_fastapi_patches.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ def _apply_fastapi_code_attributes_patch() -> None:
3636
"""
3737
try:
3838
# Import FastAPI instrumentation classes and AWS decorator
39-
from fastapi import routing
39+
from fastapi import routing # pylint: disable=import-outside-toplevel
4040

41-
from amazon.opentelemetry.distro.code_correlation import record_code_attributes
42-
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
41+
from amazon.opentelemetry.distro.code_correlation import ( # pylint: disable=import-outside-toplevel
42+
record_code_attributes,
43+
)
44+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor # pylint: disable=import-outside-toplevel
4345

4446
# Store the original _instrument and _uninstrument methods
4547
original_instrument = FastAPIInstrumentor._instrument

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_flask_patches.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _apply_flask_instrumentation_patches() -> None:
2020
_apply_flask_code_attributes_patch()
2121

2222

23-
def _apply_flask_code_attributes_patch() -> None:
23+
def _apply_flask_code_attributes_patch() -> None: # pylint: disable=too-many-statements
2424
"""Flask instrumentation patch for code attributes
2525
2626
This patch modifies the Flask instrumentation to automatically apply
@@ -37,10 +37,12 @@ def _apply_flask_code_attributes_patch() -> None:
3737
"""
3838
try:
3939
# Import Flask instrumentation classes and AWS decorator
40-
import flask
40+
import flask # pylint: disable=import-outside-toplevel
4141

42-
from amazon.opentelemetry.distro.code_correlation import record_code_attributes
43-
from opentelemetry.instrumentation.flask import FlaskInstrumentor
42+
from amazon.opentelemetry.distro.code_correlation import ( # pylint: disable=import-outside-toplevel
43+
record_code_attributes,
44+
)
45+
from opentelemetry.instrumentation.flask import FlaskInstrumentor # pylint: disable=import-outside-toplevel
4446

4547
# Store the original _instrument and _uninstrument methods
4648
original_instrument = FlaskInstrumentor._instrument
@@ -79,7 +81,7 @@ def _wrapped_dispatch_request(self):
7981
"""Wrapped Flask.dispatch_request method to handle deferred view function binding."""
8082
try:
8183
# Get the current request context
82-
from flask import request
84+
from flask import request # pylint: disable=import-outside-toplevel
8385

8486
# Check if there's an endpoint for this request
8587
endpoint = request.endpoint

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_starlette_patches.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ def _apply_starlette_code_attributes_patch() -> None:
8282
"""
8383
try:
8484
# Import Starlette routing classes and AWS decorator
85-
from starlette.routing import Route
86-
87-
from amazon.opentelemetry.distro.code_correlation import record_code_attributes
88-
from opentelemetry.instrumentation.starlette import StarletteInstrumentor
85+
from starlette.routing import Route # pylint: disable=import-outside-toplevel
86+
87+
from amazon.opentelemetry.distro.code_correlation import ( # pylint: disable=import-outside-toplevel
88+
record_code_attributes,
89+
)
90+
from opentelemetry.instrumentation.starlette import ( # pylint: disable=import-outside-toplevel
91+
StarletteInstrumentor,
92+
)
8993

9094
# Store the original _instrument and _uninstrument methods
9195
original_instrument = StarletteInstrumentor._instrument

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/patches/test_flask_patches.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def setUp(self):
3939
self.app = flask.Flask(__name__)
4040

4141
# Add test routes
42-
@self.app.route("/hello/<name>")
43-
def hello(name):
44-
return f"Hello {name}!"
42+
@self.app.route("/hello")
43+
def hello():
44+
return "Hello!"
4545

4646
@self.app.route("/error")
4747
def error_endpoint():
@@ -120,7 +120,7 @@ def test_flask_patches_with_real_app(self, mock_get_status):
120120

121121
# Test a request to trigger the patches
122122
instrumentor.instrument_app(self.app)
123-
resp = self.client.get("/hello/world")
123+
resp = self.client.get("/hello")
124124
self.assertEqual(200, resp.status_code)
125125

126126
# Test uninstrumentation - this should restore original Flask methods
@@ -152,16 +152,16 @@ def test_flask_patches_disabled(self, mock_get_status):
152152
mock_get_status.assert_called_once()
153153

154154
# Make a request
155-
resp = self.client.get("/hello/world")
155+
resp = self.client.get("/hello")
156156
self.assertEqual(200, resp.status_code)
157-
self.assertEqual([b"Hello world!"], list(resp.response))
157+
self.assertEqual([b"Hello!"], list(resp.response))
158158

159159
# Check spans were still generated (normal instrumentation)
160160
spans = self.memory_exporter.get_finished_spans()
161161
self.assertEqual(len(spans), 1)
162162

163163
span = spans[0]
164-
self.assertEqual(span.name, "GET /hello/<name>")
164+
self.assertEqual(span.name, "GET /hello")
165165
self.assertEqual(span.kind, trace.SpanKind.SERVER)
166166

167167
# Clean up - avoid Flask instrumentation issues
@@ -226,7 +226,6 @@ def lambda_func():
226226
self.app.add_url_rule("/test_lambda", "test_lambda", lambda_func)
227227

228228
# Clean up - don't call uninstrument_app to avoid Flask instrumentation issues
229-
pass
230229

231230
@patch("amazon.opentelemetry.distro.patches._flask_patches.get_code_correlation_enabled_status")
232231
def test_flask_patches_dispatch_request_coverage(self, mock_get_status):

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_remote_sampler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,14 @@ def test_should_sample_with_expired_rule_cache(self, mock_post=None):
344344
self.rs = AwsXRayRemoteSampler(resource=Resource.get_empty())
345345

346346
# Mock rule cache to be expired
347-
with patch.object(self.rs._root._root._AwsXRayRemoteSampler__rule_cache, "expired", return_value=True):
348-
with patch("amazon.opentelemetry.distro.sampler.aws_xray_remote_sampler._logger") as mock_logger:
347+
with patch.object(
348+
self.rs._root._root._AwsXRayRemoteSampler__rule_cache, "expired", return_value=True
349+
): # pylint: disable=not-context-manager
350+
with patch(
351+
"amazon.opentelemetry.distro.sampler.aws_xray_remote_sampler._logger"
352+
) as mock_logger: # pylint: disable=not-context-manager
349353
# Call should_sample when cache is expired
350-
result = self.rs._root._root.should_sample(None, 0, "test_span")
354+
result = self.rs._root._root.should_sample(None, 0, "test_span") # pylint: disable=not-context-manager
351355

352356
# Verify debug log was called
353357
mock_logger.debug.assert_called_once_with("Rule cache is expired so using fallback sampling strategy")

eachdist.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[lintroots]
66
extraroots=scripts/, sample-applications/, contract-tests/images/
7-
subglob=*.py,tests/,test/,src/*, simple-client-server, applications/django/**
7+
subglob=*.py,src/*, simple-client-server, applications/django/**
88

99
[testroots]
1010
extraroots=tests/

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ deps =
1515
-c dev-requirements.txt
1616
test: pytest
1717
test: pytest-cov
18+
test: fastapi
19+
test: starlette
20+
test: flask
1821

1922
setenv =
2023
; TODO: The two repos branches need manual updated over time, need to figure out a more sustainable solution.

0 commit comments

Comments
 (0)