Skip to content

Commit

Permalink
Merge branch 'main' into bump-tornado-641
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Jun 14, 2024
2 parents 2aad4a4 + 91a69d4 commit 386593e
Show file tree
Hide file tree
Showing 21 changed files with 406 additions and 116 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- `opentelemetry-sdk-extension-aws` Add AwsXrayLambdaPropagator
([#2573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2573))

### Breaking changes

- `opentelemetry-instrumentation-asgi`, `opentelemetry-instrumentation-fastapi`, `opentelemetry-instrumentation-starlette` Use `tracer` and `meter` of originating components instead of one from `asgi` middleware
Expand All @@ -18,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2538](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2538))
- Add Python 3.12 support
([#2572](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2572))
- `opentelemetry-instrumentation-aiohttp-server`, `opentelemetry-instrumentation-httpx` Ensure consistently use of suppress_instrumentation utils
([#2590](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2590))

## Version 1.25.0/0.46b0 (2024-05-31)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.9.3
aiohttp==3.9.4
aiosignal==1.3.1
asgiref==3.7.2
async-timeout==4.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
from aiohttp import web
from multidict import CIMultiDictProxy

from opentelemetry import context, metrics, trace
from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
from opentelemetry import metrics, trace
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.instrumentation.utils import (
http_status_to_status_code,
is_http_instrumentation_enabled,
)
from opentelemetry.propagate import extract
from opentelemetry.propagators.textmap import Getter
from opentelemetry.semconv.metrics import MetricInstruments
Expand Down Expand Up @@ -191,10 +193,8 @@ def keys(self, carrier: Dict) -> List:
@web.middleware
async def middleware(request, handler):
"""Middleware for aiohttp implementing tracing logic"""
if (
context.get_value("suppress_instrumentation")
or context.get_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY)
or _excluded_urls.url_disabled(request.url.path)
if not is_http_instrumentation_enabled() or _excluded_urls.url_disabled(
request.url.path
):
return await handler(request)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.9.3
aiohttp==3.9.4
aiosignal==1.3.1
asgiref==3.7.2
async-timeout==4.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from opentelemetry.instrumentation.aiohttp_server import (
AioHttpServerInstrumentor,
)
from opentelemetry.instrumentation.utils import suppress_http_instrumentation
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.globals_test import reset_trace_globals
from opentelemetry.test.test_base import TestBase
Expand Down Expand Up @@ -64,16 +65,25 @@ async def default_handler(request, status=200):
return aiohttp.web.Response(status=status)


@pytest.fixture(name="suppress")
def fixture_suppress():
return False


@pytest_asyncio.fixture(name="server_fixture")
async def fixture_server_fixture(tracer, aiohttp_server):
async def fixture_server_fixture(tracer, aiohttp_server, suppress):
_, memory_exporter = tracer

AioHttpServerInstrumentor().instrument()

app = aiohttp.web.Application()
app.add_routes([aiohttp.web.get("/test-path", default_handler)])
if suppress:
with suppress_http_instrumentation():
server = await aiohttp_server(app)
else:
server = await aiohttp_server(app)

server = await aiohttp_server(app)
yield server, app

memory_exporter.clear()
Expand Down Expand Up @@ -128,3 +138,18 @@ async def test_status_code_instrumentation(
f"http://{server.host}:{server.port}{url}"
== span.attributes[SpanAttributes.HTTP_URL]
)


@pytest.mark.asyncio
@pytest.mark.parametrize("suppress", [True])
async def test_suppress_instrumentation(
tracer, server_fixture, aiohttp_client
):
_, memory_exporter = tracer
server, _ = server_fixture
assert len(memory_exporter.get_finished_spans()) == 0

client = await aiohttp_client(server)
await client.get("/test-path")

assert len(memory_exporter.get_finished_spans()) == 0
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ importlib-metadata==6.11.0
iniconfig==2.0.0
Jinja2==3.1.4
jmespath==1.0.1
MarkupSafe==2.0.1
moto==3.1.19
MarkupSafe==2.1.5
moto==5.0.9
packaging==24.0
pluggy==1.5.0
py-cpuinfo==9.0.0
Expand All @@ -31,7 +31,7 @@ six==1.16.0
tomli==2.0.1
typing_extensions==4.9.0
urllib3==1.26.18
Werkzeug==2.1.2
Werkzeug==3.0.3
wrapt==1.16.0
xmltodict==0.13.0
zipp==3.17.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from unittest import mock

import botocore.session
from moto import mock_dynamodb2 # pylint: disable=import-error
from moto import mock_aws # pylint: disable=import-error

from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
from opentelemetry.instrumentation.botocore.extensions.dynamodb import (
Expand Down Expand Up @@ -184,7 +184,7 @@ def assert_extension_item_col_metrics(self, operation: str):
)
self.assert_item_col_metrics(span)

@mock_dynamodb2
@mock_aws
def test_batch_get_item(self):
table_name1 = "test_table1"
table_name2 = "test_table2"
Expand All @@ -203,7 +203,7 @@ def test_batch_get_item(self):
self.assert_table_names(span, table_name1, table_name2)
self.assert_consumed_capacity(span, table_name1, table_name2)

@mock_dynamodb2
@mock_aws
def test_batch_write_item(self):
table_name1 = "test_table1"
table_name2 = "test_table2"
Expand All @@ -224,7 +224,7 @@ def test_batch_write_item(self):
self.assert_consumed_capacity(span, table_name1, table_name2)
self.assert_item_col_metrics(span)

@mock_dynamodb2
@mock_aws
def test_create_table(self):
local_sec_idx = {
"IndexName": "local_sec_idx",
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_create_table(self):
)
self.assert_provisioned_read_cap(span, 42)

@mock_dynamodb2
@mock_aws
def test_delete_item(self):
self._create_prepared_table()

Expand Down Expand Up @@ -297,7 +297,7 @@ def test_delete_item_consumed_capacity(self):
def test_delete_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("DeleteItem")

@mock_dynamodb2
@mock_aws
def test_delete_table(self):
self._create_prepared_table()

Expand All @@ -306,7 +306,7 @@ def test_delete_table(self):
span = self.assert_span("DeleteTable")
self.assert_table_names(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_describe_table(self):
self._create_prepared_table()

Expand All @@ -315,15 +315,31 @@ def test_describe_table(self):
span = self.assert_span("DescribeTable")
self.assert_table_names(span, self.default_table_name)

@mock_dynamodb2
def test_get_item(self):
@mock_aws
def test_get_item_expression(self):
self._create_prepared_table()

self.client.get_item(
TableName=self.default_table_name,
Key={"id": {"S": "1"}},
ConsistentRead=True,
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_consumed_capacity(span, self.default_table_name)

@mock_aws
def test_get_item_non_expression(self):
self._create_prepared_table()

self.client.get_item(
TableName=self.default_table_name,
Key={"id": {"S": "1"}},
ConsistentRead=True,
AttributesToGet=["id"],
ProjectionExpression="PE",
ReturnConsumedCapacity="TOTAL",
)
Expand All @@ -334,7 +350,7 @@ def test_get_item(self):
self.assert_projection(span, "PE")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_list_tables(self):
self._create_table(TableName="my_table")
self._create_prepared_table()
Expand All @@ -351,7 +367,7 @@ def test_list_tables(self):
)
self.assertEqual(5, span.attributes[SpanAttributes.AWS_DYNAMODB_LIMIT])

@mock_dynamodb2
@mock_aws
def test_put_item(self):
table = "test_table"
self._create_prepared_table(TableName=table)
Expand All @@ -372,7 +388,7 @@ def test_put_item(self):
def test_put_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("PutItem")

@mock_dynamodb2
@mock_aws
def test_query(self):
self._create_prepared_table()

Expand Down Expand Up @@ -407,7 +423,7 @@ def test_query(self):
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_scan(self):
self._create_prepared_table()

Expand Down Expand Up @@ -444,7 +460,7 @@ def test_scan(self):
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_update_item(self):
self._create_prepared_table()

Expand All @@ -465,7 +481,7 @@ def test_update_item(self):
def test_update_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("UpdateItem")

@mock_dynamodb2
@mock_aws
def test_update_table(self):
self._create_prepared_table()

Expand Down
Loading

0 comments on commit 386593e

Please sign in to comment.