Skip to content

Commit 78adca2

Browse files
Merge branch 'main' into grpc-aio-abort-arity
2 parents d3b3a73 + 773e431 commit 78adca2

File tree

70 files changed

+349
-325
lines changed

Some content is hidden

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

70 files changed

+349
-325
lines changed

.pylintrc

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# A comma-separated list of package or module names from where C extensions may
44
# be loaded. Extensions are loading into the active Python interpreter and may
55
# run arbitrary code.
6-
extension-pkg-whitelist=
6+
extension-pkg-whitelist=cassandra
77

88
# Add list of files or directories to be excluded. They should be base names, not
99
# paths.
@@ -29,7 +29,7 @@ limit-inference-results=100
2929

3030
# List of plugins (as comma separated values of python modules names) to load,
3131
# usually to register additional checkers.
32-
load-plugins=
32+
load-plugins=pylint.extensions.no_self_use
3333

3434
# Pickle collected data for later comparisons.
3535
persistent=yes
@@ -69,7 +69,6 @@ disable=missing-docstring,
6969
duplicate-code,
7070
ungrouped-imports, # Leave this up to isort
7171
wrong-import-order, # Leave this up to isort
72-
bad-continuation, # Leave this up to black
7372
line-too-long, # Leave this up to black
7473
exec-used,
7574
super-with-arguments, # temp-pylint-upgrade
@@ -81,6 +80,7 @@ disable=missing-docstring,
8180
invalid-overridden-method, # temp-pylint-upgrade
8281
missing-module-docstring, # temp-pylint-upgrade
8382
import-error, # needed as a workaround as reported here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/290
83+
cyclic-import,
8484

8585
# Enable the message, report, category or checker with the given id(s). You can
8686
# either give multiple identifier separated by comma (,) or put this option
@@ -268,13 +268,6 @@ max-line-length=79
268268
# Maximum number of lines in a module.
269269
max-module-lines=1000
270270

271-
# List of optional constructs for which whitespace checking is disabled. `dict-
272-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
273-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
274-
# `empty-line` allows space-only lines.
275-
no-space-check=trailing-comma,
276-
dict-separator
277-
278271
# Allow the body of a class to be on the same line as the declaration if body
279272
# contains single statement.
280273
single-line-class-stmt=no

CONTRIBUTING.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ An easier way to do so is:
5252
2. Run `.tox/lint/bin/isort .`
5353

5454
See
55-
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)
55+
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini)
5656
for more detail on available tox commands.
5757

58+
### Troubleshooting
59+
60+
- Some packages may require additional system wide dependencies to be installed. For example, you may need to install `libpq-dev` to run the postgresql client libraries instrumentation tests. or `libsnappy-dev` to run the prometheus exporter tests. If you encounter a build error, please check the installation instructions for the package you are trying to run tests for.
61+
5862
### Benchmarks
5963

6064
Performance progression of benchmarks for packages distributed by OpenTelemetry Python can be viewed as a [graph of throughput vs commit history](https://opentelemetry-python-contrib.readthedocs.io/en/latest/performance/benchmarks.html). From the linked page, you can download a JSON file with the performance results.

dev-requirements.txt

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
pylint==2.12.2
2-
flake8~=3.7
3-
isort~=5.6
4-
black>=22.1.0
5-
httpretty~=1.0
6-
mypy==0.790
7-
sphinx
8-
sphinx-rtd-theme~=0.4
9-
sphinx-autodoc-typehints
10-
pytest!=5.2.3
11-
pytest-cov>=2.8
12-
readme-renderer~=24.0
1+
pylint==3.0.2
2+
flake8==6.1.0
3+
isort==5.12.0
4+
black==22.3.0
5+
httpretty==1.1.4
6+
mypy==0.931
7+
sphinx==7.1.2
8+
sphinx-rtd-theme==2.0.0rc4
9+
sphinx-autodoc-typehints==1.25.2
10+
pytest==7.1.3
11+
pytest-cov==4.1.0
12+
readme-renderer==42.0
1313
bleach==4.1.0 # transient dependency for readme-renderer
14-
grpcio-tools==1.29.0
15-
mypy-protobuf>=1.23
1614
protobuf~=3.13
1715
markupsafe>=2.0.1
1816
codespell==2.1.0
1917
requests==2.31.0
2018
ruamel.yaml==0.17.21
19+
flaky==3.7.0

docs-requirements.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
sphinx==4.5.0
2-
sphinx-rtd-theme~=0.4
3-
sphinx-autodoc-typehints
1+
sphinx==7.1.2
2+
sphinx-rtd-theme==2.0.0rc4
3+
sphinx-autodoc-typehints==1.25.2
44

55
# Need to install the api/sdk in the venv for autodoc. Modifying sys.path
66
# doesn't work for pkg_resources.
@@ -45,11 +45,8 @@ remoulade>=0.50
4545
sqlalchemy>=1.0
4646
tornado>=5.1.1
4747
tortoise-orm>=0.17.0
48-
ddtrace>=0.34.0
4948
httpx>=0.18.0
5049

5150
# indirect dependency pins
5251
markupsafe==2.0.1
5352
itsdangerous==2.0.1
54-
55-
docutils==0.16

eachdist.ini

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ packages=
5454
[lintroots]
5555
extraroots=examples/*,scripts/
5656
subglob=*.py,tests/,test/,src/*,examples/*
57+
ignore=sklearn
5758

5859
[testroots]
5960
extraroots=examples/*,tests/

exporter/opentelemetry-exporter-prometheus-remote-write/tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pytest
44

55
import opentelemetry.test.metrictestutil as metric_util
6+
7+
# pylint: disable=no-name-in-module
68
from opentelemetry.exporter.prometheus_remote_write import (
79
PrometheusRemoteWriteMetricsExporter,
810
)

exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919

20+
# pylint: disable=no-name-in-module
2021
from opentelemetry.exporter.prometheus_remote_write import (
2122
PrometheusRemoteWriteMetricsExporter,
2223
)

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import asyncio
1616
import contextlib
17+
import sys
1718
import typing
1819
import unittest
1920
import urllib.parse
@@ -116,14 +117,19 @@ def test_status_codes(self):
116117
status_code=status_code,
117118
)
118119

120+
url = f"http://{host}:{port}/test-path?query=param#foobar"
121+
# if python version is < 3.8, then the url will be
122+
if sys.version_info[1] < 8:
123+
url = f"http://{host}:{port}/test-path#foobar"
124+
119125
self.assert_spans(
120126
[
121127
(
122128
"GET",
123129
(span_status, None),
124130
{
125131
SpanAttributes.HTTP_METHOD: "GET",
126-
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path#foobar",
132+
SpanAttributes.HTTP_URL: url,
127133
SpanAttributes.HTTP_STATUS_CODE: int(
128134
status_code
129135
),
@@ -136,7 +142,7 @@ def test_status_codes(self):
136142

137143
def test_schema_url(self):
138144
with self.subTest(status_code=200):
139-
host, port = self._http_request(
145+
self._http_request(
140146
trace_config=aiohttp_client.create_trace_config(),
141147
url="/test-path?query=param#foobar",
142148
status_code=200,
@@ -156,7 +162,7 @@ def test_not_recording(self):
156162
mock_tracer.start_span.return_value = mock_span
157163
with mock.patch("opentelemetry.trace.get_tracer"):
158164
# pylint: disable=W0612
159-
host, port = self._http_request(
165+
self._http_request(
160166
trace_config=aiohttp_client.create_trace_config(),
161167
url="/test-path?query=param#foobar",
162168
)

instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# limitations under the License.
1414

1515
import urllib
16+
from timeit import default_timer
17+
from typing import Dict, List, Tuple, Union
18+
1619
from aiohttp import web
1720
from multidict import CIMultiDictProxy
18-
from timeit import default_timer
19-
from typing import Tuple, Dict, List, Union
2021

21-
from opentelemetry import context, trace, metrics
22+
from opentelemetry import context, metrics, trace
2223
from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
2324
from opentelemetry.instrumentation.aiohttp_server.package import _instruments
2425
from opentelemetry.instrumentation.aiohttp_server.version import __version__
2526
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
2627
from opentelemetry.instrumentation.utils import http_status_to_status_code
27-
from opentelemetry.propagators.textmap import Getter
2828
from opentelemetry.propagate import extract
29-
from opentelemetry.semconv.trace import SpanAttributes
29+
from opentelemetry.propagators.textmap import Getter
3030
from opentelemetry.semconv.metrics import MetricInstruments
31+
from opentelemetry.semconv.trace import SpanAttributes
3132
from opentelemetry.trace.status import Status, StatusCode
32-
from opentelemetry.util.http import get_excluded_urls
33-
from opentelemetry.util.http import remove_url_credentials
33+
from opentelemetry.util.http import get_excluded_urls, remove_url_credentials
3434

3535
_duration_attrs = [
3636
SpanAttributes.HTTP_METHOD,
@@ -127,7 +127,7 @@ def collect_request_attributes(request: web.Request) -> Dict:
127127
result[SpanAttributes.HTTP_METHOD] = http_method
128128

129129
http_host_value_list = (
130-
[request.host] if type(request.host) != list else request.host
130+
[request.host] if not isinstance(request.host, list) else request.host
131131
)
132132
if http_host_value_list:
133133
result[SpanAttributes.HTTP_SERVER_NAME] = ",".join(

instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py

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

15+
from enum import Enum
16+
from http import HTTPStatus
17+
18+
import aiohttp
1519
import pytest
1620
import pytest_asyncio
17-
import aiohttp
18-
from http import HTTPStatus
19-
from .utils import HTTPMethod
2021

2122
from opentelemetry import trace as trace_api
22-
from opentelemetry.test.test_base import TestBase
23-
from opentelemetry.instrumentation.aiohttp_server import AioHttpServerInstrumentor
23+
from opentelemetry.instrumentation.aiohttp_server import (
24+
AioHttpServerInstrumentor,
25+
)
2426
from opentelemetry.semconv.trace import SpanAttributes
27+
from opentelemetry.test.globals_test import reset_trace_globals
28+
from opentelemetry.test.test_base import TestBase
2529
from opentelemetry.util._importlib_metadata import entry_points
2630

27-
from opentelemetry.test.globals_test import (
28-
reset_trace_globals,
29-
)
3031

32+
class HTTPMethod(Enum):
33+
"""HTTP methods and descriptions"""
34+
35+
def __repr__(self):
36+
return f"{self.value}"
37+
38+
CONNECT = "CONNECT"
39+
DELETE = "DELETE"
40+
GET = "GET"
41+
HEAD = "HEAD"
42+
OPTIONS = "OPTIONS"
43+
PATCH = "PATCH"
44+
POST = "POST"
45+
PUT = "PUT"
46+
TRACE = "TRACE"
3147

32-
@pytest.fixture(scope="session")
33-
def tracer():
48+
49+
@pytest.fixture(name="tracer", scope="session")
50+
def fixture_tracer():
3451
test_base = TestBase()
3552

3653
tracer_provider, memory_exporter = test_base.create_tracer_provider()
@@ -47,15 +64,14 @@ async def default_handler(request, status=200):
4764
return aiohttp.web.Response(status=status)
4865

4966

50-
@pytest_asyncio.fixture
51-
async def server_fixture(tracer, aiohttp_server):
67+
@pytest_asyncio.fixture(name="server_fixture")
68+
async def fixture_server_fixture(tracer, aiohttp_server):
5269
_, memory_exporter = tracer
5370

5471
AioHttpServerInstrumentor().instrument()
5572

5673
app = aiohttp.web.Application()
57-
app.add_routes(
58-
[aiohttp.web.get("/test-path", default_handler)])
74+
app.add_routes([aiohttp.web.get("/test-path", default_handler)])
5975

6076
server = await aiohttp_server(app)
6177
yield server, app
@@ -67,26 +83,31 @@ async def server_fixture(tracer, aiohttp_server):
6783

6884
def test_checking_instrumentor_pkg_installed():
6985

70-
(instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="aiohttp-server")
86+
(instrumentor_entrypoint,) = entry_points(
87+
group="opentelemetry_instrumentor", name="aiohttp-server"
88+
)
7189
instrumentor = instrumentor_entrypoint.load()()
72-
assert (isinstance(instrumentor, AioHttpServerInstrumentor))
90+
assert isinstance(instrumentor, AioHttpServerInstrumentor)
7391

7492

7593
@pytest.mark.asyncio
76-
@pytest.mark.parametrize("url, expected_method, expected_status_code", [
77-
("/test-path", HTTPMethod.GET, HTTPStatus.OK),
78-
("/not-found", HTTPMethod.GET, HTTPStatus.NOT_FOUND)
79-
])
94+
@pytest.mark.parametrize(
95+
"url, expected_method, expected_status_code",
96+
[
97+
("/test-path", HTTPMethod.GET, HTTPStatus.OK),
98+
("/not-found", HTTPMethod.GET, HTTPStatus.NOT_FOUND),
99+
],
100+
)
80101
async def test_status_code_instrumentation(
81102
tracer,
82103
server_fixture,
83104
aiohttp_client,
84105
url,
85106
expected_method,
86-
expected_status_code
107+
expected_status_code,
87108
):
88109
_, memory_exporter = tracer
89-
server, app = server_fixture
110+
server, _ = server_fixture
90111

91112
assert len(memory_exporter.get_finished_spans()) == 0
92113

@@ -98,8 +119,12 @@ async def test_status_code_instrumentation(
98119
[span] = memory_exporter.get_finished_spans()
99120

100121
assert expected_method.value == span.attributes[SpanAttributes.HTTP_METHOD]
101-
assert expected_status_code == span.attributes[SpanAttributes.HTTP_STATUS_CODE]
102-
103-
assert f"http://{server.host}:{server.port}{url}" == span.attributes[
104-
SpanAttributes.HTTP_URL
105-
]
122+
assert (
123+
expected_status_code
124+
== span.attributes[SpanAttributes.HTTP_STATUS_CODE]
125+
)
126+
127+
assert (
128+
f"http://{server.host}:{server.port}{url}"
129+
== span.attributes[SpanAttributes.HTTP_URL]
130+
)

instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py

-32
This file was deleted.

0 commit comments

Comments
 (0)