Exemplo n.º 1
0
 def __init__(self,
              *,
              plugin_executor=None,
              api_key=None,
              disable_trace=False,
              disable_metric=True,
              disable_log=True,
              opts=None,
              **ignored):
     super(TestWrapper, self).__init__(api_key, disable_trace,
                                       disable_metric, disable_log, opts)
     ExecutionContextManager.set_provider(
         TracingExecutionContextProvider())  #TODO
     self.application_info_provider = GlobalApplicationInfoProvider()
     self._set_application_info("Foresight", "TestSuite", "TestSuite")
     self.plugin_context = PluginContext(
         application_info=self.application_info_provider.
         get_application_info(),
         request_count=0,
         executor=plugin_executor,
         api_key=self.api_key)
     max_test_log_count = ConfigProvider.get(
         config_names.THUNDRA_TEST_LOG_COUNT_MAX)
     self.config.log_config = LogConfig(
         sampler=MaxCountAwareSampler(max_test_log_count))
     self.plugins = wrapper_utils.initialize_plugins(self.plugin_context,
                                                     disable_trace,
                                                     disable_metric,
                                                     disable_log,
                                                     config=self.config)
     TestWrapper.__instance = self
Exemplo n.º 2
0
    def __init__(self,
                 api_key=None,
                 disable_trace=False,
                 disable_metric=True,
                 disable_log=True,
                 opts=None):
        super(TornadoWrapper, self).__init__(api_key, disable_trace,
                                             disable_metric, disable_log, opts)
        self.application_info_provider = GlobalApplicationInfoProvider()
        ExecutionContextManager.set_provider(TracingExecutionContextProvider())
        self.plugin_context = PluginContext(
            application_info=self.application_info_provider.
            get_application_info(),
            request_count=0,
            executor=tornado_executor,
            api_key=self.api_key)

        self.plugins = wrapper_utils.initialize_plugins(self.plugin_context,
                                                        disable_trace,
                                                        disable_metric,
                                                        disable_log,
                                                        config=self.config)

        web_wrapper_utils.update_application_info(
            self.application_info_provider,
            self.plugin_context.application_info,
            constants.ClassNames['TORNADO'])
Exemplo n.º 3
0
    def mock_before_request(self, request, req_body):
        ExecutionContextManager.set_provider(TracingExecutionContextProvider())
        execution_context = wrapper_utils.create_execution_context()
        execution_context.platform_data["request"] = request
        execution_context.platform_data["request"]["body"] = req_body

        self.plugin_context.request_count += 1
        self.execute_hook("before:invocation", execution_context)

        assert execution_context.root_span.operation_name == '/1'
        assert execution_context.root_span.get_tag('http.method') == 'GET'
        assert execution_context.root_span.get_tag('http.host') == 'testserver'
        assert execution_context.root_span.get_tag('http.query_params') == b''
        assert execution_context.root_span.get_tag('http.path') == '/1'
        assert execution_context.root_span.class_name == constants.ClassNames[
            'FASTAPI']
        assert execution_context.root_span.domain_name == 'API'

        return execution_context
Exemplo n.º 4
0
    def __init__(self, api_key=None, disable_trace=False, disable_metric=True, disable_log=True, opts=None):
        try:
            from django.conf import settings
            django_settings = getattr(settings, 'THUNDRA', None)
            if django_settings is not None:
                configure({'config': django_settings})
        except:
            pass

        super(DjangoWrapper, self).__init__(api_key, disable_trace, disable_metric, disable_log, opts)
        self.application_info_provider = GlobalApplicationInfoProvider()
        ExecutionContextManager.set_provider(TracingExecutionContextProvider())
        self.plugin_context = PluginContext(application_info=self.application_info_provider.get_application_info(),
                                            request_count=0,
                                            executor=django_executor,
                                            api_key=self.api_key)

        self.plugins = wrapper_utils.initialize_plugins(self.plugin_context, disable_trace, disable_metric, disable_log,
                                                        config=self.config)

        web_wrapper_utils.update_application_info(self.application_info_provider, self.plugin_context.application_info,
                                                  constants.ClassNames['DJANGO'])
Exemplo n.º 5
0
    def __init__(self,
                 api_key=None,
                 disable_trace=False,
                 disable_metric=True,
                 disable_log=True,
                 opts=None):
        super(LambdaWrapper, self).__init__(api_key, disable_trace,
                                            disable_metric, disable_log, opts)
        self.application_info_provider = GlobalApplicationInfoProvider(
            LambdaApplicationInfoProvider())
        self.plugin_context = PluginContext(
            application_info=self.application_info_provider.
            get_application_info(),
            request_count=0,
            executor=lambda_executor,
            api_key=self.api_key)

        ExecutionContextManager.set_provider(GlobalExecutionContextProvider())
        self.plugins = wrapper_utils.initialize_plugins(
            self.plugin_context, disable_trace, disable_metric, disable_log,
            self.config)

        self.timeout_margin = ConfigProvider.get(
            config_names.THUNDRA_LAMBDA_TIMEOUT_MARGIN,
            constants.DEFAULT_LAMBDA_TIMEOUT_MARGIN)

        if not ConfigProvider.get(
                config_names.THUNDRA_TRACE_INSTRUMENT_DISABLE):
            # Pass thundra instance to integration for wrapping handler wrappers
            handler_wrappers.patch_modules(self)

        self.ptvsd_imported = False
        if ConfigProvider.get(
                config_names.THUNDRA_LAMBDA_DEBUGGER_ENABLE,
                ConfigProvider.get(
                    config_names.THUNDRA_LAMBDA_DEBUGGER_AUTH_TOKEN)):
            self.initialize_debugger()
Exemplo n.º 6
0
def set_execution_context_provider():
    ExecutionContextManager.set_provider(GlobalExecutionContextProvider())