Expand allowed versions for jinja2 instrumentation (#712)

* Expand allowed versions

The Jinja2 API hasn't changed the functions that have been wrapped in at least 8 years.
The version supported should be much more broad.

* don't include 4+

* Update changelog

* Fix test that depends on lru_cache now

* tox -e generate

* Make test setup backwards compatible

* Update for code review feedback

* Disable linting check

* Fix black formatting issue

* Update readme from tox -e generate

* Update core repo sha

Co-authored-by: alrex <aboten@lightstep.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Owais Lone <owais@users.noreply.github.com>
This commit is contained in:
andrew-matteson
2021-10-12 12:15:16 -04:00
committed by GitHub
parent 224780f38d
commit 36275f3cbf
5 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,7 @@ on:
- 'release/*' - 'release/*'
pull_request: pull_request:
env: env:
CORE_REPO_SHA: adad94bfa69520cb4cbabca714827fd14503baf0 CORE_REPO_SHA: 65528f7534f1f5f2e8adc7520b6e696a84569c7d
jobs: jobs:
build: build:

View File

@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#720](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/720)) ([#720](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/720))
### Changed
- `opentelemetry-instrumentation-jinja2` Allow instrumentation of newer Jinja2 versions.
### Added ### Added
- `opentelemetry-instrumentation-elasticsearch` Added `response_hook` and `request_hook` callbacks - `opentelemetry-instrumentation-elasticsearch` Added `response_hook` and `request_hook` callbacks
([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670)) ([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670))

View File

@ -16,7 +16,7 @@
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | | [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 |
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | | [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 |
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0, < 0.19.0 | | [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0, < 0.19.0 |
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2~=2.7 | | [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 |
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | | [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging |
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | | [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 |
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 1.1.0 | | [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 1.1.0 |

View File

@ -13,4 +13,4 @@
# limitations under the License. # limitations under the License.
_instruments = ("jinja2~=2.7",) _instruments = ("jinja2 >= 2.7, < 4.0",)

View File

@ -16,6 +16,7 @@ import os
from unittest import mock from unittest import mock
import jinja2 import jinja2
from packaging import version
from opentelemetry import trace as trace_api from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.jinja2 import Jinja2Instrumentor from opentelemetry.instrumentation.jinja2 import Jinja2Instrumentor
@ -31,8 +32,13 @@ class TestJinja2Instrumentor(TestBase):
super().setUp() super().setUp()
Jinja2Instrumentor().instrument() Jinja2Instrumentor().instrument()
# prevent cache effects when using Template('code...') # prevent cache effects when using Template('code...')
# pylint: disable=protected-access if version.parse(jinja2.__version__) >= version.parse("3.0.0"):
jinja2.environment._spontaneous_environments.clear() # by clearing functools.lru_cache
jinja2.environment.get_spontaneous_environment.clear()
else:
# by clearing jinja2.utils.LRUCache
jinja2.environment._spontaneous_environments.clear() # pylint: disable=no-member
self.tracer = get_tracer(__name__) self.tracer = get_tracer(__name__)
def tearDown(self): def tearDown(self):