Skip to content

Commit

Permalink
Merge branch 'main' into add_confluent_kafka_producer_returns
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored May 24, 2024
2 parents 967233e + 65b4f85 commit d939628
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception".
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-dbapi` Fix compatibility with Psycopg3 to extract libpq build version (#2500)[https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2500]
- `opentelemetry-instrumentation-grpc` AioClientInterceptor should propagate with a Metadata object
([#2363](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2363))
- `opentelemetry-instrumentation-boto3sqs` Instrument Session and resource
Expand All @@ -56,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2420](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2420))
- `opentelemetry-instrumentation-asyncio` Check for __name__ attribute in the coroutine
([#2521](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2521))
- `opentelemetry-util-http` Preserve brackets around literal IPv6 hosts ([#2552](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2552))

## Version 1.24.0/0.45b0 (2024-03-28)

Expand Down Expand Up @@ -1541,4 +1543,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-resource-detector-azure` Suppress instrumentation for `urllib` call
([#2178](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2178))
- AwsLambdaInstrumentor handles and re-raises function exception ([#2245](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2245))

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from unittest.mock import MagicMock

import aiopg
import psycopg2

import opentelemetry.instrumentation.aiopg
from opentelemetry import trace as trace_api
Expand Down Expand Up @@ -384,7 +385,9 @@ def test_span_failed(self):
span.attributes[SpanAttributes.DB_STATEMENT], "Test query"
)
self.assertIs(span.status.status_code, trace_api.StatusCode.ERROR)
self.assertEqual(span.status.description, "Exception: Test Exception")
self.assertEqual(
span.status.description, "ProgrammingError: Test Exception"
)

def test_executemany(self):
db_integration = AiopgIntegration(self.tracer, "testcomponent")
Expand Down Expand Up @@ -570,17 +573,17 @@ class MockCursor:
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg2.ProgrammingError("Test Exception")

def close(self):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def trace_item(self, coro_or_future):

async def trace_coroutine(self, coro):
if not hasattr(coro, "__name__"):
return
return coro
start = default_timer()
attr = {
"type": "coroutine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ def rest_api_handler(event, context):


def handler_exc(event, context):
# pylint: disable=broad-exception-raised
raise Exception("500 internal server error")
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonschema==4.21.1
jsonschema-specifications==2023.12.1
junit-xml==1.9
MarkupSafe==2.0.1
moto==2.2.20
moto==3.1.19
mpmath==1.3.0
networkx==3.1
packaging==23.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ def test_get_item(self):
Key={"id": {"S": "1"}},
ConsistentRead=True,
AttributesToGet=["id"],
ProjectionExpression="1,2",
ProjectionExpression="PE",
ReturnConsumedCapacity="TOTAL",
)

span = self.assert_span("GetItem")
self.assert_table_names(span, self.default_table_name)
self.assert_consistent_read(span, True)
self.assert_projection(span, "1,2")
self.assert_projection(span, "PE")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_query(self):
}
},
ScanIndexForward=True,
ProjectionExpression="1,2",
ProjectionExpression="PE",
ReturnConsumedCapacity="TOTAL",
)

Expand All @@ -403,7 +403,7 @@ def test_query(self):
self.assert_consistent_read(span, True)
self.assert_index_name(span, "lsi")
self.assert_limit(span, 42)
self.assert_projection(span, "1,2")
self.assert_projection(span, "PE")
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

Expand All @@ -419,7 +419,7 @@ def test_scan(self):
Select="ALL_ATTRIBUTES",
TotalSegments=17,
Segment=21,
ProjectionExpression="1,2",
ProjectionExpression="PE",
ConsistentRead=True,
ReturnConsumedCapacity="TOTAL",
)
Expand All @@ -440,7 +440,7 @@ def test_scan(self):
self.assert_consistent_read(span, True)
self.assert_index_name(span, "lsi")
self.assert_limit(span, 42)
self.assert_projection(span, "1,2")
self.assert_projection(span, "PE")
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,19 @@ def traced_execution(
if args and self._commenter_enabled:
try:
args_list = list(args)
if hasattr(self._connect_module, "__libpq_version__"):
libpq_version = self._connect_module.__libpq_version__
else:
libpq_version = (
self._connect_module.pq.__build_version__
)

commenter_data = {
# Psycopg2/framework information
"db_driver": f"psycopg2:{self._connect_module.__version__.split(' ')[0]}",
"dbapi_threadsafety": self._connect_module.threadsafety,
"dbapi_level": self._connect_module.apilevel,
"libpq_version": self._connect_module.__libpq_version__,
"libpq_version": libpq_version,
"driver_paramstyle": self._connect_module.paramstyle,
}
if self._commenter_options.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ def test_executemany_comment(self):
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_compatible_build_version_psycopg_psycopg2_libpq(self):
connect_module = mock.MagicMock()
connect_module.__version__ = mock.MagicMock()
connect_module.pq = mock.MagicMock()
connect_module.pq.__build_version__ = 123
connect_module.apilevel = 123
connect_module.threadsafety = 123
connect_module.paramstyle = "test"

db_integration = dbapi.DatabaseApiIntegration(
"testname",
"testcomponent",
enable_commenter=True,
commenter_options={"db_driver": False, "dbapi_level": False},
connect_module=connect_module,
)
mock_connection = db_integration.wrapped_connection(
mock_connect, {}, {}
)
cursor = mock_connection.cursor()
cursor.executemany("Select 1;")
self.assertRegex(
cursor.query,
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_executemany_flask_integration_comment(self):
connect_module = mock.MagicMock()
connect_module.__version__ = mock.MagicMock()
Expand Down Expand Up @@ -393,16 +419,19 @@ def __init__(self) -> None:
# pylint: disable=unused-argument, no-self-use
def execute(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")

# pylint: disable=unused-argument, no-self-use
def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
self.query = query
self.params = params

# pylint: disable=unused-argument, no-self-use
def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
# pylint: disable=broad-exception-raised
raise Exception("Test Exception")
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def response_hook(span, response):


def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def response_hook(span, response):


def request_hook_with_exception(_span, _request):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


def response_hook_with_exception(_span, _response):
raise Exception()
raise Exception() # pylint: disable=broad-exception-raised


class TestHooks(TestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_decorate_deque_proxy(
self.assertEqual(res, evt)
generator_info.pending_events.popleft.assert_called_once()
extract.assert_not_called()
context_get_current.not_called()
context_get_current.assert_not_called()
context_detach.assert_called_once()
context_attach.assert_not_called()
get_span.assert_not_called()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def __init__(self, *args, **kwargs):
# pylint: disable=unused-argument, no-self-use
async def execute(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def executemany(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

# pylint: disable=unused-argument, no-self-use
async def callproc(self, query, params=None, throw_exception=False):
if throw_exception:
raise Exception("Test Exception")
raise psycopg.Error("Test Exception")

async def __aenter__(self, *args, **kwargs):
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def timeout_exception_callback(*_, **__):

@staticmethod
def base_exception_callback(*_, **__):
raise Exception("test")
raise Exception("test") # pylint: disable=broad-exception-raised

def assert_span(self, exporter=None, num_spans=1):
if exporter is None:
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1198,15 +1198,15 @@ deps =
-r dev-requirements.txt

commands =
black --config {toxinidir}/pyproject.toml {{toxinidir}} --diff --check
isort --settings-path {toxinidir}/.isort.cfg {{toxinidir}} --diff --check-only
black --config {toxinidir}/pyproject.toml {toxinidir} --diff --check
isort --settings-path {toxinidir}/.isort.cfg {toxinidir} --diff --check-only
flake8 --config {toxinidir}/.flake8 {toxinidir}

[testenv:spellcheck]
basepython: python3
recreate = True
deps =
codespell
codespell==2.2.6

commands =
codespell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ def remove_url_credentials(url: str) -> str:
parsed = urlparse(url)
if all([parsed.scheme, parsed.netloc]): # checks for valid url
parsed_url = urlparse(url)
netloc = (
(":".join(((parsed_url.hostname or ""), str(parsed_url.port))))
if parsed_url.port
else (parsed_url.hostname or "")
)
_, _, netloc = parsed.netloc.rpartition("@")
return urlunparse(
(
parsed_url.scheme,
Expand Down
27 changes: 27 additions & 0 deletions util/opentelemetry-util-http/tests/test_remove_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from opentelemetry.util.http import remove_url_credentials


class TestRemoveUrlCredentials(unittest.TestCase):
def test_remove_no_credentials(self):
url = "http://opentelemetry.io:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, url)

def test_remove_credentials(self):
url = "http://someuser:[email protected]:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(
cleaned_url, "http://opentelemetry.io:8080/test/path?query=value"
)

def test_remove_credentials_ipv4_literal(self):
url = "http://someuser:[email protected]:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, "http://127.0.0.1:8080/test/path?query=value")

def test_remove_credentials_ipv6_literal(self):
url = "http://someuser:somepass@[::1]:8080/test/path?query=value"
cleaned_url = remove_url_credentials(url)
self.assertEqual(cleaned_url, "http://[::1]:8080/test/path?query=value")

0 comments on commit d939628

Please sign in to comment.