From d6c6a158b580030cac6f7c370b71b6eca6cf1ed8 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 21 Feb 2022 17:03:39 +0530 Subject: [PATCH 01/13] Added configuration for sqlcommenter --- .../src/opentelemetry/instrumentation/psycopg2/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py index e338902e1b..8cace040ef 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py @@ -76,7 +76,7 @@ def _instrument(self, **kwargs): Psycopg: http://initd.org/psycopg/ """ tracer_provider = kwargs.get("tracer_provider") - + enable_sqlcommenter = kwargs.get("enable_commenter", False) dbapi.wrap_connect( __name__, psycopg2, @@ -86,6 +86,7 @@ def _instrument(self, **kwargs): version=__version__, tracer_provider=tracer_provider, db_api_integration_factory=DatabaseApiIntegration, + enable_commenter=enable_sqlcommenter ) def _uninstrument(self, **kwargs): From b9026584016d8166cea77f1ac76ff5340a10947f Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Wed, 2 Mar 2022 15:49:36 +0530 Subject: [PATCH 02/13] Fixed linting errors --- .../src/opentelemetry/instrumentation/psycopg2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py index 8cace040ef..4b7ff23ea6 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py @@ -86,7 +86,7 @@ def _instrument(self, **kwargs): version=__version__, tracer_provider=tracer_provider, db_api_integration_factory=DatabaseApiIntegration, - enable_commenter=enable_sqlcommenter + enable_commenter=enable_sqlcommenter, ) def _uninstrument(self, **kwargs): From e878f0a4c60844a02e811b4156cbd2edcc148053 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Wed, 2 Mar 2022 18:02:18 +0530 Subject: [PATCH 03/13] Updated CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236a3de288..daa4d49e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.9.1-0.28b1...HEAD) ### Added - +- `opentelemetry-instrumentation-psycopg2` extended the sql commenter support of dbapi into psycopg2 + ([#940](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/940)) - `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability ([#908](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/908)) From bd8f208133b53e74823a8e9565c4f6164de9435f Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Fri, 11 Mar 2022 18:06:44 +0530 Subject: [PATCH 04/13] Unit test case for sqlcommenter in psycopg2 --- .../tests/test_psycopg2_integration.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index d20cc41348..2cce3ef8cd 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -224,3 +224,23 @@ def test_uninstrument_connection_with_instrument_connection(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) + + @mock.patch('opentelemetry.instrumentation.dbapi.wrap_connect') + def test_sqlcommenter_enabled(self, event_mocked): + cnx = psycopg2.connect(database="test") + Psycopg2Instrumentor().instrument(enable_commenter=True) + query = "SELECT * FROM test" + cursor = cnx.cursor() + cursor.execute(query) + args, kwargs = event_mocked.call_args + self.assertEqual(kwargs['enable_commenter'], True) + + @mock.patch('opentelemetry.instrumentation.dbapi.wrap_connect') + def test_sqlcommenter_disabled(self, event_mocked): + cnx = psycopg2.connect(database="test") + Psycopg2Instrumentor().instrument() + query = "SELECT * FROM test" + cursor = cnx.cursor() + cursor.execute(query) + args, kwargs = event_mocked.call_args + self.assertEqual(kwargs['enable_commenter'], False) From 145e1bf8033d3011497a4eb4fe015e76f17b6376 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Fri, 11 Mar 2022 18:24:14 +0530 Subject: [PATCH 05/13] Merge conflict resolved --- .github/workflows/test.yml | 2 +- README.md | 2 +- _template/version.py | 2 +- eachdist.ini | 4 +- .../opentelemetry-exporter-datadog/README.rst | 7 +- .../opentelemetry-exporter-datadog/setup.cfg | 2 +- .../opentelemetry/exporter/datadog/version.py | 2 +- .../setup.cfg | 2 +- .../exporter/richconsole/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/aiohttp_client/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/aiopg/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/asgi/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/asyncpg/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/aws_lambda/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/boto/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/botocore/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/celery/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/dbapi/version.py | 2 +- .../setup.cfg | 12 +- .../instrumentation/django/middleware.py | 2 +- .../instrumentation/django/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/elasticsearch/version.py | 2 +- .../setup.cfg | 10 +- .../instrumentation/falcon/version.py | 2 +- .../setup.cfg | 10 +- .../instrumentation/fastapi/version.py | 2 +- .../setup.cfg | 10 +- .../instrumentation/flask/__init__.py | 8 + .../instrumentation/flask/version.py | 2 +- .../tests/base_test.py | 14 ++ .../tests/test_programmatic.py | 98 +++++++++++ .../setup.cfg | 6 +- .../instrumentation/grpc/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/httpx/version.py | 2 +- .../setup.cfg | 4 +- .../instrumentation/jinja2/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/kafka/version.py | 2 +- .../setup.cfg | 4 +- .../instrumentation/logging/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/mysql/version.py | 2 +- .../setup.cfg | 2 +- .../instrumentation/pika/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/psycopg2/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/pymemcache/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/pymongo/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/pymysql/version.py | 2 +- .../setup.cfg | 10 +- .../instrumentation/pyramid/callbacks.py | 2 +- .../instrumentation/pyramid/version.py | 2 +- .../setup.cfg | 6 +- .../instrumentation/redis/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/requests/__init__.py | 10 +- .../instrumentation/requests/version.py | 2 +- .../setup.cfg | 4 +- .../instrumentation/sklearn/version.py | 2 +- .../setup.cfg | 4 +- .../instrumentation/sqlalchemy/__init__.py | 1 + .../instrumentation/sqlalchemy/engine.py | 24 ++- .../instrumentation/sqlalchemy/version.py | 2 +- .../tests/test_sqlalchemy.py | 25 +++ .../tests/test_sqlcommenter.py | 53 ++++++ .../setup.cfg | 6 +- .../instrumentation/sqlite3/version.py | 2 +- .../setup.cfg | 10 +- .../instrumentation/starlette/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/tornado/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/urllib/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/urllib3/version.py | 2 +- .../setup.cfg | 8 +- .../instrumentation/wsgi/__init__.py | 51 +++++- .../instrumentation/wsgi/version.py | 2 +- .../tests/test_wsgi_middleware.py | 154 ++++++++++++++++++ opentelemetry-distro/setup.cfg | 6 +- .../src/opentelemetry/distro/version.py | 2 +- .../instrumentation/bootstrap_gen.py | 72 ++++---- .../opentelemetry/instrumentation/utils.py | 13 +- .../opentelemetry/instrumentation/version.py | 2 +- .../propagators/ot_trace/version.py | 2 +- .../tests/postgres/test_psycopg_functional.py | 26 +++ .../src/opentelemetry/util/http/__init__.py | 29 +++- .../src/opentelemetry/util/http/version.py | 2 +- .../tests/test_capture_custom_headers.py | 67 ++++++++ 103 files changed, 781 insertions(+), 223 deletions(-) create mode 100644 instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py create mode 100644 util/opentelemetry-util-http/tests/test_capture_custom_headers.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b29e330d8d..2235798121 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 523257d9e13273abf21d03fc92b33cae02816216 + CORE_REPO_SHA: eb98182acc54faeffc7440f9fbce8e71b4575fcc jobs: build: diff --git a/README.md b/README.md index cb274eb4b7..970b12b3d5 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telem - [Aaron Abbott](https://github.com/aabmass), Google - [Alex Boten](https://github.com/codeboten), Lightstep - [Nathaniel Ruiz Nowell](https://github.com/NathanielRN), AWS +- [Owais Lone](https://github.com/owais), Splunk - [Srikanth Chekuri](https://github.com/lonewolf3739) *Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver).* @@ -105,7 +106,6 @@ Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-t - [Diego Hurtado](https://github.com/ocelotl), Lightstep - [Leighton Chen](https://github.com/lzchen), Microsoft -- [Owais Lone](https://github.com/owais), Splunk *Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).* diff --git a/_template/version.py b/_template/version.py index a94d4ed446..5743fb8ce1 100644 --- a/_template/version.py +++ b/_template/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/eachdist.ini b/eachdist.ini index baec3c3a93..4d348dcb2b 100644 --- a/eachdist.ini +++ b/eachdist.ini @@ -16,7 +16,7 @@ sortfirst= ext/* [stable] -version=1.9.1 +version=1.10.0 packages= opentelemetry-sdk @@ -34,7 +34,7 @@ packages= opentelemetry-api [prerelease] -version=0.28b1 +version=0.29b0 packages= all diff --git a/exporter/opentelemetry-exporter-datadog/README.rst b/exporter/opentelemetry-exporter-datadog/README.rst index cb97e5997f..08dc5e800e 100644 --- a/exporter/opentelemetry-exporter-datadog/README.rst +++ b/exporter/opentelemetry-exporter-datadog/README.rst @@ -1,5 +1,5 @@ -OpenTelemetry Datadog Exporter -============================== +OpenTelemetry Datadog Span Exporter +=================================== |pypi| @@ -10,6 +10,9 @@ This library allows to export tracing data to `Datadog `_. OpenTelemetry span event and links are not supported. +.. warning:: This exporter has been deprecated. To export your OTLP traces from OpenTelemetry SDK directly to Datadog Agent, please refer to `OTLP Ingest in Datadog Agent `_ . + + Installation ------------ diff --git a/exporter/opentelemetry-exporter-datadog/setup.cfg b/exporter/opentelemetry-exporter-datadog/setup.cfg index 1ea787f908..a7e97467f3 100644 --- a/exporter/opentelemetry-exporter-datadog/setup.cfg +++ b/exporter/opentelemetry-exporter-datadog/setup.cfg @@ -43,7 +43,7 @@ install_requires = ddtrace>=0.34.0,<0.47.0 opentelemetry-api ~= 1.3 opentelemetry-sdk ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.packages.find] where = src diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py index a94d4ed446..5743fb8ce1 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/exporter/opentelemetry-exporter-richconsole/setup.cfg b/exporter/opentelemetry-exporter-richconsole/setup.cfg index 0ba71fc889..75dd3ff279 100644 --- a/exporter/opentelemetry-exporter-richconsole/setup.cfg +++ b/exporter/opentelemetry-exporter-richconsole/setup.cfg @@ -43,7 +43,7 @@ install_requires = rich>=10.0.0 opentelemetry-api ~= 1.3 opentelemetry-sdk ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.packages.find] where = src diff --git a/exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/version.py b/exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/version.py index a94d4ed446..5743fb8ce1 100644 --- a/exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/version.py +++ b/exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg index d845eaf9b7..1440845a37 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.cfg @@ -41,9 +41,9 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py index fe3dafc50e..09073ff486 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg b/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg index bf2258df51..fef3174f77 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-aiopg/setup.cfg @@ -41,14 +41,14 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation-dbapi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-dbapi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-test-utils == 0.29b0 + opentelemetry-semantic-conventions == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg b/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg index 51aaea39e0..5d7e1655fb 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-asgi/setup.cfg @@ -41,14 +41,14 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 asgiref ~= 3.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg index 91e4bdbe32..23d0368b55 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.cfg b/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.cfg index 679d307539..cfcaa23e16 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.cfg @@ -38,13 +38,13 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 opentelemetry-propagator-aws-xray == 1.0.1 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/version.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/version.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg index 03639951f3..628735eefb 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = moto~=2.0 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 markupsafe==2.0.1 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg index 261ad302d6..15a8027b0e 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = moto[all] ~= 2.2.6 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 markupsafe==2.0.1 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-celery/setup.cfg b/instrumentation/opentelemetry-instrumentation-celery/setup.cfg index 49af2a6a5e..f1b100a2fe 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-celery/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = pytest - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg b/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg index d173cdfff5..3043c1922c 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-dbapi/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py index 8c4371483c..33dc2fd267 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/version.py @@ -12,6 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" _instruments = tuple() diff --git a/instrumentation/opentelemetry-instrumentation-django/setup.cfg b/instrumentation/opentelemetry-instrumentation-django/setup.cfg index 6ad43e9afc..349baf5c3d 100644 --- a/instrumentation/opentelemetry-instrumentation-django/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-django/setup.cfg @@ -40,17 +40,17 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-util-http == 0.28b1 - opentelemetry-instrumentation-wsgi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-util-http == 0.29b0 + opentelemetry-instrumentation-wsgi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] asgi = - opentelemetry-instrumentation-asgi == 0.28b1 + opentelemetry-instrumentation-asgi == 0.29b0 test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index 6ffc200609..6d756c665a 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -275,7 +275,7 @@ def process_response(self, request, response): add_response_attributes( span, f"{response.status_code} {response.reason_phrase}", - response, + response.items(), ) propagator = get_global_response_propagator() diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg index 3d02adcec1..1d785632a2 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 elasticsearch-dsl >= 2.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg b/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg index a7aae1a65a..e5ea642115 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-falcon/setup.cfg @@ -40,15 +40,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-instrumentation-wsgi == 0.28b1 - opentelemetry-util-http == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-wsgi == 0.29b0 + opentelemetry-util-http == 0.29b0 + opentelemetry-instrumentation == 0.29b0 opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 parameterized == 0.7.4 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg b/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg index 1704ebddb9..be10a90ea8 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-fastapi/setup.cfg @@ -41,10 +41,10 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-instrumentation-asgi == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-instrumentation-asgi == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.entry_points] opentelemetry_instrumentor = @@ -52,7 +52,7 @@ opentelemetry_instrumentor = [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 requests ~= 2.23.0 # needed for testclient [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg index d71bd41650..0215c672ca 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg @@ -40,15 +40,15 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-util-http == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-instrumentation-wsgi == 0.28b1 + opentelemetry-util-http == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-instrumentation-wsgi == 0.29b0 opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 markupsafe==2.0.1 [options.entry_points] diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 6a46460be7..1db768a2c0 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -153,6 +153,10 @@ def _start_response(status, response_headers, *args, **kwargs): otel_wsgi.add_response_attributes( span, status, response_headers ) + if span.kind == trace.SpanKind.SERVER: + otel_wsgi.add_custom_response_headers( + span, response_headers + ) else: _logger.warning( "Flask environ's OpenTelemetry span " @@ -200,6 +204,10 @@ def _before_request(): ] = flask.request.url_rule.rule for key, value in attributes.items(): span.set_attribute(key, value) + if span.kind == trace.SpanKind.SERVER: + otel_wsgi.add_custom_request_headers( + span, flask_request_environ + ) activation = trace.use_span(span, end_on_exit=True) activation.__enter__() # pylint: disable=E1101 diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py b/instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py index d989c66474..d5424f9079 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from flask import Response from werkzeug.test import Client from werkzeug.wrappers import BaseResponse @@ -23,6 +24,16 @@ def _hello_endpoint(helloid): raise ValueError(":-(") return "Hello: " + str(helloid) + @staticmethod + def _custom_response_headers(): + resp = Response("test response") + resp.headers["content-type"] = "text/plain; charset=utf-8" + resp.headers["content-length"] = "13" + resp.headers[ + "my-custom-header" + ] = "my-custom-value-1,my-custom-header-2" + return resp + def _common_initialization(self): def excluded_endpoint(): return "excluded" @@ -35,6 +46,9 @@ def excluded2_endpoint(): self.app.route("/excluded/")(self._hello_endpoint) self.app.route("/excluded")(excluded_endpoint) self.app.route("/excluded2")(excluded2_endpoint) + self.app.route("/test_custom_response_headers")( + self._custom_response_headers + ) # pylint: disable=attribute-defined-outside-init self.client = Client(self.app, BaseResponse) diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index a3064b52e5..6329bf1d30 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -442,3 +442,101 @@ def test_mark_span_internal_in_presence_of_span_from_other_framework(self): self.assertEqual( span_list[0].parent.span_id, span_list[1].context.span_id ) + + +class TestCustomRequestResponseHeaders( + InstrumentationTest, TestBase, WsgiTestBase +): + def setUp(self): + super().setUp() + + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST": "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3", + "OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE": "content-type,content-length,my-custom-header,invalid-header", + }, + ) + self.env_patch.start() + self.app = Flask(__name__) + FlaskInstrumentor().instrument_app(self.app) + + self._common_initialization() + + def tearDown(self): + super().tearDown() + self.env_patch.stop() + with self.disable_logging(): + FlaskInstrumentor().uninstrument_app(self.app) + + def test_custom_request_header_added_in_server_span(self): + headers = { + "Custom-Test-Header-1": "Test Value 1", + "Custom-Test-Header-2": "TestValue2,TestValue3", + } + resp = self.client.get("/hello/123", headers=headers) + self.assertEqual(200, resp.status_code) + span = self.memory_exporter.get_finished_spans()[0] + expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + "http.request.header.custom_test_header_2": ( + "TestValue2,TestValue3", + ), + } + self.assertEqual(span.kind, trace.SpanKind.SERVER) + self.assertSpanHasAttributes(span, expected) + + def test_custom_request_header_not_added_in_internal_span(self): + tracer = trace.get_tracer(__name__) + with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): + headers = { + "Custom-Test-Header-1": "Test Value 1", + "Custom-Test-Header-2": "TestValue2,TestValue3", + } + resp = self.client.get("/hello/123", headers=headers) + self.assertEqual(200, resp.status_code) + span = self.memory_exporter.get_finished_spans()[0] + not_expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + "http.request.header.custom_test_header_2": ( + "TestValue2,TestValue3", + ), + } + self.assertEqual(span.kind, trace.SpanKind.INTERNAL) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + def test_custom_response_header_added_in_server_span(self): + resp = self.client.get("/test_custom_response_headers") + self.assertEqual(resp.status_code, 200) + span = self.memory_exporter.get_finished_spans()[0] + expected = { + "http.response.header.content_type": ( + "text/plain; charset=utf-8", + ), + "http.response.header.content_length": ("13",), + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + self.assertEqual(span.kind, trace.SpanKind.SERVER) + self.assertSpanHasAttributes(span, expected) + + def test_custom_response_header_not_added_in_internal_span(self): + tracer = trace.get_tracer(__name__) + with tracer.start_as_current_span("test", kind=trace.SpanKind.SERVER): + resp = self.client.get("/test_custom_response_headers") + self.assertEqual(resp.status_code, 200) + span = self.memory_exporter.get_finished_spans()[0] + not_expected = { + "http.response.header.content_type": ( + "text/plain; charset=utf-8", + ), + "http.response.header.content_length": ("13",), + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + self.assertEqual(span.kind, trace.SpanKind.INTERNAL) + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg b/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg index 02afc99619..9792b21c6c 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-grpc/setup.cfg @@ -42,13 +42,13 @@ packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 opentelemetry-sdk ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 opentelemetry-sdk ~= 1.3 protobuf >= 3.13.0 diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-httpx/setup.cfg b/instrumentation/opentelemetry-instrumentation-httpx/setup.cfg index 8a6194cf61..2cf3788de9 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-httpx/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] test = opentelemetry-sdk ~= 1.3 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/version.py b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/version.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg index 97588f6eff..3a55687d95 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg @@ -40,12 +40,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 markupsafe==2.0.1 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/setup.cfg b/instrumentation/opentelemetry-instrumentation-kafka-python/setup.cfg index 0332dff1b1..afa38ef1b4 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.5 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-semantic-conventions == 0.28b1 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-semantic-conventions == 0.29b0 [options.extras_require] test = wrapt >= 1.0.0, < 2.0.0 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.entry_points] opentelemetry_instrumentor = diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/version.py b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/version.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-logging/setup.cfg b/instrumentation/opentelemetry-instrumentation-logging/setup.cfg index 648a79670b..cee9e8d3aa 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-logging/setup.cfg @@ -40,11 +40,11 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/version.py b/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/version.py index 8c4371483c..33dc2fd267 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/version.py +++ b/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/version.py @@ -12,6 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" _instruments = tuple() diff --git a/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg b/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg index 70e5e9289c..f1adfb9f02 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-mysql/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation-dbapi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-dbapi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/src/opentelemetry/instrumentation/mysql/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-pika/setup.cfg b/instrumentation/opentelemetry-instrumentation-pika/setup.cfg index b1b5e0792a..8499c980d6 100644 --- a/instrumentation/opentelemetry-instrumentation-pika/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pika/setup.cfg @@ -49,7 +49,7 @@ install_requires = test = pytest wrapt >= 1.0.0, < 2.0.0 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/version.py b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/version.py +++ b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg index 08d563d622..47d2a90605 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation-dbapi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-dbapi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg index b3f9e8227d..98ed80c046 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg index 2b14d627fc..e58efe5be5 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymongo/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg b/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg index 2579444f41..bd02bfb1f2 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pymysql/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation-dbapi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-dbapi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py +++ b/instrumentation/opentelemetry-instrumentation-pymysql/src/opentelemetry/instrumentation/pymysql/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg b/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg index 350efdb102..7c19e465b2 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-pyramid/setup.cfg @@ -40,17 +40,17 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation-wsgi == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation-wsgi == 0.29b0 + opentelemetry-util-http == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = werkzeug == 0.16.1 - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index 8dc09cae5e..cc424eb0d9 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -161,7 +161,7 @@ def trace_tween(request): otel_wsgi.add_response_attributes( span, response_or_exception.status, - response_or_exception.headers, + response_or_exception.headerlist, ) propagator = get_global_response_propagator() diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-redis/setup.cfg b/instrumentation/opentelemetry-instrumentation-redis/setup.cfg index 9fe555cde2..f3fc65d89e 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-redis/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 wrapt >= 1.12.1 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 opentelemetry-sdk ~= 1.3 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-requests/setup.cfg b/instrumentation/opentelemetry-instrumentation-requests/setup.cfg index 6a784e6441..a8aa3cece8 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-requests/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 httpretty ~= 1.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index 7286556751..7aefd32ec7 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -162,13 +162,15 @@ def _instrumented_requests_call( url = remove_url_credentials(url) + span_attributes = { + SpanAttributes.HTTP_METHOD: method, + SpanAttributes.HTTP_URL: url, + } + with tracer.start_as_current_span( - span_name, kind=SpanKind.CLIENT + span_name, kind=SpanKind.CLIENT, attributes=span_attributes ) as span, set_ip_on_next_http_connection(span): exception = None - if span.is_recording(): - span.set_attribute(SpanAttributes.HTTP_METHOD, method) - span.set_attribute(SpanAttributes.HTTP_URL, url) headers = get_or_create_headers() inject(headers) diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg b/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg index 7459046387..ac07ede730 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sklearn/setup.cfg @@ -41,11 +41,11 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py index fe3dafc50e..09073ff486 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg index 7268cbc012..a3b24881cc 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.cfg @@ -41,8 +41,8 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 packaging >= 21.0 wrapt >= 1.11.2 diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py index 0c81f2f0da..3beab1fefc 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/__init__.py @@ -106,6 +106,7 @@ def _instrument(self, **kwargs): return EngineTracer( _get_tracer(kwargs.get("engine"), tracer_provider), kwargs.get("engine"), + kwargs.get("enable_commenter", False), ) return None diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index ea0589ca38..10531d8d57 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -17,7 +17,12 @@ from opentelemetry import trace from opentelemetry.instrumentation.sqlalchemy.version import __version__ +from opentelemetry.instrumentation.utils import ( + _generate_opentelemetry_traceparent, + _generate_sql_comment, +) from opentelemetry.semconv.trace import NetTransportValues, SpanAttributes +from opentelemetry.trace import Span from opentelemetry.trace.status import Status, StatusCode @@ -70,12 +75,15 @@ def _wrap_create_engine_internal(func, module, args, kwargs): class EngineTracer: - def __init__(self, tracer, engine): + def __init__(self, tracer, engine, enable_commenter=False): self.tracer = tracer self.engine = engine self.vendor = _normalize_vendor(engine.name) + self.enable_commenter = enable_commenter - listen(engine, "before_cursor_execute", self._before_cur_exec) + listen( + engine, "before_cursor_execute", self._before_cur_exec, retval=True + ) listen(engine, "after_cursor_execute", _after_cur_exec) listen(engine, "handle_error", _handle_error) @@ -115,6 +123,18 @@ def _before_cur_exec( span.set_attribute(key, value) context._otel_span = span + if self.enable_commenter: + statement = statement + EngineTracer._generate_comment(span=span) + + return statement, params + + @staticmethod + def _generate_comment(span: Span) -> str: + span_context = span.get_span_context() + meta = {} + if span_context.is_valid: + meta.update(_generate_opentelemetry_traceparent(span)) + return _generate_sql_comment(**meta) # pylint: disable=unused-argument diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index ec3560f3d1..dd09ff6dbf 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import asyncio +import logging from unittest import mock import pytest @@ -20,12 +21,17 @@ from opentelemetry import trace from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor +from opentelemetry.instrumentation.sqlalchemy.engine import EngineTracer from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider, export from opentelemetry.test.test_base import TestBase class TestSqlalchemyInstrumentation(TestBase): + @pytest.fixture(autouse=True) + def inject_fixtures(self, caplog): + self.caplog = caplog # pylint: disable=attribute-defined-outside-init + def tearDown(self): super().tearDown() SQLAlchemyInstrumentor().uninstrument() @@ -150,3 +156,22 @@ async def run(): self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT) asyncio.get_event_loop().run_until_complete(run()) + + def test_generate_commenter(self): + logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO) + engine = create_engine("sqlite:///:memory:") + SQLAlchemyInstrumentor().instrument( + engine=engine, + tracer_provider=self.tracer_provider, + enable_commenter=True, + ) + + cnx = engine.connect() + cnx.execute("SELECT 1 + 1;").fetchall() + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertIn( + EngineTracer._generate_comment(span), + self.caplog.records[-2].getMessage(), + ) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py new file mode 100644 index 0000000000..89f8d4cca7 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py @@ -0,0 +1,53 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest +from sqlalchemy import create_engine + +from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor +from opentelemetry.test.test_base import TestBase + + +class TestSqlalchemyInstrumentationWithSQLCommenter(TestBase): + @pytest.fixture(autouse=True) + def inject_fixtures(self, caplog): + self.caplog = caplog # pylint: disable=attribute-defined-outside-init + + def tearDown(self): + super().tearDown() + SQLAlchemyInstrumentor().uninstrument() + + def test_sqlcommenter_enabled(self): + engine = create_engine("sqlite:///:memory:") + SQLAlchemyInstrumentor().instrument( + engine=engine, + tracer_provider=self.tracer_provider, + enable_commenter=True, + ) + cnx = engine.connect() + cnx.execute("SELECT 1;").fetchall() + self.assertRegex( + self.caplog.records[-2].getMessage(), + r"SELECT 1; /\*traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/", + ) + + def test_sqlcommenter_disabled(self): + engine = create_engine("sqlite:///:memory:", echo=True) + SQLAlchemyInstrumentor().instrument( + engine=engine, tracer_provider=self.tracer_provider + ) + cnx = engine.connect() + cnx.execute("SELECT 1;").fetchall() + + self.assertEqual(self.caplog.records[-2].getMessage(), "SELECT 1;") diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg index fb8af958de..076d7f8fc7 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.cfg @@ -41,12 +41,12 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation-dbapi == 0.28b1 - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation-dbapi == 0.29b0 + opentelemetry-instrumentation == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py index 8c4371483c..33dc2fd267 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/version.py @@ -12,6 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" _instruments = tuple() diff --git a/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg b/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg index eeb5d1496d..4ce0e19796 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-starlette/setup.cfg @@ -41,10 +41,10 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-instrumentation-asgi == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-instrumentation-asgi == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.entry_points] opentelemetry_instrumentor = @@ -52,7 +52,7 @@ opentelemetry_instrumentor = [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 requests ~= 2.23.0 # needed for testclient [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg b/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg index 8903a20a56..36bbe6839d 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-tornado/setup.cfg @@ -39,14 +39,14 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-instrumentation == 0.28b1 + opentelemetry-instrumentation == 0.29b0 opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.entry_points] opentelemetry_instrumentor = diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg b/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg index 5d0836a1cb..36a849e82d 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-urllib/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 httpretty ~= 1.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py index 8c4371483c..33dc2fd267 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/version.py @@ -12,6 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" _instruments = tuple() diff --git a/instrumentation/opentelemetry-instrumentation-urllib3/setup.cfg b/instrumentation/opentelemetry-instrumentation-urllib3/setup.cfg index 5d73a7a505..fb10975f6e 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib3/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-urllib3/setup.cfg @@ -41,14 +41,14 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 wrapt >= 1.0.0, < 2.0.0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 httpretty ~= 1.0 [options.packages.find] diff --git a/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/version.py b/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/version.py +++ b/instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg index 5033ee3f2a..4b95888c45 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-wsgi/setup.cfg @@ -41,13 +41,13 @@ package_dir= packages=find_namespace: install_requires = opentelemetry-api ~= 1.3 - opentelemetry-semantic-conventions == 0.28b1 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-util-http == 0.28b1 + opentelemetry-semantic-conventions == 0.29b0 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-util-http == 0.29b0 [options.extras_require] test = - opentelemetry-test-utils == 0.28b1 + opentelemetry-test-utils == 0.29b0 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index fdb2076ccd..57a0c8a4c0 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -117,7 +117,14 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he from opentelemetry.propagators.textmap import Getter from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.status import Status, StatusCode -from opentelemetry.util.http import remove_url_credentials +from opentelemetry.util.http import ( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, + get_custom_headers, + normalise_request_header_name, + normalise_response_header_name, + remove_url_credentials, +) _HTTP_VERSION_PREFIX = "HTTP/" _CARRIER_KEY_PREFIX = "HTTP_" @@ -208,6 +215,44 @@ def collect_request_attributes(environ): return result +def add_custom_request_headers(span, environ): + """Adds custom HTTP request headers into the span which are configured by the user + from the PEP3333-conforming WSGI environ to be used as span creation attributes as described + in the specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + attributes = {} + custom_request_headers_name = get_custom_headers( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST + ) + for header_name in custom_request_headers_name: + wsgi_env_var = header_name.upper().replace("-", "_") + header_values = environ.get(f"HTTP_{wsgi_env_var}") + if header_values: + key = normalise_request_header_name(header_name) + attributes[key] = [header_values] + span.set_attributes(attributes) + + +def add_custom_response_headers(span, response_headers): + """Adds custom HTTP response headers into the sapn which are configured by the user from the + PEP3333-conforming WSGI environ as described in the specification + https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + attributes = {} + custom_response_headers_name = get_custom_headers( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE + ) + response_headers_dict = {} + if response_headers: + for header_name, header_value in response_headers: + response_headers_dict[header_name.lower()] = header_value + + for header_name in custom_response_headers_name: + header_values = response_headers_dict.get(header_name.lower()) + if header_values: + key = normalise_response_header_name(header_name) + attributes[key] = [header_values] + span.set_attributes(attributes) + + def add_response_attributes( span, start_response_status, response_headers ): # pylint: disable=unused-argument @@ -268,6 +313,8 @@ def _create_start_response(span, start_response, response_hook): @functools.wraps(start_response) def _start_response(status, response_headers, *args, **kwargs): add_response_attributes(span, status, response_headers) + if span.is_recording() and span.kind == trace.SpanKind.SERVER: + add_custom_response_headers(span, response_headers) if response_hook: response_hook(status, response_headers) return start_response(status, response_headers, *args, **kwargs) @@ -289,6 +336,8 @@ def __call__(self, environ, start_response): context_getter=wsgi_getter, attributes=collect_request_attributes(environ), ) + if span.is_recording() and span.kind == trace.SpanKind.SERVER: + add_custom_request_headers(span, environ) if self.request_hook: self.request_hook(span, environ) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py index a94d4ed446..5743fb8ce1 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index 13b39c9937..3238930792 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -25,6 +25,10 @@ from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase from opentelemetry.trace import StatusCode +from opentelemetry.util.http import ( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, +) class Response: @@ -82,6 +86,19 @@ def error_wsgi_unhandled(environ, start_response): raise ValueError +def wsgi_with_custom_response_headers(environ, start_response): + assert isinstance(environ, dict) + start_response( + "200 OK", + [ + ("content-type", "text/plain; charset=utf-8"), + ("content-length", "100"), + ("my-custom-header", "my-custom-value-1,my-custom-header-2"), + ], + ) + return [b"*"] + + class TestWsgiApplication(WsgiTestBase): def validate_response( self, @@ -444,5 +461,142 @@ def test_mark_span_internal_in_presence_of_span_from_other_framework(self): ) +class TestAdditionOfCustomRequestResponseHeaders(WsgiTestBase, TestBase): + def setUp(self): + super().setUp() + tracer_provider, _ = TestBase.create_tracer_provider() + self.tracer = tracer_provider.get_tracer(__name__) + + def iterate_response(self, response): + while True: + try: + value = next(response) + self.assertEqual(value, b"*") + except StopIteration: + break + + @mock.patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3", + }, + ) + def test_custom_request_headers_non_recording_span(self): + try: + tracer_provider = trace_api.NoOpTracerProvider() + self.environ.update( + { + "HTTP_CUSTOM_TEST_HEADER_1": "Test Value 2", + "HTTP_CUSTOM_TEST_HEADER_2": "TestValue2,TestValue3", + } + ) + app = otel_wsgi.OpenTelemetryMiddleware( + simple_wsgi, tracer_provider=tracer_provider + ) + response = app(self.environ, self.start_response) + self.iterate_response(response) + except Exception as exc: # pylint: disable=W0703 + self.fail(f"Exception raised with NonRecordingSpan {exc}") + + @mock.patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1,Custom-Test-Header-2,Custom-Test-Header-3" + }, + ) + def test_custom_request_headers_added_in_server_span(self): + self.environ.update( + { + "HTTP_CUSTOM_TEST_HEADER_1": "Test Value 1", + "HTTP_CUSTOM_TEST_HEADER_2": "TestValue2,TestValue3", + } + ) + app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi) + response = app(self.environ, self.start_response) + self.iterate_response(response) + span = self.memory_exporter.get_finished_spans()[0] + expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + "http.request.header.custom_test_header_2": ( + "TestValue2,TestValue3", + ), + } + self.assertSpanHasAttributes(span, expected) + + @mock.patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "Custom-Test-Header-1" + }, + ) + def test_custom_request_headers_not_added_in_internal_span(self): + self.environ.update( + { + "HTTP_CUSTOM_TEST_HEADER_1": "Test Value 1", + } + ) + + with self.tracer.start_as_current_span( + "test", kind=trace_api.SpanKind.SERVER + ): + app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi) + response = app(self.environ, self.start_response) + self.iterate_response(response) + span = self.memory_exporter.get_finished_spans()[0] + not_expected = { + "http.request.header.custom_test_header_1": ("Test Value 1",), + } + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + @mock.patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "content-type,content-length,my-custom-header,invalid-header" + }, + ) + def test_custom_response_headers_added_in_server_span(self): + app = otel_wsgi.OpenTelemetryMiddleware( + wsgi_with_custom_response_headers + ) + response = app(self.environ, self.start_response) + self.iterate_response(response) + span = self.memory_exporter.get_finished_spans()[0] + expected = { + "http.response.header.content_type": ( + "text/plain; charset=utf-8", + ), + "http.response.header.content_length": ("100",), + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + self.assertSpanHasAttributes(span, expected) + + @mock.patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "my-custom-header" + }, + ) + def test_custom_response_headers_not_added_in_internal_span(self): + with self.tracer.start_as_current_span( + "test", kind=trace_api.SpanKind.INTERNAL + ): + app = otel_wsgi.OpenTelemetryMiddleware( + wsgi_with_custom_response_headers + ) + response = app(self.environ, self.start_response) + self.iterate_response(response) + span = self.memory_exporter.get_finished_spans()[0] + not_expected = { + "http.response.header.my_custom_header": ( + "my-custom-value-1,my-custom-header-2", + ), + } + for key, _ in not_expected.items(): + self.assertNotIn(key, span.attributes) + + if __name__ == "__main__": unittest.main() diff --git a/opentelemetry-distro/setup.cfg b/opentelemetry-distro/setup.cfg index 9510731ca7..fb0bd5d334 100644 --- a/opentelemetry-distro/setup.cfg +++ b/opentelemetry-distro/setup.cfg @@ -42,8 +42,8 @@ zip_safe = False include_package_data = True install_requires = opentelemetry-api ~= 1.3 - opentelemetry-instrumentation == 0.28b1 - opentelemetry-sdk == 1.9.1 + opentelemetry-instrumentation == 0.29b0 + opentelemetry-sdk == 1.10.0 [options.packages.find] where = src @@ -57,4 +57,4 @@ opentelemetry_configurator = [options.extras_require] test = otlp = - opentelemetry-exporter-otlp == 1.9.1 + opentelemetry-exporter-otlp == 1.10.0 diff --git a/opentelemetry-distro/src/opentelemetry/distro/version.py b/opentelemetry-distro/src/opentelemetry/distro/version.py index a94d4ed446..5743fb8ce1 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/version.py +++ b/opentelemetry-distro/src/opentelemetry/distro/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index c3905787ff..a159d3bae9 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -18,130 +18,130 @@ libraries = { "aiohttp": { "library": "aiohttp ~= 3.0", - "instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.28b1", + "instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.29b0", }, "aiopg": { "library": "aiopg >= 0.13.0, < 1.3.0", - "instrumentation": "opentelemetry-instrumentation-aiopg==0.28b1", + "instrumentation": "opentelemetry-instrumentation-aiopg==0.29b0", }, "asgiref": { "library": "asgiref ~= 3.0", - "instrumentation": "opentelemetry-instrumentation-asgi==0.28b1", + "instrumentation": "opentelemetry-instrumentation-asgi==0.29b0", }, "asyncpg": { "library": "asyncpg >= 0.12.0", - "instrumentation": "opentelemetry-instrumentation-asyncpg==0.28b1", + "instrumentation": "opentelemetry-instrumentation-asyncpg==0.29b0", }, "boto": { "library": "boto~=2.0", - "instrumentation": "opentelemetry-instrumentation-boto==0.28b1", + "instrumentation": "opentelemetry-instrumentation-boto==0.29b0", }, "botocore": { "library": "botocore ~= 1.0", - "instrumentation": "opentelemetry-instrumentation-botocore==0.28b1", + "instrumentation": "opentelemetry-instrumentation-botocore==0.29b0", }, "celery": { "library": "celery >= 4.0, < 6.0", - "instrumentation": "opentelemetry-instrumentation-celery==0.28b1", + "instrumentation": "opentelemetry-instrumentation-celery==0.29b0", }, "django": { "library": "django >= 1.10", - "instrumentation": "opentelemetry-instrumentation-django==0.28b1", + "instrumentation": "opentelemetry-instrumentation-django==0.29b0", }, "elasticsearch": { "library": "elasticsearch >= 2.0", - "instrumentation": "opentelemetry-instrumentation-elasticsearch==0.28b1", + "instrumentation": "opentelemetry-instrumentation-elasticsearch==0.29b0", }, "falcon": { "library": "falcon >= 2.0.0, < 4.0.0", - "instrumentation": "opentelemetry-instrumentation-falcon==0.28b1", + "instrumentation": "opentelemetry-instrumentation-falcon==0.29b0", }, "fastapi": { "library": "fastapi ~= 0.58", - "instrumentation": "opentelemetry-instrumentation-fastapi==0.28b1", + "instrumentation": "opentelemetry-instrumentation-fastapi==0.29b0", }, "flask": { "library": "flask >= 1.0, < 3.0", - "instrumentation": "opentelemetry-instrumentation-flask==0.28b1", + "instrumentation": "opentelemetry-instrumentation-flask==0.29b0", }, "grpcio": { "library": "grpcio ~= 1.27", - "instrumentation": "opentelemetry-instrumentation-grpc==0.28b1", + "instrumentation": "opentelemetry-instrumentation-grpc==0.29b0", }, "httpx": { "library": "httpx >= 0.18.0", - "instrumentation": "opentelemetry-instrumentation-httpx==0.28b1", + "instrumentation": "opentelemetry-instrumentation-httpx==0.29b0", }, "jinja2": { "library": "jinja2 >= 2.7, < 4.0", - "instrumentation": "opentelemetry-instrumentation-jinja2==0.28b1", + "instrumentation": "opentelemetry-instrumentation-jinja2==0.29b0", }, "kafka-python": { "library": "kafka-python >= 2.0", - "instrumentation": "opentelemetry-instrumentation-kafka-python==0.28b1", + "instrumentation": "opentelemetry-instrumentation-kafka-python==0.29b0", }, "mysql-connector-python": { "library": "mysql-connector-python ~= 8.0", - "instrumentation": "opentelemetry-instrumentation-mysql==0.28b1", + "instrumentation": "opentelemetry-instrumentation-mysql==0.29b0", }, "pika": { "library": "pika >= 0.12.0", - "instrumentation": "opentelemetry-instrumentation-pika==0.28b1", + "instrumentation": "opentelemetry-instrumentation-pika==0.29b0", }, "psycopg2": { "library": "psycopg2 >= 2.7.3.1", - "instrumentation": "opentelemetry-instrumentation-psycopg2==0.28b1", + "instrumentation": "opentelemetry-instrumentation-psycopg2==0.29b0", }, "pymemcache": { "library": "pymemcache ~= 1.3", - "instrumentation": "opentelemetry-instrumentation-pymemcache==0.28b1", + "instrumentation": "opentelemetry-instrumentation-pymemcache==0.29b0", }, "pymongo": { "library": "pymongo >= 3.1, < 5.0", - "instrumentation": "opentelemetry-instrumentation-pymongo==0.28b1", + "instrumentation": "opentelemetry-instrumentation-pymongo==0.29b0", }, "PyMySQL": { "library": "PyMySQL < 2", - "instrumentation": "opentelemetry-instrumentation-pymysql==0.28b1", + "instrumentation": "opentelemetry-instrumentation-pymysql==0.29b0", }, "pyramid": { "library": "pyramid >= 1.7", - "instrumentation": "opentelemetry-instrumentation-pyramid==0.28b1", + "instrumentation": "opentelemetry-instrumentation-pyramid==0.29b0", }, "redis": { "library": "redis >= 2.6", - "instrumentation": "opentelemetry-instrumentation-redis==0.28b1", + "instrumentation": "opentelemetry-instrumentation-redis==0.29b0", }, "requests": { "library": "requests ~= 2.0", - "instrumentation": "opentelemetry-instrumentation-requests==0.28b1", + "instrumentation": "opentelemetry-instrumentation-requests==0.29b0", }, "scikit-learn": { "library": "scikit-learn ~= 0.24.0", - "instrumentation": "opentelemetry-instrumentation-sklearn==0.28b1", + "instrumentation": "opentelemetry-instrumentation-sklearn==0.29b0", }, "sqlalchemy": { "library": "sqlalchemy", - "instrumentation": "opentelemetry-instrumentation-sqlalchemy==0.28b1", + "instrumentation": "opentelemetry-instrumentation-sqlalchemy==0.29b0", }, "starlette": { "library": "starlette ~= 0.13.0", - "instrumentation": "opentelemetry-instrumentation-starlette==0.28b1", + "instrumentation": "opentelemetry-instrumentation-starlette==0.29b0", }, "tornado": { "library": "tornado >= 5.1.1", - "instrumentation": "opentelemetry-instrumentation-tornado==0.28b1", + "instrumentation": "opentelemetry-instrumentation-tornado==0.29b0", }, "urllib3": { "library": "urllib3 >= 1.0.0, < 2.0.0", - "instrumentation": "opentelemetry-instrumentation-urllib3==0.28b1", + "instrumentation": "opentelemetry-instrumentation-urllib3==0.29b0", }, } default_instrumentations = [ - "opentelemetry-instrumentation-aws-lambda==0.28b1", - "opentelemetry-instrumentation-dbapi==0.28b1", - "opentelemetry-instrumentation-logging==0.28b1", - "opentelemetry-instrumentation-sqlite3==0.28b1", - "opentelemetry-instrumentation-urllib==0.28b1", - "opentelemetry-instrumentation-wsgi==0.28b1", + "opentelemetry-instrumentation-aws-lambda==0.29b0", + "opentelemetry-instrumentation-dbapi==0.29b0", + "opentelemetry-instrumentation-logging==0.29b0", + "opentelemetry-instrumentation-sqlite3==0.29b0", + "opentelemetry-instrumentation-urllib==0.29b0", + "opentelemetry-instrumentation-wsgi==0.29b0", ] diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py index ef21fccbf6..56f174d758 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py @@ -23,7 +23,7 @@ # pylint: disable=E0611 from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY # noqa: F401 from opentelemetry.propagate import extract -from opentelemetry.trace import StatusCode +from opentelemetry.trace import Span, StatusCode def extract_attributes_from_object( @@ -152,3 +152,14 @@ def _url_quote(s): # pylint: disable=invalid-name # thus in our quoting, we need to escape it too to finally give # foo,bar --> foo%%2Cbar return quoted.replace("%", "%%") + + +def _generate_opentelemetry_traceparent(span: Span) -> str: + meta = {} + _version = "00" + _span_id = trace.format_span_id(span.context.span_id) + _trace_id = trace.format_trace_id(span.context.trace_id) + _flags = str(trace.TraceFlags.SAMPLED) + _traceparent = _version + "-" + _trace_id + "-" + _span_id + "-" + _flags + meta.update({"traceparent": _traceparent}) + return meta diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/version.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/version.py index a94d4ed446..5743fb8ce1 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/version.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/version.py b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/version.py index a94d4ed446..5743fb8ce1 100644 --- a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/version.py +++ b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index e007bb7e84..905138cb4f 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -155,3 +155,29 @@ def test_composed_queries(self): span.attributes[SpanAttributes.DB_STATEMENT], 'SELECT FROM "users" where "name"=\'"abc"\'', ) + + def test_commenter_enabled(self): + + stmt = "CREATE TABLE IF NOT EXISTS users (id integer, name varchar)" + with self._tracer.start_as_current_span("rootSpan"): + self._cursor.execute(stmt) + self.validate_spans("CREATE") + Psycopg2Instrumentor().uninstrument() + Psycopg2Instrumentor().instrument(enable_commenter=True) + + self._cursor.execute( + sql.SQL("SELECT FROM {table} where {field}='{value}'").format( + table=sql.Identifier("users"), + field=sql.Identifier("name"), + value=sql.Identifier("abc"), + ) + ) + + spans = self.memory_exporter.get_finished_spans() + span = spans[2] + self.assertEqual(span.name, "SELECT") + self.assertEqual( + span.attributes[SpanAttributes.DB_STATEMENT], + 'SELECT FROM "users" where "name"=\'"abc"\'', + ) + diff --git a/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py b/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py index 3fa2947994..aa34fb439a 100644 --- a/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py +++ b/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py @@ -15,9 +15,16 @@ from os import environ from re import compile as re_compile from re import search -from typing import Iterable +from typing import Iterable, List from urllib.parse import urlparse, urlunparse +OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST = ( + "OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST" +) +OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE = ( + "OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE" +) + class ExcludeList: """Class to exclude certain paths (given as a list of regexes) from tracing requests""" @@ -98,3 +105,23 @@ def remove_url_credentials(url: str) -> str: except ValueError: # an unparseable url was passed pass return url + + +def normalise_request_header_name(header: str) -> str: + key = header.lower().replace("-", "_") + return f"http.request.header.{key}" + + +def normalise_response_header_name(header: str) -> str: + key = header.lower().replace("-", "_") + return f"http.response.header.{key}" + + +def get_custom_headers(env_var: str) -> List[str]: + custom_headers = environ.get(env_var, []) + if custom_headers: + custom_headers = [ + custom_headers.strip() + for custom_headers in custom_headers.split(",") + ] + return custom_headers diff --git a/util/opentelemetry-util-http/src/opentelemetry/util/http/version.py b/util/opentelemetry-util-http/src/opentelemetry/util/http/version.py index a94d4ed446..5743fb8ce1 100644 --- a/util/opentelemetry-util-http/src/opentelemetry/util/http/version.py +++ b/util/opentelemetry-util-http/src/opentelemetry/util/http/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.28b1" +__version__ = "0.29b0" diff --git a/util/opentelemetry-util-http/tests/test_capture_custom_headers.py b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py new file mode 100644 index 0000000000..eb1a4f6a7e --- /dev/null +++ b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py @@ -0,0 +1,67 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from unittest.mock import patch + +from opentelemetry.test.test_base import TestBase +from opentelemetry.util.http import ( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, + get_custom_headers, + normalise_request_header_name, + normalise_response_header_name, +) + + +class TestCaptureCustomHeaders(TestBase): + @patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: "User-Agent,Test-Header" + }, + ) + def test_get_custom_request_header(self): + custom_headers_to_capture = get_custom_headers( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST + ) + self.assertEqual( + custom_headers_to_capture, ["User-Agent", "Test-Header"] + ) + + @patch.dict( + "os.environ", + { + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: "content-type,content-length,test-header" + }, + ) + def test_get_custom_response_header(self): + custom_headers_to_capture = get_custom_headers( + OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE + ) + self.assertEqual( + custom_headers_to_capture, + [ + "content-type", + "content-length", + "test-header", + ], + ) + + def test_normalise_request_header_name(self): + key = normalise_request_header_name("Test-Header") + self.assertEqual(key, "http.request.header.test_header") + + def test_normalise_response_header_name(self): + key = normalise_response_header_name("Test-Header") + self.assertEqual(key, "http.response.header.test_header") From 3e481d209096b1f232191629bee913b7d45b0327 Mon Sep 17 00:00:00 2001 From: Thiyagu55 <64461612+Thiyagu55@users.noreply.github.com> Date: Fri, 11 Mar 2022 18:26:45 +0530 Subject: [PATCH 06/13] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea5e4ca1e..740dfba77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes ([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925) + - `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes ([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952) From b27ec20e93c893ca3709b3f241775258183c2da7 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 11:49:58 +0530 Subject: [PATCH 07/13] psycopg2 sqlcommenter integration test --- .../postgres/test_psycopg_sqlcommenter.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py new file mode 100644 index 0000000000..a2d872333f --- /dev/null +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -0,0 +1,62 @@ +# Copyright 2020, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import psycopg2 + +from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor +from opentelemetry.test.test_base import TestBase + +POSTGRES_HOST = os.getenv("POSTGRESQL_HOST", "localhost") +POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT", "5432")) +POSTGRES_DB_NAME = os.getenv("POSTGRESQL_DB_NAME", "postgres") +POSTGRES_PASSWORD = os.getenv("POSTGRESQL_PASSWORD", "postgres") +POSTGRES_USER = os.getenv("POSTGRESQL_USER", "postgres") + + +class TestFunctionalPsycopg(TestBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls._connection = None + cls._cursor = None + cls._tracer = cls.tracer_provider.get_tracer(__name__) + Psycopg2Instrumentor().instrument(enable_commenter=True) + cls._connection = psycopg2.connect( + dbname=POSTGRES_DB_NAME, + user=POSTGRES_USER, + password=POSTGRES_PASSWORD, + host=POSTGRES_HOST, + port=POSTGRES_PORT, + ) + cls._connection.set_session(autocommit=True) + cls._cursor = cls._connection.cursor() + + @classmethod + def tearDownClass(cls): + if cls._cursor: + cls._cursor.close() + if cls._connection: + cls._connection.close() + Psycopg2Instrumentor().uninstrument() + + def test_commenter_enabled(self): + self._cursor.execute( + "SELECT 1;" + ) + self.assertRegex( + self._cursor.query.decode('ascii'), + r"SELECT 1; /\*traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/", + ) From 47d818059d83b2db4b62853870ae1eae8cb7b21c Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 13:01:36 +0530 Subject: [PATCH 08/13] linting changes --- .../tests/test_psycopg2_integration.py | 8 ++++---- .../tests/postgres/test_psycopg_functional.py | 1 - .../tests/postgres/test_psycopg_sqlcommenter.py | 15 ++++----------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index 2cce3ef8cd..af0983793b 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -225,7 +225,7 @@ def test_uninstrument_connection_with_instrument_connection(self): spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) - @mock.patch('opentelemetry.instrumentation.dbapi.wrap_connect') + @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") def test_sqlcommenter_enabled(self, event_mocked): cnx = psycopg2.connect(database="test") Psycopg2Instrumentor().instrument(enable_commenter=True) @@ -233,9 +233,9 @@ def test_sqlcommenter_enabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) args, kwargs = event_mocked.call_args - self.assertEqual(kwargs['enable_commenter'], True) + self.assertEqual(kwargs["enable_commenter"], True) - @mock.patch('opentelemetry.instrumentation.dbapi.wrap_connect') + @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") def test_sqlcommenter_disabled(self, event_mocked): cnx = psycopg2.connect(database="test") Psycopg2Instrumentor().instrument() @@ -243,4 +243,4 @@ def test_sqlcommenter_disabled(self, event_mocked): cursor = cnx.cursor() cursor.execute(query) args, kwargs = event_mocked.call_args - self.assertEqual(kwargs['enable_commenter'], False) + self.assertEqual(kwargs["enable_commenter"], False) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index 905138cb4f..38ecff02e7 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -180,4 +180,3 @@ def test_commenter_enabled(self): span.attributes[SpanAttributes.DB_STATEMENT], 'SELECT FROM "users" where "name"=\'"abc"\'', ) - diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py index a2d872333f..775dabc070 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -12,18 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - import psycopg2 from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor from opentelemetry.test.test_base import TestBase -POSTGRES_HOST = os.getenv("POSTGRESQL_HOST", "localhost") -POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT", "5432")) -POSTGRES_DB_NAME = os.getenv("POSTGRESQL_DB_NAME", "postgres") -POSTGRES_PASSWORD = os.getenv("POSTGRESQL_PASSWORD", "postgres") -POSTGRES_USER = os.getenv("POSTGRESQL_USER", "postgres") +from test_psycopg_functional import POSTGRES_HOST, POSTGRES_DB_NAME, \ + POSTGRES_PORT, POSTGRES_PASSWORD, POSTGRES_USER class TestFunctionalPsycopg(TestBase): @@ -53,10 +48,8 @@ def tearDownClass(cls): Psycopg2Instrumentor().uninstrument() def test_commenter_enabled(self): - self._cursor.execute( - "SELECT 1;" - ) + self._cursor.execute("SELECT 1;") self.assertRegex( - self._cursor.query.decode('ascii'), + self._cursor.query.decode("ascii"), r"SELECT 1; /\*traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/", ) From bc6c7468f510f9756f3444f809ccdcd7d65c8839 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 13:33:48 +0530 Subject: [PATCH 09/13] linting changes --- .../tests/postgres/test_psycopg_sqlcommenter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py index 775dabc070..d8b7b7dc0c 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -17,8 +17,13 @@ from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor from opentelemetry.test.test_base import TestBase -from test_psycopg_functional import POSTGRES_HOST, POSTGRES_DB_NAME, \ - POSTGRES_PORT, POSTGRES_PASSWORD, POSTGRES_USER +from test_psycopg_functional import ( + POSTGRES_HOST, + POSTGRES_DB_NAME, + POSTGRES_PORT, + POSTGRES_PASSWORD, + POSTGRES_USER, +) class TestFunctionalPsycopg(TestBase): From 7c86ec63da9375f2da1f974ffa12e0a519e1cdf7 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 13:58:00 +0530 Subject: [PATCH 10/13] linting changes --- .../tests/postgres/test_psycopg_sqlcommenter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py index d8b7b7dc0c..48daae8076 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -13,10 +13,6 @@ # limitations under the License. import psycopg2 - -from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor -from opentelemetry.test.test_base import TestBase - from test_psycopg_functional import ( POSTGRES_HOST, POSTGRES_DB_NAME, @@ -25,6 +21,9 @@ POSTGRES_USER, ) +from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor +from opentelemetry.test.test_base import TestBase + class TestFunctionalPsycopg(TestBase): @classmethod From fa62d9d75d57ae5c66cdb39906007dc357c875fa Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 14:12:37 +0530 Subject: [PATCH 11/13] linting changes --- .../tests/postgres/test_psycopg_sqlcommenter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py index 48daae8076..1e3460600e 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py @@ -14,10 +14,10 @@ import psycopg2 from test_psycopg_functional import ( - POSTGRES_HOST, POSTGRES_DB_NAME, - POSTGRES_PORT, + POSTGRES_HOST, POSTGRES_PASSWORD, + POSTGRES_PORT, POSTGRES_USER, ) From 28e332e7f1bd4d70297e708c0dfa2ef48bdb41ce Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Mon, 14 Mar 2022 14:27:00 +0530 Subject: [PATCH 12/13] linting changes --- .../tests/test_psycopg2_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index af0983793b..73f702d1b5 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -232,7 +232,7 @@ def test_sqlcommenter_enabled(self, event_mocked): query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) - args, kwargs = event_mocked.call_args + kwargs = event_mocked.call_args.kwargs self.assertEqual(kwargs["enable_commenter"], True) @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") @@ -242,5 +242,5 @@ def test_sqlcommenter_disabled(self, event_mocked): query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) - args, kwargs = event_mocked.call_args + kwargs = event_mocked.call_args.kwargs self.assertEqual(kwargs["enable_commenter"], False) From abb1b1512832625fd248a76dbd15f8b7e59e27f1 Mon Sep 17 00:00:00 2001 From: Thiyagu55 Date: Thu, 17 Mar 2022 11:31:36 +0530 Subject: [PATCH 13/13] version compatability issue fix --- .../tests/test_psycopg2_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index 73f702d1b5..e974da7d60 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -232,7 +232,7 @@ def test_sqlcommenter_enabled(self, event_mocked): query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) - kwargs = event_mocked.call_args.kwargs + kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], True) @mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect") @@ -242,5 +242,5 @@ def test_sqlcommenter_disabled(self, event_mocked): query = "SELECT * FROM test" cursor = cnx.cursor() cursor.execute(query) - kwargs = event_mocked.call_args.kwargs + kwargs = event_mocked.call_args[1] self.assertEqual(kwargs["enable_commenter"], False)