def __init__(self, flask_app, logger): self.app = flask_app self.log = logger self.api = Api(self.app) self.is_terminating = False self.func_properties = {} self.func_request_counts = {} self.api_prefix = getenv("API_PREFIX") self.tracer = None if not isinstance(self.log, AI4EAppInsights): self.tracer = self.log.tracer self.api_task_manager = TaskManager() signal.signal(signal.SIGINT, self.initialize_term) # Add health check endpoint self.app.add_url_rule( self.api_prefix + "/", view_func=self.health_check, methods=["GET"] ) print("Adding url rule: " + self.api_prefix + "/") # Add task endpoint self.api.add_resource( Task, self.api_prefix + "/task/<id>", resource_class_kwargs={"task_manager": self.api_task_manager}, ) print("Adding url rule: " + self.api_prefix + "/task/<int:taskId>") self.app.before_request(self.before_request)
def __init__(self, flask_app, logger): self.app = flask_app self.log = logger self.api = Api(self.app) self.appinsights = AppInsights(self.app) self.is_terminating = False self.func_properties = {} self.func_request_counts = {} self.api_prefix = getenv('API_PREFIX') self.api_task_manager = TaskManager() signal.signal(signal.SIGINT, self.initialize_term) # Add health check endpoint self.app.add_url_rule(self.api_prefix + '/', view_func=self.health_check, methods=['GET']) print("Adding url rule: " + self.api_prefix + '/') # Add task endpoint self.api.add_resource( Task, self.api_prefix + '/task/<int:id>', resource_class_kwargs={'task_manager': self.api_task_manager}) print("Adding url rule: " + self.api_prefix + '/task/<int:taskId>') self.app.before_request(self.before_request)
def __init__(self, flask_app, logger): self.app = flask_app self.log = logger self.api = Api(self.app) self.is_terminating = False self.func_properties = {} self.func_request_counts = {} self.api_prefix = getenv('API_PREFIX') self.tracer = None self.api_task_manager = TaskManager() signal.signal(signal.SIGINT, self.initialize_term) # Add health check endpoint self.app.add_url_rule(self.api_prefix + '/', view_func=self.health_check, methods=['GET']) print("Adding url rule: " + self.api_prefix + '/') # Add task endpoint self.api.add_resource( Task, self.api_prefix + '/task/<id>', resource_class_kwargs={'task_manager': self.api_task_manager}) print("Adding url rule: " + self.api_prefix + '/task/<int:taskId>') if getenv('APPINSIGHTS_INSTRUMENTATIONKEY', None): azure_exporter = AzureExporter( connection_string='InstrumentationKey=' + str(getenv('APPINSIGHTS_INSTRUMENTATIONKEY')), timeout=getenv('APPINSIGHTS_TIMEOUT', 30.0)) sampling_rate = getenv('TRACE_SAMPLING_RATE', None) if not sampling_rate: sampling_rate = 1.0 self.middleware = FlaskMiddleware( self.app, exporter=azure_exporter, sampler=ProbabilitySampler(rate=float(sampling_rate)), ) self.tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey=' + str(getenv('APPINSIGHTS_INSTRUMENTATIONKEY')), timeout=getenv('APPINSIGHTS_TIMEOUT', 30.0)), sampler=ProbabilitySampler(rate=float(sampling_rate)), ) self.app.before_request(self.before_request)