def _disable_trace(url): excluded_hosts = configuration.Configuration().FLASK_EXCLUDED_HOSTS excluded_paths = configuration.Configuration().FLASK_EXCLUDED_PATHS if excluded_hosts: excluded_hosts = str.split(excluded_hosts, ",") if disable_tracing_hostname(url, excluded_hosts): return True if excluded_paths: excluded_paths = str.split(excluded_paths, ",") if disable_tracing_path(url, excluded_paths): return True return False
def get_traced_request_attrs(): attrs = configuration.Configuration().TORNADO_TRACED_REQUEST_ATTRS or "" if attrs: attrs = [attr.strip() for attr in attrs.split(",")] else: attrs = [] return attrs
def get_excluded_urls(): urls = configuration.Configuration().TORNADO_EXCLUDED_URLS or "" if urls: urls = str.split(urls, ",") return ExcludeList(urls)
def get_excluded_urls(): urls = configuration.Configuration().FLASK_EXCLUDED_URLS or [] if urls: urls = str.split(urls, ",") return ExcludeList(urls)
def get_excluded_paths(): paths = configuration.Configuration().FLASK_EXCLUDED_PATHS or [] if paths: paths = str.split(paths, ",") return paths
def get_excluded_hosts(): hosts = configuration.Configuration().FLASK_EXCLUDED_HOSTS or [] if hosts: hosts = str.split(hosts, ",") return hosts
import opentelemetry.instrumentation.wsgi as otel_wsgi from opentelemetry import configuration, context, propagators, trace from opentelemetry.instrumentation.flask.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.util import time_ns _logger = getLogger(__name__) _ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key" _ENVIRON_SPAN_KEY = "opentelemetry-flask.span_key" _ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key" _ENVIRON_TOKEN = "opentelemetry-flask.token" _excluded_urls = configuration.Configuration()._excluded_urls("flask") def get_default_span_name(): span_name = "" try: span_name = flask.request.url_rule.rule except AttributeError: span_name = otel_wsgi.get_default_span_name(flask.request.environ) return span_name def _rewrapped_app(wsgi_app): def _wrapped_app(environ, start_response): # We want to measure the time for route matching, etc. # In theory, we could start the span here and use
from opentelemetry import configuration, context, propagators, trace from opentelemetry.instrumentation.pyramid.version import __version__ from opentelemetry.util import time_ns TWEEN_NAME = "opentelemetry.instrumentation.pyramid.trace_tween_factory" SETTING_TRACE_ENABLED = "opentelemetry-pyramid.trace_enabled" _ENVIRON_STARTTIME_KEY = "opentelemetry-pyramid.starttime_key" _ENVIRON_SPAN_KEY = "opentelemetry-pyramid.span_key" _ENVIRON_ACTIVATION_KEY = "opentelemetry-pyramid.activation_key" _ENVIRON_ENABLED_KEY = "opentelemetry-pyramid.tracing_enabled_key" _ENVIRON_TOKEN = "opentelemetry-pyramid.token" _logger = getLogger(__name__) _excluded_urls = configuration.Configuration()._excluded_urls("pyramid") def includeme(config): config.add_settings({SETTING_TRACE_ENABLED: True}) config.add_subscriber(_before_traversal, BeforeTraversal) _insert_tween(config) def _insert_tween(config): settings = config.get_settings() tweens = settings.get("pyramid.tweens") # If the list is empty, pyramid does not consider the tweens have been # set explicitly. And if our tween is already there, nothing to do if not tweens or not tweens.strip():
extract_attributes_from_object, http_status_to_status_code, unwrap, ) from opentelemetry.trace.propagation.textmap import DictGetter from opentelemetry.trace.status import Status from opentelemetry.util import time_ns from .client import fetch_async # pylint: disable=E0401 _logger = getLogger(__name__) _TraceContext = namedtuple("TraceContext", ["activation", "span", "token"]) _HANDLER_CONTEXT_KEY = "_otel_trace_context_key" _OTEL_PATCHED_KEY = "_otel_patched_key" cfg = configuration.Configuration() _excluded_urls = cfg._excluded_urls("tornado") _traced_attrs = cfg._traced_request_attrs("tornado") carrier_getter = DictGetter() class TornadoInstrumentor(BaseInstrumentor): patched_handlers = [] original_handler_new = None def _instrument(self, **kwargs): """ _instrument patches tornado.web.RequestHandler and tornado.httpclient.AsyncHTTPClient classes to automatically instrument requests both received and sent by Tornado.