diff --git a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md index aa3775a925d0..d51f4ac4db8a 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.8.10 (Unreleased) ### Features Added +- Add support for the `httpx2` OpenTelemetry instrumentation entry point + ([#48899](https://github.com/Azure/azure-sdk-for-python/pull/48899)) - Add httpx instrumentation support ([#47953](https://github.com/Azure/azure-sdk-for-python/pull/47953)) diff --git a/sdk/monitor/azure-monitor-opentelemetry/README.md b/sdk/monitor/azure-monitor-opentelemetry/README.md index ee2a93fed322..380a345e586e 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/README.md +++ b/sdk/monitor/azure-monitor-opentelemetry/README.md @@ -19,7 +19,7 @@ OpenTelemetry instrumentations allow automatic collection of requests sent from | [OpenTelemetry Django Instrumentation][ot_instrumentation_django] | [django][pypi_django] | [link][ot_instrumentation_django_version] | [OpenTelemetry FastApi Instrumentation][ot_instrumentation_fastapi] | [fastapi][pypi_fastapi] | [link][ot_instrumentation_fastapi_version] | [OpenTelemetry Flask Instrumentation][ot_instrumentation_flask] | [flask][pypi_flask] | [link][ot_instrumentation_flask_version] -| [OpenTelemetry Httpx Instrumentation][ot_instrumentation_httpx] | [httpx][pypi_httpx] | [link][ot_instrumentation_httpx_version] +| [OpenTelemetry Httpx Instrumentation][ot_instrumentation_httpx] | [httpx][pypi_httpx], [httpx2][pypi_httpx2] | [link][ot_instrumentation_httpx_version] | [OpenTelemetry Psycopg2 Instrumentation][ot_instrumentation_psycopg2] | [psycopg2][pypi_psycopg2] | [link][ot_instrumentation_psycopg2_version] | [OpenTelemetry Requests Instrumentation][ot_instrumentation_requests] | [requests][pypi_requests] | [link][ot_instrumentation_requests_version] | [OpenTelemetry UrlLib Instrumentation][ot_instrumentation_urllib] | [urllib][pypi_urllib] | All @@ -264,6 +264,7 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [pypi_fastapi]: https://pypi.org/project/fastapi/ [pypi_flask]: https://pypi.org/project/Flask/ [pypi_httpx]: https://pypi.org/project/httpx/ +[pypi_httpx2]: https://pypi.org/project/httpx2/ [pypi_psycopg2]: https://pypi.org/project/psycopg2/ [pypi_requests]: https://pypi.org/project/requests/ [pypi_urllib]: https://docs.python.org/3/library/urllib.html diff --git a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py index dde291d442dd..f80d7a5ff4f4 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py +++ b/sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_constants.py @@ -79,6 +79,7 @@ "fastapi", "flask", "httpx", + "httpx2", "psycopg2", "requests", "urllib", diff --git a/sdk/monitor/azure-monitor-opentelemetry/dev_requirements.txt b/sdk/monitor/azure-monitor-opentelemetry/dev_requirements.txt index a04a4e50aa62..5fcfcaa1b3d2 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/dev_requirements.txt +++ b/sdk/monitor/azure-monitor-opentelemetry/dev_requirements.txt @@ -7,4 +7,5 @@ psycopg2-binary requests urllib3 httpx +httpx2 brotli diff --git a/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/instrumentation_options.py b/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/instrumentation_options.py index db5cff77dc8d..e4dc52830ebc 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/instrumentation_options.py +++ b/sdk/monitor/azure-monitor-opentelemetry/samples/tracing/instrumentation_options.py @@ -18,5 +18,6 @@ "urllib": {"enabled": False}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, } ) diff --git a/sdk/monitor/azure-monitor-opentelemetry/tests/instrumentation/test_httpx.py b/sdk/monitor/azure-monitor-opentelemetry/tests/instrumentation/test_httpx.py index cc74c0ea5d09..b9627ce90387 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/tests/instrumentation/test_httpx.py +++ b/sdk/monitor/azure-monitor-opentelemetry/tests/instrumentation/test_httpx.py @@ -8,13 +8,18 @@ from opentelemetry.instrumentation.httpx import ( HTTPXClientInstrumentor, + HTTPX2ClientInstrumentor, ) class TestHttpxInstrumentation(unittest.TestCase): def test_instrument(self): + self._instrument(HTTPXClientInstrumentor) + self._instrument(HTTPX2ClientInstrumentor) + + def _instrument(self, instrumentor): try: - HTTPXClientInstrumentor().instrument() + instrumentor().instrument() except Exception as ex: # pylint: disable=broad-except print(ex) - self.fail(f"Unexpected exception raised when instrumenting {HTTPXClientInstrumentor.__name__}") + self.fail(f"Unexpected exception raised when instrumenting {instrumentor.__name__}") diff --git a/sdk/monitor/azure-monitor-opentelemetry/tests/utils/test_configurations.py b/sdk/monitor/azure-monitor-opentelemetry/tests/utils/test_configurations.py index fab94569b51a..df02dde648ae 100644 --- a/sdk/monitor/azure-monitor-opentelemetry/tests/utils/test_configurations.py +++ b/sdk/monitor/azure-monitor-opentelemetry/tests/utils/test_configurations.py @@ -112,6 +112,7 @@ def test_get_configurations(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, "previewlib1": {"enabled": False}, "previewlib2": {"enabled": False}, }, @@ -147,6 +148,7 @@ def test_get_configurations_defaults(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -196,6 +198,7 @@ def test_get_configurations_env_vars(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -280,6 +283,7 @@ def test_merge_instrumentation_options_conflict(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": False}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) @@ -315,6 +319,7 @@ def test_merge_instrumentation_options_extra_args(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) @@ -461,6 +466,7 @@ def test_get_configurations_env_vars_rate_limited(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -489,6 +495,7 @@ def test_get_configurations_rate_limited_sampler_param(self, resource_create_moc "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -528,6 +535,7 @@ def test_get_configurations_env_vars_no_preference(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -567,6 +575,7 @@ def test_get_configurations_env_vars_check_default(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -607,6 +616,7 @@ def test_get_configurations_env_vars_fixed_percentage(self, resource_create_mock "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes) @@ -646,6 +656,7 @@ def test_get_configurations_env_vars_always_on(self, resource_create_mock): "urllib": {"enabled": True}, "urllib3": {"enabled": True}, "httpx": {"enabled": True}, + "httpx2": {"enabled": True}, }, ) self.assertEqual(configurations["resource"].attributes, TEST_DEFAULT_RESOURCE.attributes)