From ca5a4a16a5e4d109db738078f75f93f68fcd056d Mon Sep 17 00:00:00 2001 From: Ashutosh Goel <39601429+ashu658@users.noreply.github.com> Date: Wed, 2 Mar 2022 02:48:14 +0530 Subject: [PATCH 1/5] Fixing build failures (#928) --- dev-requirements.txt | 1 + docs-requirements.txt | 2 ++ gen-requirements.txt | 1 + instrumentation/opentelemetry-instrumentation-boto/setup.cfg | 1 + .../opentelemetry-instrumentation-botocore/setup.cfg | 1 + instrumentation/opentelemetry-instrumentation-flask/setup.cfg | 1 + instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg | 1 + 7 files changed, 8 insertions(+) diff --git a/dev-requirements.txt b/dev-requirements.txt index 5b53cd381b..4bc1bde99b 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -13,3 +13,4 @@ readme-renderer~=24.0 grpcio-tools==1.29.0 mypy-protobuf>=1.23 protobuf>=3.13.0 +markupsafe==2.0.1 diff --git a/docs-requirements.txt b/docs-requirements.txt index 1a5f7d0cb0..f9a9a13f7d 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -37,3 +37,5 @@ sqlalchemy>=1.0 tornado>=5.1.1 ddtrace>=0.34.0 httpx>=0.18.0 +markupsafe==2.0.1 +itsdangerous==2.0.1 \ No newline at end of file diff --git a/gen-requirements.txt b/gen-requirements.txt index d4a52e0da8..bba15feb22 100644 --- a/gen-requirements.txt +++ b/gen-requirements.txt @@ -1,6 +1,7 @@ -c dev-requirements.txt astor==0.8.1 jinja2~=2.7 +markupsafe==2.0.1 isort black requests diff --git a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg index b80e12b7c5..03639951f3 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-boto/setup.cfg @@ -48,6 +48,7 @@ install_requires = test = moto~=2.0 opentelemetry-test-utils == 0.28b1 + markupsafe==2.0.1 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg index 64ef81f120..261ad302d6 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-botocore/setup.cfg @@ -48,6 +48,7 @@ install_requires = test = moto[all] ~= 2.2.6 opentelemetry-test-utils == 0.28b1 + markupsafe==2.0.1 [options.packages.find] where = src diff --git a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg index 9a14ed20ec..d71bd41650 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-flask/setup.cfg @@ -49,6 +49,7 @@ install_requires = [options.extras_require] test = opentelemetry-test-utils == 0.28b1 + markupsafe==2.0.1 [options.entry_points] opentelemetry_instrumentor = diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg index 63dff62b6d..97588f6eff 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg +++ b/instrumentation/opentelemetry-instrumentation-jinja2/setup.cfg @@ -46,6 +46,7 @@ install_requires = [options.extras_require] test = opentelemetry-test-utils == 0.28b1 + markupsafe==2.0.1 [options.packages.find] where = src From 7bb29bd9ab81baf941a81619baaa77c0fa527f76 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Wed, 2 Mar 2022 17:03:34 -0500 Subject: [PATCH 2/5] Fix typos (#929) --- .../opentelemetry-instrumentation-aiohttp-client/setup.py | 4 ++-- .../opentelemetry-instrumentation-aiopg/setup.py | 4 ++-- instrumentation/opentelemetry-instrumentation-asgi/setup.py | 4 ++-- .../opentelemetry-instrumentation-asyncpg/setup.py | 4 ++-- .../opentelemetry-instrumentation-aws-lambda/setup.py | 4 ++-- instrumentation/opentelemetry-instrumentation-boto/setup.py | 4 ++-- .../opentelemetry-instrumentation-botocore/setup.py | 4 ++-- .../opentelemetry-instrumentation-celery/setup.py | 4 ++-- .../opentelemetry-instrumentation-dbapi/setup.py | 4 ++-- .../opentelemetry-instrumentation-django/setup.py | 4 ++-- .../opentelemetry-instrumentation-elasticsearch/setup.py | 4 ++-- .../opentelemetry-instrumentation-falcon/setup.py | 4 ++-- .../opentelemetry-instrumentation-fastapi/setup.py | 4 ++-- .../opentelemetry-instrumentation-flask/setup.py | 4 ++-- instrumentation/opentelemetry-instrumentation-grpc/setup.py | 4 ++-- .../opentelemetry-instrumentation-httpx/setup.py | 4 ++-- .../opentelemetry-instrumentation-jinja2/setup.py | 4 ++-- .../opentelemetry-instrumentation-kafka-python/setup.py | 4 ++-- .../opentelemetry-instrumentation-logging/setup.py | 4 ++-- .../opentelemetry-instrumentation-mysql/setup.py | 4 ++-- instrumentation/opentelemetry-instrumentation-pika/setup.py | 4 ++-- .../opentelemetry-instrumentation-psycopg2/setup.py | 4 ++-- .../opentelemetry-instrumentation-pymemcache/setup.py | 4 ++-- .../opentelemetry-instrumentation-pymongo/setup.py | 4 ++-- .../opentelemetry-instrumentation-pymysql/setup.py | 4 ++-- .../opentelemetry-instrumentation-pyramid/setup.py | 4 ++-- .../opentelemetry-instrumentation-redis/setup.py | 4 ++-- .../opentelemetry-instrumentation-requests/setup.py | 4 ++-- .../opentelemetry-instrumentation-sklearn/setup.py | 4 ++-- .../opentelemetry-instrumentation-sqlalchemy/setup.py | 4 ++-- .../opentelemetry-instrumentation-sqlite3/setup.py | 4 ++-- .../opentelemetry-instrumentation-starlette/setup.py | 4 ++-- .../opentelemetry-instrumentation-tornado/setup.py | 4 ++-- .../src/opentelemetry/instrumentation/tornado/__init__.py | 5 +++-- .../opentelemetry-instrumentation-urllib/setup.py | 4 ++-- .../opentelemetry-instrumentation-urllib3/setup.py | 4 ++-- instrumentation/opentelemetry-instrumentation-wsgi/setup.py | 4 ++-- templates/instrumentation_setup.py.txt | 6 +++--- 38 files changed, 78 insertions(+), 77 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.py index 048e145d6c..a236509153 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/setup.py b/instrumentation/opentelemetry-instrumentation-aiopg/setup.py index 555f005832..f98a9ab362 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/setup.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-asgi/setup.py b/instrumentation/opentelemetry-instrumentation-asgi/setup.py index ce79c106ff..e98879da6d 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/setup.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.py b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.py index 5e7120c8a7..49b24e5836 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/setup.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.py index d1a8664236..dfcabf0026 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-boto/setup.py b/instrumentation/opentelemetry-instrumentation-boto/setup.py index 05cab9ce70..929673a1f6 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/setup.py +++ b/instrumentation/opentelemetry-instrumentation-boto/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-botocore/setup.py b/instrumentation/opentelemetry-instrumentation-botocore/setup.py index d99c702829..8b1182f7a8 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/setup.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-celery/setup.py b/instrumentation/opentelemetry-instrumentation-celery/setup.py index 2c8b3507ac..8f029cf718 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/setup.py +++ b/instrumentation/opentelemetry-instrumentation-celery/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/setup.py b/instrumentation/opentelemetry-instrumentation-dbapi/setup.py index ff0f57a950..6f0e4f0f0a 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/setup.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-django/setup.py b/instrumentation/opentelemetry-instrumentation-django/setup.py index 48e934c354..ddf4c0760a 100644 --- a/instrumentation/opentelemetry-instrumentation-django/setup.py +++ b/instrumentation/opentelemetry-instrumentation-django/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.py index 3a99f38e74..d6ba804a5f 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-falcon/setup.py b/instrumentation/opentelemetry-instrumentation-falcon/setup.py index 1079daacc6..b319ce4ca1 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/setup.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/setup.py b/instrumentation/opentelemetry-instrumentation-fastapi/setup.py index 48a804bb27..6e4a2fa867 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/setup.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-flask/setup.py b/instrumentation/opentelemetry-instrumentation-flask/setup.py index a484fca705..8a12e07e31 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/setup.py +++ b/instrumentation/opentelemetry-instrumentation-flask/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-grpc/setup.py b/instrumentation/opentelemetry-instrumentation-grpc/setup.py index a6fb80cbdf..0a145c9c8e 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/setup.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-httpx/setup.py b/instrumentation/opentelemetry-instrumentation-httpx/setup.py index 8287bf52e9..b413dffc3c 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/setup.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/setup.py b/instrumentation/opentelemetry-instrumentation-jinja2/setup.py index 0359c1f5bf..dabdc041db 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/setup.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/setup.py b/instrumentation/opentelemetry-instrumentation-kafka-python/setup.py index 4d6bbbabb4..083b4ec4b9 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/setup.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-logging/setup.py b/instrumentation/opentelemetry-instrumentation-logging/setup.py index 8b419ca346..115450aa09 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/setup.py +++ b/instrumentation/opentelemetry-instrumentation-logging/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-mysql/setup.py b/instrumentation/opentelemetry-instrumentation-mysql/setup.py index af6fd555ea..93ca542f9e 100644 --- a/instrumentation/opentelemetry-instrumentation-mysql/setup.py +++ b/instrumentation/opentelemetry-instrumentation-mysql/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-pika/setup.py b/instrumentation/opentelemetry-instrumentation-pika/setup.py index ac600392c1..1930f07ca9 100644 --- a/instrumentation/opentelemetry-instrumentation-pika/setup.py +++ b/instrumentation/opentelemetry-instrumentation-pika/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.py b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.py index 9bd056fc02..d6819d5639 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/setup.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.py b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.py index 274046dc8c..105c59e9e5 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/setup.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/setup.py b/instrumentation/opentelemetry-instrumentation-pymongo/setup.py index 9b2f5b2893..d4da27261a 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/setup.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-pymysql/setup.py b/instrumentation/opentelemetry-instrumentation-pymysql/setup.py index 6c7c8a43b4..3e38522e11 100644 --- a/instrumentation/opentelemetry-instrumentation-pymysql/setup.py +++ b/instrumentation/opentelemetry-instrumentation-pymysql/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/setup.py b/instrumentation/opentelemetry-instrumentation-pyramid/setup.py index b815ddb4bc..d5770b21d8 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/setup.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-redis/setup.py b/instrumentation/opentelemetry-instrumentation-redis/setup.py index b494d81330..5516c76301 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/setup.py +++ b/instrumentation/opentelemetry-instrumentation-redis/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-requests/setup.py b/instrumentation/opentelemetry-instrumentation-requests/setup.py index ecdcadfc96..3fea135761 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/setup.py +++ b/instrumentation/opentelemetry-instrumentation-requests/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/setup.py b/instrumentation/opentelemetry-instrumentation-sklearn/setup.py index ec7e2b9578..9fe347fef6 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/setup.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.py index 81f2ee899d..867116ac95 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.py b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.py index 15ab6abe39..73c703af79 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/setup.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-starlette/setup.py b/instrumentation/opentelemetry-instrumentation-starlette/setup.py index f363ce2047..962386540d 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/setup.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-tornado/setup.py b/instrumentation/opentelemetry-instrumentation-tornado/setup.py index 124943f35b..86ad20db36 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/setup.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index ce81c13735..c18c7acb0e 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -45,12 +45,13 @@ def get(self): :: - export OTEL_PYTHON_TORNADO_EXLUDED_URLS='/healthz,/ping' + export OTEL_PYTHON_TORNADO_EXCLUDED_URLS='/healthz,/ping' Then any requests made to ``/healthz`` and ``/ping`` will not be automatically traced. Request attributes -******************** +****************** + To extract certain attributes from Tornado's request object and use them as span attributes, set the environment variable ``OTEL_PYTHON_TORNADO_TRACED_REQUEST_ATTRS`` to a comma delimited list of request attribute names. diff --git a/instrumentation/opentelemetry-instrumentation-urllib/setup.py b/instrumentation/opentelemetry-instrumentation-urllib/setup.py index cb47ef170b..f8ae47aa01 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/setup.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-urllib3/setup.py b/instrumentation/opentelemetry-instrumentation-urllib3/setup.py index 8b3f3f74de..149726533f 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib3/setup.py +++ b/instrumentation/opentelemetry-instrumentation-urllib3/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/setup.py b/instrumentation/opentelemetry-instrumentation-wsgi/setup.py index d0b5f351fa..91fed6a279 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/setup.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/setup.py @@ -28,8 +28,8 @@ config.read("setup.cfg") # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if "options.extras_require" in config: for key, value in config["options.extras_require"].items(): diff --git a/templates/instrumentation_setup.py.txt b/templates/instrumentation_setup.py.txt index f19238bef2..80d588e0ff 100644 --- a/templates/instrumentation_setup.py.txt +++ b/templates/instrumentation_setup.py.txt @@ -27,8 +27,8 @@ config = ConfigParser() config.read('setup.cfg') # We provide extras_require parameter to setuptools.setup later which -# overwrites the extra_require section from setup.cfg. To support extra_require -# secion in setup.cfg, we load it here and merge it with the extra_require param. +# overwrites the extras_require section from setup.cfg. To support extras_require +# section in setup.cfg, we load it here and merge it with the extras_require param. extras_require = {} if 'options.extras_require' in config: for key, value in config['options.extras_require'].items(): @@ -84,4 +84,4 @@ setuptools.setup( cmdclass={'meta': JSONMetadataCommand}, version=PACKAGE_INFO["__version__"], extras_require=extras_require -) \ No newline at end of file +) From 2ab66416ab7927f08400e324a40fc4ee38d9e116 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 4 Mar 2022 11:00:37 -0800 Subject: [PATCH 3/5] Make requests span attributes available to samplers (#931) --- CHANGELOG.md | 2 ++ .../opentelemetry/instrumentation/requests/__init__.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236a3de288..7a67773c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability ([#908](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/908)) +- `opentelemetry-instrumentation-requests` make span attribute available to samplers + ([#931](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/931)) ### Fixed 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) From 2f5bbc416ab33f4856e1990a5e5682fcedc90f5f Mon Sep 17 00:00:00 2001 From: Ashutosh Goel <39601429+ashu658@users.noreply.github.com> Date: Mon, 7 Mar 2022 23:11:46 +0530 Subject: [PATCH 4/5] Capture custom request/response headers for wsgi and change in passing response_headers in django, pyramid (#925) --- CHANGELOG.md | 3 + .../instrumentation/django/middleware.py | 2 +- .../instrumentation/pyramid/callbacks.py | 2 +- .../instrumentation/wsgi/__init__.py | 51 ++++++- .../tests/test_wsgi_middleware.py | 131 ++++++++++++++++++ .../src/opentelemetry/util/http/__init__.py | 29 +++- .../tests/test_capture_custom_headers.py | 67 +++++++++ 7 files changed, 281 insertions(+), 4 deletions(-) create mode 100644 util/opentelemetry-util-http/tests/test_capture_custom_headers.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a67773c5e..f8967010a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ 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) +- `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes + ([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925) + ### Added - `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability 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-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-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index fdb2076ccd..ad4d425b25 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.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.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/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index 13b39c9937..35f8e0577a 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,119 @@ 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_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/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/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 dbb35a29465bcaf84380715c356726718724859b Mon Sep 17 00:00:00 2001 From: Thiyagu55 <64461612+Thiyagu55@users.noreply.github.com> Date: Wed, 9 Mar 2022 11:27:00 +0530 Subject: [PATCH 5/5] Sqlcommenter integration into SQLAlchemy (#924) * Integrating sqlcommenter into psycopg2 * Integrating sqlcommenter into psycopg2 - Converted public local variable into private * Added test cases for sqlcommenter & PR Changes * Code refactoring for generate sqlcommenter * Added testcase for sqlcommenter integration into sqlalchemy * updated change log * updated to accept latest logs * Updated lint changes * Fixed errors due to linting * Fixed linting errors * Fixed linting errors * Fixed linting errors * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Srikanth Chekuri Co-authored-by: Srikanth Chekuri --- CHANGELOG.md | 2 + .../instrumentation/sqlalchemy/__init__.py | 1 + .../instrumentation/sqlalchemy/engine.py | 24 ++++++++- .../tests/test_sqlalchemy.py | 25 +++++++++ .../tests/test_sqlcommenter.py | 53 +++++++++++++++++++ .../opentelemetry/instrumentation/utils.py | 13 ++++- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlcommenter.py diff --git a/CHANGELOG.md b/CHANGELOG.md index f8967010a7..6e38858d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `opentelemetry-instrumentation-sqlalchemy` added experimental sql commenter capability + ([#924](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/924)) - `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability ([#908](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/908)) - `opentelemetry-instrumentation-requests` make span attribute available to samplers 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/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/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