Skip to content

Commit 4f20802

Browse files
committed
Remove Configuration from flask
1 parent e484642 commit 4f20802

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ def hello():
4848
"""
4949

5050
from logging import getLogger
51+
from re import compile as re_compile, search
52+
from os import environ
5153

5254
import flask
5355

5456
import opentelemetry.instrumentation.wsgi as otel_wsgi
55-
from opentelemetry import configuration, context, propagators, trace
57+
from opentelemetry import context, propagators, trace
5658
from opentelemetry.instrumentation.flask.version import __version__
5759
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5860
from opentelemetry.util import time_ns
@@ -65,7 +67,31 @@ def hello():
6567
_ENVIRON_TOKEN = "opentelemetry-flask.token"
6668

6769

68-
_excluded_urls = configuration.Configuration()._excluded_urls("flask")
70+
class _ExcludeList:
71+
"""Class to exclude certain paths (given as a list of regexes) from tracing requests"""
72+
73+
def __init__(self, excluded_urls):
74+
self._excluded_urls = excluded_urls
75+
if self._excluded_urls:
76+
self._regex = re_compile("|".join(excluded_urls))
77+
78+
def url_disabled(self, url: str) -> bool:
79+
return bool(self._excluded_urls and search(self._regex, url))
80+
81+
82+
def _get_excluded_urls():
83+
excluded_urls = environ.get("OTEL_PYTHON_FLASK_EXCLUDED_URLS", [])
84+
85+
if excluded_urls:
86+
excluded_urls = [
87+
excluded_url.strip()
88+
for excluded_url in excluded_urls.split(",")
89+
]
90+
91+
return _ExcludeList(excluded_urls)
92+
93+
94+
_excluded_urls = _get_excluded_urls()
6995

7096

7197
def get_default_span_name():

instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py

-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
from werkzeug.test import Client
1616
from werkzeug.wrappers import BaseResponse
1717

18-
from opentelemetry.configuration import Configuration
19-
2018

2119
class InstrumentationTest:
2220
def setUp(self): # pylint: disable=invalid-name
2321
super().setUp() # pylint: disable=no-member
24-
Configuration._reset() # pylint: disable=protected-access
2522

2623
@staticmethod
2724
def _hello_endpoint(helloid):

instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
from flask import Flask, request
1818

1919
from opentelemetry import trace
20-
from opentelemetry.configuration import Configuration
21-
from opentelemetry.instrumentation.flask import FlaskInstrumentor
20+
from opentelemetry.instrumentation.flask import (
21+
FlaskInstrumentor, _get_excluded_urls
22+
)
2223
from opentelemetry.test.test_base import TestBase
2324
from opentelemetry.test.wsgitestutil import WsgiTestBase
2425

@@ -63,7 +64,7 @@ def setUp(self):
6364
self.env_patch.start()
6465
self.exclude_patch = patch(
6566
"opentelemetry.instrumentation.flask._excluded_urls",
66-
Configuration()._excluded_urls("flask"),
67+
_get_excluded_urls(),
6768
)
6869
self.exclude_patch.start()
6970

0 commit comments

Comments
 (0)