Beispiel #1
0
    def __init__(self, get_response=None):
        self.get_response = get_response
        settings = getattr(django.conf.settings, 'OPENCENSUS', {})
        settings = settings.get('TRACE', {})

        self.sampler = (settings.get('SAMPLER', None)
                        or samplers.ProbabilitySampler())
        if isinstance(self.sampler, six.string_types):
            self.sampler = configuration.load(self.sampler)

        self.exporter = settings.get('EXPORTER', None) or \
            print_exporter.PrintExporter()
        if isinstance(self.exporter, six.string_types):
            self.exporter = configuration.load(self.exporter)

        self.propagator = settings.get('PROPAGATOR', None) or \
            trace_context_http_header_format.TraceContextPropagator()
        if isinstance(self.propagator, six.string_types):
            self.propagator = configuration.load(self.propagator)

        self.excludelist_paths = settings.get(EXCLUDELIST_PATHS, None)

        self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None)

        if django.VERSION >= (2,):  # pragma: NO COVER
            connection.execute_wrappers.append(_trace_db_call)

        # pylint: disable=protected-access
        integrations.add_integration(integrations._Integrations.DJANGO)
Beispiel #2
0
    def init_app(self, app):
        self.app = app

        # get settings from app config
        settings = self.app.config.get('OPENCENSUS', {})
        settings = settings.get('TRACE', {})

        if self.sampler is None:
            self.sampler = (settings.get('SAMPLER', None)
                            or samplers.ProbabilitySampler())
            if isinstance(self.sampler, six.string_types):
                self.sampler = configuration.load(self.sampler)

        if self.exporter is None:
            self.exporter = settings.get('EXPORTER', None) or \
                print_exporter.PrintExporter()
            if isinstance(self.exporter, six.string_types):
                self.exporter = configuration.load(self.exporter)

        if self.propagator is None:
            self.propagator = settings.get('PROPAGATOR', None) or \
                trace_context_http_header_format.TraceContextPropagator()
            if isinstance(self.propagator, six.string_types):
                self.propagator = configuration.load(self.propagator)

        self.excludelist_paths = settings.get(EXCLUDELIST_PATHS,
                                              self.excludelist_paths)

        self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None)

        self.setup_trace()

        # pylint: disable=protected-access
        integrations.add_integration(integrations._Integrations.FLASK)
def trace_integration(tracer=None):
    """Wrap the mysql connector to trace it."""
    log.info('Integrated module: {}'.format(MODULE_NAME))
    conn_func = getattr(psycopg2, CONN_WRAP_METHOD)
    conn_module = inspect.getmodule(conn_func)
    setattr(conn_module, conn_func.__name__, connect)
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.POSTGRESQL)
def trace_integration(tracer=None):
    """Wrap the mysql connector to trace it."""
    logging.info('Integrated module: {}'.format(MODULE_NAME))
    conn_func = getattr(mysql.connector, CONN_WRAP_METHOD)
    conn_module = inspect.getmodule(conn_func)
    wrapped = trace.wrap_conn(conn_func)
    setattr(conn_module, CONN_WRAP_METHOD, wrapped)
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.MYSQL)
def trace_integration(tracer=None):
    """Integrate with SQLAlchemy to trace it using event listener.

    See: http://docs.sqlalchemy.org/en/latest/core/events.html
    """
    log.info('Integrated module: {}'.format(MODULE_NAME))
    trace_engine(engine.Engine)
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.SQLALCHEMY)
def trace_integration(tracer=None):
    """Replace the global default logging class with `TraceLogger`.

    Loggers created after the integration will produce `LogRecord`s
    with extra traceId, spanId, and traceSampled attributes from the opencensus
    context.
    """
    logging.setLoggerClass(TraceLogger)
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.LOGGING)
Beispiel #7
0
def trace_integration(tracer=None):
    """Trace the Google Cloud Client libraries by integrating with
    the transport level including HTTP and gRPC.
    """
    log.info('Integrated module: {}'.format(MODULE_NAME))

    # Integrate with gRPC
    trace_grpc(tracer)

    # Integrate with HTTP
    trace_http(tracer)

    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.GOOGLE_CLOUD)
def trace_integration(tracer=None):
    """Wrap the httplib to trace."""
    log.info('Integrated module: {}'.format(MODULE_NAME))

    # Wrap the httplib request function
    request_func = getattr(httplib.HTTPConnection, HTTPLIB_REQUEST_FUNC)
    wrapped_request = wrap_httplib_request(request_func)
    setattr(httplib.HTTPConnection, request_func.__name__, wrapped_request)

    # Wrap the httplib response function
    response_func = getattr(httplib.HTTPConnection, HTTPLIB_RESPONSE_FUNC)
    wrapped_response = wrap_httplib_response(response_func)
    setattr(httplib.HTTPConnection, response_func.__name__, wrapped_response)

    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.HTTP_LIB)
Beispiel #9
0
def trace_integration(tracer=None):
    """Wrap the requests library to trace it."""
    log.info('Integrated module: {}'.format(MODULE_NAME))

    if tracer is not None:
        # The execution_context tracer should never be None - if it has not
        # been set it returns a no-op tracer. Most code in this library does
        # not handle None being used in the execution context.
        execution_context.set_opencensus_tracer(tracer)

    # Wrap Session class
    # Since
    # https://github.com/psf/requests/commit/d72d1162142d1bf8b1b5711c664fbbd674f349d1
    # (v0.7.0, Oct 23, 2011), get, post, etc are implemented via request which
    # again, is implemented via Session.request (`Session` was named `session`
    # before v1.0.0, Dec 17, 2012, see
    # https://github.com/psf/requests/commit/4e5c4a6ab7bb0195dececdd19bb8505b872fe120)
    wrapt.wrap_function_wrapper(MODULE_NAME, 'Session.request',
                                wrap_session_request)
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.REQUESTS)
    def __init__(self, handler, registry):
        """Constructor for the pyramid tween

        :param handler: Either the main Pyramid request handling
        function or another tween
        :type handler: function
        :param registry: The pyramid application registry
        :type registry: :class:`pyramid.registry.Registry`
        """
        self.handler = handler
        self.registry = registry
        settings = PyramidTraceSettings(registry)

        self.sampler = settings.SAMPLER
        self.exporter = settings.EXPORTER
        self.propagator = settings.PROPAGATOR

        self._excludelist_paths = settings.EXCLUDELIST_PATHS

        # pylint: disable=protected-access
        integrations.add_integration(integrations._Integrations.PYRAMID)
Beispiel #11
0
def trace_integration(tracer=None):
    """Integrate with pymongo to trace it using event listener."""
    log.info('Integrated module: {}'.format(MODULE_NAME))
    monitoring.register(MongoCommandListener(tracer=tracer))
    # pylint: disable=protected-access
    integrations.add_integration(integrations._Integrations.PYMONGO)