Skip to content

Commit

Permalink
Merge branch 'main' into feature/asyncio-instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bourbonkk authored Dec 3, 2023
2 parents b4ffc63 + 4bf3577 commit ffc043b
Show file tree
Hide file tree
Showing 84 changed files with 1,383 additions and 478 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: 9831afaff5b4d371fd9a14266ab47884546bd971
CORE_REPO_SHA: 35a021194787359324c46f5ca99d31802e4c92bd

jobs:
build:
Expand Down
13 changes: 3 additions & 10 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
extension-pkg-whitelist=cassandra

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

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

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

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

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1919](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1943))
- `opentelemetry-instrumentation` Added Otel semantic convention opt-in mechanism
([#1987](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1987))
- `opentelemetry-instrumentation-httpx` Fix mixing async and non async hooks
([#1920](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1920))
- `opentelemetry-instrumentation-requests` Implement new semantic convention opt-in with stable http semantic conventions
([#2002](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2002))
- `opentelemetry-instrument-grpc` Fix arity of context.abort for AIO RPCs
([#2066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2066))

### Fixed

- `opentelemetry-instrumentation-urllib`/`opentelemetry-instrumentation-urllib3` Fix metric descriptions to match semantic conventions
([#1959](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1959))

## Version 1.21.0/0.42b0 (2023-11-01)

### Added
Expand All @@ -28,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-aio-pika` and `opentelemetry-instrumentation-pika` Fix missing trace context propagation when trace not recording.
([#1969](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1969))
- Fix version of Flask dependency `werkzeug`
([#1980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1980))
- `opentelemetry-resource-detector-azure` Using new Cloud Resource ID attribute.
Expand Down
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ An easier way to do so is:
2. Run `.tox/lint/bin/isort .`

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

### Troubleshooting

- 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.

### Benchmarks

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.
Expand Down
27 changes: 13 additions & 14 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
pylint==2.12.2
flake8~=3.7
isort~=5.6
black>=22.1.0
httpretty~=1.0
mypy==0.790
sphinx
sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints
pytest!=5.2.3
pytest-cov>=2.8
readme-renderer~=24.0
pylint==3.0.2
flake8==6.1.0
isort==5.12.0
black==22.3.0
httpretty==1.1.4
mypy==0.931
sphinx==7.1.2
sphinx-rtd-theme==2.0.0rc4
sphinx-autodoc-typehints==1.25.2
pytest==7.1.3
pytest-cov==4.1.0
readme-renderer==42.0
bleach==4.1.0 # transient dependency for readme-renderer
grpcio-tools==1.29.0
mypy-protobuf>=1.23
protobuf~=3.13
markupsafe>=2.0.1
codespell==2.1.0
requests==2.31.0
ruamel.yaml==0.17.21
flaky==3.7.0
9 changes: 3 additions & 6 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sphinx==4.5.0
sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints
sphinx==7.1.2
sphinx-rtd-theme==2.0.0rc4
sphinx-autodoc-typehints==1.25.2

# Need to install the api/sdk in the venv for autodoc. Modifying sys.path
# doesn't work for pkg_resources.
Expand Down Expand Up @@ -45,11 +45,8 @@ remoulade>=0.50
sqlalchemy>=1.0
tornado>=5.1.1
tortoise-orm>=0.17.0
ddtrace>=0.34.0
httpx>=0.18.0

# indirect dependency pins
markupsafe==2.0.1
itsdangerous==2.0.1

docutils==0.16
1 change: 1 addition & 0 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ packages=
[lintroots]
extraroots=examples/*,scripts/
subglob=*.py,tests/,test/,src/*,examples/*
ignore=sklearn

[testroots]
extraroots=examples/*,tests/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pytest

import opentelemetry.test.metrictestutil as metric_util

# pylint: disable=no-name-in-module
from opentelemetry.exporter.prometheus_remote_write import (
PrometheusRemoteWriteMetricsExporter,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

# pylint: disable=no-name-in-module
from opentelemetry.exporter.prometheus_remote_write import (
PrometheusRemoteWriteMetricsExporter,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ async def decorated_publish(
if not span:
return await publish(message, routing_key, **kwargs)
with trace.use_span(span, end_on_exit=True):
if span.is_recording():
propagate.inject(message.properties.headers)
propagate.inject(message.properties.headers)
return_value = await publish(message, routing_key, **kwargs)
return return_value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import asyncio
from typing import Type
from unittest import TestCase, mock, skipIf
from unittest.mock import MagicMock

from aio_pika import Exchange, RobustExchange

Expand Down Expand Up @@ -92,6 +93,36 @@ def test_publish(self):
def test_robust_publish(self):
self._test_publish(RobustExchange)

def _test_publish_works_with_not_recording_span(self, exchange_type):
exchange = exchange_type(CONNECTION_7, CHANNEL_7, EXCHANGE_NAME)
with mock.patch.object(
PublishDecorator, "_get_publish_span"
) as mock_get_publish_span:
mocked_not_recording_span = MagicMock()
mocked_not_recording_span.is_recording.return_value = False
mock_get_publish_span.return_value = mocked_not_recording_span
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch(
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
) as mock_inject:
decorated_publish = PublishDecorator(
self.tracer, exchange
).decorate(mock_publish)
self.loop.run_until_complete(
decorated_publish(MESSAGE, ROUTING_KEY)
)
mock_publish.assert_called_once()
mock_get_publish_span.assert_called_once()
mock_inject.assert_called_once()

def test_publish_works_with_not_recording_span(self):
self._test_publish_works_with_not_recording_span(Exchange)

def test_publish_works_with_not_recording_span_robust(self):
self._test_publish_works_with_not_recording_span(RobustExchange)


@skipIf(AIOPIKA_VERSION_INFO <= (8, 0), "Only for aio_pika 8")
class TestInstrumentedExchangeAioRmq8(TestCase):
Expand Down Expand Up @@ -144,3 +175,33 @@ def test_publish(self):

def test_robust_publish(self):
self._test_publish(RobustExchange)

def _test_publish_works_with_not_recording_span(self, exchange_type):
exchange = exchange_type(CONNECTION_7, CHANNEL_7, EXCHANGE_NAME)
with mock.patch.object(
PublishDecorator, "_get_publish_span"
) as mock_get_publish_span:
mocked_not_recording_span = MagicMock()
mocked_not_recording_span.is_recording.return_value = False
mock_get_publish_span.return_value = mocked_not_recording_span
with mock.patch.object(
Exchange, "publish", return_value=asyncio.sleep(0)
) as mock_publish:
with mock.patch(
"opentelemetry.instrumentation.aio_pika.publish_decorator.propagate.inject"
) as mock_inject:
decorated_publish = PublishDecorator(
self.tracer, exchange
).decorate(mock_publish)
self.loop.run_until_complete(
decorated_publish(MESSAGE, ROUTING_KEY)
)
mock_publish.assert_called_once()
mock_get_publish_span.assert_called_once()
mock_inject.assert_called_once()

def test_publish_works_with_not_recording_span(self):
self._test_publish_works_with_not_recording_span(Exchange)

def test_publish_works_with_not_recording_span_robust(self):
self._test_publish_works_with_not_recording_span(RobustExchange)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import asyncio
import contextlib
import sys
import typing
import unittest
import urllib.parse
Expand Down Expand Up @@ -116,14 +117,19 @@ def test_status_codes(self):
status_code=status_code,
)

url = f"http://{host}:{port}/test-path?query=param#foobar"
# if python version is < 3.8, then the url will be
if sys.version_info[1] < 8:
url = f"http://{host}:{port}/test-path#foobar"

self.assert_spans(
[
(
"GET",
(span_status, None),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path#foobar",
SpanAttributes.HTTP_URL: url,
SpanAttributes.HTTP_STATUS_CODE: int(
status_code
),
Expand All @@ -136,7 +142,7 @@ def test_status_codes(self):

def test_schema_url(self):
with self.subTest(status_code=200):
host, port = self._http_request(
self._http_request(
trace_config=aiohttp_client.create_trace_config(),
url="/test-path?query=param#foobar",
status_code=200,
Expand All @@ -156,7 +162,7 @@ def test_not_recording(self):
mock_tracer.start_span.return_value = mock_span
with mock.patch("opentelemetry.trace.get_tracer"):
# pylint: disable=W0612
host, port = self._http_request(
self._http_request(
trace_config=aiohttp_client.create_trace_config(),
url="/test-path?query=param#foobar",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
# limitations under the License.

import urllib
from timeit import default_timer
from typing import Dict, List, Tuple, Union

from aiohttp import web
from multidict import CIMultiDictProxy
from timeit import default_timer
from typing import Tuple, Dict, List, Union

from opentelemetry import context, trace, metrics
from opentelemetry import context, metrics, trace
from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.aiohttp_server.package import _instruments
from opentelemetry.instrumentation.aiohttp_server.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import http_status_to_status_code
from opentelemetry.propagators.textmap import Getter
from opentelemetry.propagate import extract
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.propagators.textmap import Getter
from opentelemetry.semconv.metrics import MetricInstruments
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.util.http import get_excluded_urls
from opentelemetry.util.http import remove_url_credentials
from opentelemetry.util.http import get_excluded_urls, remove_url_credentials

_duration_attrs = [
SpanAttributes.HTTP_METHOD,
Expand Down Expand Up @@ -127,7 +127,7 @@ def collect_request_attributes(request: web.Request) -> Dict:
result[SpanAttributes.HTTP_METHOD] = http_method

http_host_value_list = (
[request.host] if type(request.host) != list else request.host
[request.host] if not isinstance(request.host, list) else request.host
)
if http_host_value_list:
result[SpanAttributes.HTTP_SERVER_NAME] = ",".join(
Expand Down
Loading

0 comments on commit ffc043b

Please sign in to comment.