Skip to content

Commit 36275f3

Browse files
andrew-mattesonalrexlzchenowais
authored
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 <[email protected]> Co-authored-by: Leighton Chen <[email protected]> Co-authored-by: Owais Lone <[email protected]>
1 parent 224780f commit 36275f3

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: adad94bfa69520cb4cbabca714827fd14503baf0
9+
CORE_REPO_SHA: 65528f7534f1f5f2e8adc7520b6e696a84569c7d
1010

1111
jobs:
1212
build:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
([#720](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/720))
1515

1616

17+
### Changed
18+
- `opentelemetry-instrumentation-jinja2` Allow instrumentation of newer Jinja2 versions.
19+
1720
### Added
1821
- `opentelemetry-instrumentation-elasticsearch` Added `response_hook` and `request_hook` callbacks
1922
([#670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/670))

instrumentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 |
1717
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 |
1818
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0, < 0.19.0 |
19-
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2~=2.7 |
19+
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 |
2020
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging |
2121
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 |
2222
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 1.1.0 |

instrumentation/opentelemetry-instrumentation-jinja2/src/opentelemetry/instrumentation/jinja2/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414

1515

16-
_instruments = ("jinja2~=2.7",)
16+
_instruments = ("jinja2 >= 2.7, < 4.0",)

instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from unittest import mock
1717

1818
import jinja2
19+
from packaging import version
1920

2021
from opentelemetry import trace as trace_api
2122
from opentelemetry.instrumentation.jinja2 import Jinja2Instrumentor
@@ -31,8 +32,13 @@ def setUp(self):
3132
super().setUp()
3233
Jinja2Instrumentor().instrument()
3334
# prevent cache effects when using Template('code...')
34-
# pylint: disable=protected-access
35-
jinja2.environment._spontaneous_environments.clear()
35+
if version.parse(jinja2.__version__) >= version.parse("3.0.0"):
36+
# by clearing functools.lru_cache
37+
jinja2.environment.get_spontaneous_environment.clear()
38+
else:
39+
# by clearing jinja2.utils.LRUCache
40+
jinja2.environment._spontaneous_environments.clear() # pylint: disable=no-member
41+
3642
self.tracer = get_tracer(__name__)
3743

3844
def tearDown(self):

0 commit comments

Comments
 (0)