Skip to content

Commit

Permalink
Merge branch 'main' into feature/http-route-in-metric
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzaloGuasch authored Jul 11, 2024
2 parents b83d7ed + 43dfc73 commit edd0ad7
Show file tree
Hide file tree
Showing 95 changed files with 173 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/instrumentations_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ jobs:
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run pytest without --benchmark-skip
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra
5 changes: 3 additions & 2 deletions .github/workflows/instrumentations_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ jobs:
matrix:
python-version: [py38, py39, py310, py311, py312, pypy3]
package:
# Only add here packages that do not have benchmark tests
- "urllib"
- "urllib3"
- "wsgi"
- "distro"
- "richconsole"
- "psycopg"
- "prometheus-remote-write"
- "sdk-extension-aws"
- "propagator-aws-xray"
- "propagator-ot-trace"
- "resource-detector-azure"
- "resource-detector-container"
Expand All @@ -58,5 +59,5 @@ jobs:
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
- name: run pytest without --benchmark-skip
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra
50 changes: 0 additions & 50 deletions .github/workflows/instrumentations_2.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ _build/
# mypy
.mypy_cache/
target

# Benchmark result files
*-benchmark.json
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2501](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2501))
- `opentelemetry-instrumentation-confluent-kafka` Add support for produce purge
([#2638](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2638))
- `opentelemetry-instrumentation-asgi` Implement new semantic convention opt-in with stable http semantic conventions
([#2610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2610))
- `opentelemetry-instrumentation-httpx` Implement new semantic convention opt-in migration with stable http semantic conventions
([#2631](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2631))
- `opentelemetry-instrumentation-system-metrics` Permit to use psutil 6.0+.
Expand All @@ -42,10 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Populate `{method}` as `HTTP` on `_OTHER` methods from scope
([#2610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2610))

### Added

- `opentelemetry-instrumentation-asgi` Implement new semantic convention opt-in with stable http semantic conventions
([#2610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2610))

### Fixed

Expand Down
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ for more detail on available tox commands.
### 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.

Running the `tox` tests also runs the performance tests if any are available. Benchmarking tests are done with `pytest-benchmark` and they output a table with results to the console.
Some packages have benchmark tests. To run them, run `tox -f benchmark`. Benchmark tests use `pytest-benchmark` and they output a table with results to the console.

To write benchmarks, simply use the [pytest benchmark fixture](https://pytest-benchmark.readthedocs.io/en/latest/usage.html#usage) like the following:

Expand All @@ -114,10 +112,10 @@ def test_simple_start_span(benchmark):
benchmark(benchmark_start_as_current_span, "benchmarkedSpan", 42)
```

Make sure the test file is under the `tests/performance/benchmarks/` folder of
Make sure the test file is under the `benchmarks/` folder of
the package it is benchmarking and further has a path that corresponds to the
file in the package it is testing. Make sure that the file name begins with
`test_benchmark_`. (e.g. `propagator/opentelemetry-propagator-aws-xray/tests/performance/benchmarks/trace/propagation/test_benchmark_aws_xray_propagator.py`)
`test_benchmark_`. (e.g. `propagator/opentelemetry-propagator-aws-xray/benchmarks/trace/propagation/test_benchmark_aws_xray_propagator.py`)

## Pull Requests

Expand Down Expand Up @@ -271,6 +269,9 @@ Below is a checklist of things to be mindful of when implementing a new instrume
- ex. <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2518a4ac07cb62ad6587dd8f6cbb5f8663a7e179/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py#L234>
- Appropriate error handling
- ex. <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2518a4ac07cb62ad6587dd8f6cbb5f8663a7e179/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py#L220>
- Isolate sync and async test
- For synchronous tests, the typical test case class is inherited from `opentelemetry.test.test_base.TestBase`. However, if you want to write asynchronous tests, the test case class should inherit also from `IsolatedAsyncioTestCase`. Adding asynchronous tests to a common test class can lead to tests passing without actually running, which can be misleading.
- ex. <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/60fb936b7e5371b3e5587074906c49fb873cbd76/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py#L84>

## Expectations from contributors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
asgiref==3.7.2
certifi==2024.2.2
charset-normalizer==3.3.2
cramjam==2.8.1
# We can drop this after bumping baseline to pypy-39
cramjam==2.1.0; platform_python_implementation == "PyPy"
cramjam==2.8.1; platform_python_implementation != "PyPy"
Deprecated==1.2.14
idna==3.7
importlib-metadata==6.11.0
Expand All @@ -17,5 +19,5 @@ tomli==2.0.1
typing_extensions==4.10.0
urllib3==2.2.2
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e exporter/opentelemetry-exporter-prometheus-remote-write
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ rich==13.7.1
tomli==2.0.1
typing_extensions==4.10.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e exporter/opentelemetry-exporter-richconsole
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aio-pika
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aio-pika
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aio-pika
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-aio-pika
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ aiosignal==1.3.1
asgiref==3.7.2
async-timeout==4.0.3
blinker==1.7.0
certifi==2024.2.2
certifi==2024.7.4
charset-normalizer==3.3.2
click==8.1.7
Deprecated==1.2.14
Expand All @@ -28,7 +28,7 @@ urllib3==2.2.2
Werkzeug==3.0.3
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e util/opentelemetry-util-http
-e instrumentation/opentelemetry-instrumentation-aiohttp-client
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tomli==2.0.1
typing_extensions==4.10.0
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e util/opentelemetry-util-http
-e instrumentation/opentelemetry-instrumentation-aiohttp-server
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pytest==7.4.4
tomli==2.0.1
typing_extensions==4.10.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-dbapi
-e instrumentation/opentelemetry-instrumentation-aiopg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest==7.4.4
tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e util/opentelemetry-util-http
-e instrumentation/opentelemetry-instrumentation-asgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pytest-asyncio==0.23.5
tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-asyncio
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import sys
from unittest import skipIf
from unittest.mock import patch

# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -41,6 +43,9 @@ def tearDown(self):

# Asyncio anext() does not have __name__ attribute, which is used to determine if the coroutine should be traced.
# This test is to ensure that the instrumentation does not break when the coroutine does not have __name__ attribute.
@skipIf(
sys.version_info < (3, 10), "anext is only available in Python 3.10+"
)
def test_asyncio_anext(self):
async def main():
async def async_gen():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def tearDown(self):

def test_cancel(self):
with self._tracer.start_as_current_span("root", kind=SpanKind.SERVER):
asyncio.run(cancellation_create_task())
try:
asyncio.run(cancellation_create_task())
except asyncio.CancelledError:
pass
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 3)
self.assertEqual(spans[0].context.trace_id, spans[1].context.trace_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import asyncio
import sys
from unittest import skipIf
from unittest.mock import patch

# pylint: disable=no-name-in-module
Expand All @@ -25,10 +26,6 @@

from .common_test_func import async_func

py11 = False
if sys.version_info >= (3, 11):
py11 = True


class TestAsyncioTaskgroup(TestBase):
@patch.dict(
Expand All @@ -46,11 +43,11 @@ def tearDown(self):
super().tearDown()
AsyncioInstrumentor().uninstrument()

@skipIf(
sys.version_info < (3, 11),
"TaskGroup is only available in Python 3.11+",
)
def test_task_group_create_task(self):
# TaskGroup is only available in Python 3.11+
if not py11:
return

async def main():
async with asyncio.TaskGroup() as tg: # pylint: disable=no-member
for _ in range(10):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import asyncio
import sys
from unittest import skipIf
from unittest.mock import patch

# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -40,34 +41,34 @@ def tearDown(self):
super().tearDown()
AsyncioInstrumentor().uninstrument()

@skipIf(
sys.version_info < (3, 9), "to_thread is only available in Python 3.9+"
)
def test_to_thread(self):
# to_thread is only available in Python 3.9+
if sys.version_info >= (3, 9):

def multiply(x, y):
return x * y
def multiply(x, y):
return x * y

async def to_thread():
result = await asyncio.to_thread(multiply, 2, 3)
assert result == 6
async def to_thread():
result = await asyncio.to_thread(multiply, 2, 3)
assert result == 6

with self._tracer.start_as_current_span("root"):
asyncio.run(to_thread())
spans = self.memory_exporter.get_finished_spans()
with self._tracer.start_as_current_span("root"):
asyncio.run(to_thread())
spans = self.memory_exporter.get_finished_spans()

self.assertEqual(len(spans), 2)
assert spans[0].name == "asyncio to_thread-multiply"
for metric in (
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics
):
if metric.name == "asyncio.process.duration":
for point in metric.data.data_points:
self.assertEqual(point.attributes["type"], "to_thread")
self.assertEqual(point.attributes["name"], "multiply")
if metric.name == "asyncio.process.created":
for point in metric.data.data_points:
self.assertEqual(point.attributes["type"], "to_thread")
self.assertEqual(point.attributes["name"], "multiply")
self.assertEqual(len(spans), 2)
assert spans[0].name == "asyncio to_thread-multiply"
for metric in (
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics
):
if metric.name == "asyncio.process.duration":
for point in metric.data.data_points:
self.assertEqual(point.attributes["type"], "to_thread")
self.assertEqual(point.attributes["name"], "multiply")
if metric.name == "asyncio.process.created":
for point in metric.data.data_points:
self.assertEqual(point.attributes["type"], "to_thread")
self.assertEqual(point.attributes["name"], "multiply")
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pytest==7.4.4
tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-asyncpg
Loading

0 comments on commit edd0ad7

Please sign in to comment.