def activate_application(self, app_name, linked_applications=[], timeout=None): """Initiates activation for the named application if this has not been done previously. If an attempt to trigger the activation of the application has already been performed, whether or not that has completed, calling this again will have no affect. The list of linked applications is the additional applications to which data should also be reported in addition to the primary application. The timeout is how long to wait for the initial connection. The timeout only applies the first time a specific named application is being activated. The timeout would be used by test harnesses and can't really be used by activation of application for first request because it could take a second or more for initial handshake to get back configuration settings for application. """ if not self._config.enabled: return # If timeout not supplied then use default from the global # configuration. Note that the timeout only applies on the first # call to activate the application. settings = newrelic.core.config.global_settings() if timeout is None: timeout = settings.startup_timeout activate_session = False with self._lock: application = self._applications.get(app_name, None) if not application: if settings.debug.log_agent_initialization: _logger.info('Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.info('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) else: _logger.debug('Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.debug('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) linked_applications = sorted(set(linked_applications)) application = newrelic.core.application.Application( app_name, linked_applications) self._applications[app_name] = application activate_session = True # Register any data sources with the application. for source, name, settings, properties in \ self._data_sources.get(None, []): application.register_data_source(source, name, settings, **properties) for source, name, settings, properties in \ self._data_sources.get(app_name, []): application.register_data_source(source, name, settings, **properties) else: # Do some checks to see whether try to reactivate the # application in a different process to what it was # originally activated in. application.validate_process() # Activate the session if application was just created and wait # for session activation if a timeout was specified. This may # bail out early if is detected that a deadlock may occur for # the period of the timeout. if activate_session: application.activate_session(timeout)
def activate_application(self, app_name, linked_applications=[], timeout=None, uninstrumented_modules=None): """Initiates activation for the named application if this has not been done previously. If an attempt to trigger the activation of the application has already been performed, whether or not that has completed, calling this again will have no affect. The list of linked applications is the additional applications to which data should also be reported in addition to the primary application. The timeout is how long to wait for the initial connection. The timeout only applies the first time a specific named application is being activated. The timeout would be used by test harnesses and can't really be used by activation of application for first request because it could take a second or more for initial handshake to get back configuration settings for application. """ if not self._config.enabled: return # If timeout not supplied then use default from the global # configuration. Note that the timeout only applies on the first # call to activate the application. settings = newrelic.core.config.global_settings() if timeout is None: # In serverless mode, we should always wait for startup since it # should take almost no time to create the session (no network # activity). if settings.serverless_mode.enabled: timeout = 10.0 else: timeout = settings.startup_timeout activate_session = False with self._lock: application = self._applications.get(app_name, None) if not application: process_id = os.getpid() if process_id != self._process_id: _logger.warning( 'Attempt to activate application in a process ' 'different to where the agent harvest thread was ' 'started. No data will be reported for this ' 'process with pid of %d. Creation of the harvest ' 'thread this application occurred in process with ' 'pid %d. If no data at all is being reported for ' 'your application, see ' 'https://docs.newrelic.com/docs/agents/' 'python-agent/troubleshooting/' 'activate-application-warning-python ' 'for troubleshooting steps. If the issue ' 'persists, please send debug logs to New Relic ' 'support for assistance.', process_id, self._process_id) if settings.debug.log_agent_initialization: _logger.info( 'Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.info('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) else: _logger.debug( 'Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.debug('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) linked_applications = sorted(set(linked_applications)) application = newrelic.core.application.Application( app_name, linked_applications) application._uninstrumented = uninstrumented_modules self._applications[app_name] = application activate_session = True # Register any data sources with the application. for source, name, settings, properties in \ self._data_sources.get(None, []): application.register_data_source(source, name, settings, **properties) for source, name, settings, properties in \ self._data_sources.get(app_name, []): application.register_data_source(source, name, settings, **properties) else: # Do some checks to see whether try to reactivate the # application in a different process to what it was # originally activated in. application.validate_process() # Activate the session if application was just created and wait # for session activation if a timeout was specified. This may # bail out early if is detected that a deadlock may occur for # the period of the timeout. if activate_session: application.activate_session(self.activate_agent, timeout)
def activate_application(self, app_name, linked_applications=[], timeout=None): """Initiates activation for the named application if this has not been done previously. If an attempt to trigger the activation of the application has already been performed, whether or not that has completed, calling this again will have no affect. The list of linked applications is the additional applications to which data should also be reported in addition to the primary application. The timeout is how long to wait for the initial connection. The timeout only applies the first time a specific named application is being activated. The timeout would be used by test harnesses and can't really be used by activation of application for first request because it could take a second or more for initial handshake to get back configuration settings for application. """ if not self._config.enabled: return # If timeout not supplied then use default from the global # configuration. Note that the timeout only applies on the first # call to activate the application. settings = newrelic.core.config.global_settings() if timeout is None: timeout = settings.startup_timeout activate_session = False with self._lock: application = self._applications.get(app_name, None) if not application: if settings.debug.log_agent_initialization: _logger.info( 'Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.info('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) else: _logger.debug( 'Creating application instance for %r ' 'in process %d.', app_name, os.getpid()) _logger.debug('Application was activated from: %r', ''.join(traceback.format_stack()[:-1])) linked_applications = sorted(set(linked_applications)) application = newrelic.core.application.Application( app_name, linked_applications) self._applications[app_name] = application activate_session = True # Register any data sources with the application. for source, name, settings, properties in \ self._data_sources.get(None, []): application.register_data_source(source, name, settings, **properties) for source, name, settings, properties in \ self._data_sources.get(app_name, []): application.register_data_source(source, name, settings, **properties) else: # Do some checks to see whether try to reactivate the # application in a different process to what it was # originally activated in. application.validate_process() # Activate the session if application was just created and wait # for session activation if a timeout was specified. This may # bail out early if is detected that a deadlock may occur for # the period of the timeout. if activate_session: application.activate_session(timeout)