Skip to content

Commit

Permalink
Remove Configuration from flask
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jan 12, 2021
1 parent e484642 commit 4f20802
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ def hello():
"""

from logging import getLogger
from re import compile as re_compile, search
from os import environ

import flask

import opentelemetry.instrumentation.wsgi as otel_wsgi
from opentelemetry import configuration, context, propagators, trace
from opentelemetry import context, propagators, trace
from opentelemetry.instrumentation.flask.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.util import time_ns
Expand All @@ -65,7 +67,31 @@ def hello():
_ENVIRON_TOKEN = "opentelemetry-flask.token"


_excluded_urls = configuration.Configuration()._excluded_urls("flask")
class _ExcludeList:
"""Class to exclude certain paths (given as a list of regexes) from tracing requests"""

def __init__(self, excluded_urls):
self._excluded_urls = excluded_urls
if self._excluded_urls:
self._regex = re_compile("|".join(excluded_urls))

def url_disabled(self, url: str) -> bool:
return bool(self._excluded_urls and search(self._regex, url))


def _get_excluded_urls():
excluded_urls = environ.get("OTEL_PYTHON_FLASK_EXCLUDED_URLS", [])

if excluded_urls:
excluded_urls = [
excluded_url.strip()
for excluded_url in excluded_urls.split(",")
]

return _ExcludeList(excluded_urls)


_excluded_urls = _get_excluded_urls()


def get_default_span_name():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse

from opentelemetry.configuration import Configuration


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

@staticmethod
def _hello_endpoint(helloid):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from flask import Flask, request

from opentelemetry import trace
from opentelemetry.configuration import Configuration
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.flask import (
FlaskInstrumentor, _get_excluded_urls
)
from opentelemetry.test.test_base import TestBase
from opentelemetry.test.wsgitestutil import WsgiTestBase

Expand Down Expand Up @@ -63,7 +64,7 @@ def setUp(self):
self.env_patch.start()
self.exclude_patch = patch(
"opentelemetry.instrumentation.flask._excluded_urls",
Configuration()._excluded_urls("flask"),
_get_excluded_urls(),
)
self.exclude_patch.start()

Expand Down

0 comments on commit 4f20802

Please sign in to comment.