def get_flask_middleware(app): config_integration.trace_integrations(['requests']) exporter = _get_exporter() return FlaskMiddleware( app, sampler=opencensus.trace.tracer.samplers.AlwaysOnSampler(), exporter=exporter)
def createMiddleWare(exporter): middleware = FlaskMiddleware( app, exporter=exporter, propagator=propagator, sampler=AlwaysOnSampler()) return middleware
def createMiddleWare(app, exporter): # Configure a flask middleware that listens for each request and applies # automatic tracing. This needs to be set up before the application starts. middleware = FlaskMiddleware(app, exporter=exporter, propagator=propagator, sampler=AlwaysOnSampler()) return middleware
def enable_flask(self,flask_app,component_name="AppLogger"): """Enable flask for tracing For more info : https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py Args: flask_app ([type]): [description] component_name (str, optional): [description]. Defaults to "AppLogger". """ FlaskMiddleware( flask_app, exporter=self.get_log_exporter(component_name=component_name) )
def initialize_opencensus(config, flask_app): if config.opencensus_enable: agent = config.opencensus_agent print(f"OpenCensus enabled and reporting to {agent} using gRPC") exporter = ocagent_trace_exporter.TraceExporter(service_name=SERVICE_NAME, endpoint=agent) sampler = samplers.ProbabilitySampler(rate=config.opencensus_sample_rate) config_integration.trace_integrations(['sqlalchemy']) FlaskMiddleware(flask_app, exporter=exporter, sampler=sampler) flask_app.wsgi_app = SentryIoContextMiddleware(flask_app.wsgi_app) flask.before_render_template.connect(render_template_start, flask_app) flask.template_rendered.connect(render_template_end, flask_app)
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)
def prep_service(): exporter = AzureExporter(connection_string=AI_INSTRUMENTATION_KEY) exporter.add_telemetry_processor(add_cloud_role_name) _ = FlaskMiddleware(app=app, exporter=exporter, sampler=AlwaysOnSampler(), propagator=TraceContextPropagator()) handler = AzureLogHandler(connection_string=AI_INSTRUMENTATION_KEY) handler.add_telemetry_processor(add_cloud_role_name) for log, level in logging_instances: log.addHandler(handler) log.setLevel(level)
def _setup_azure_logging(logger: logging.Logger, app: Flask, connection_string: str): #:https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python #:param logger: Logging instance for azure opencensus stream handler. #:param app: Flask app instance for azure opencensus handler. #:param connection_string: Azure Application Insight connection string. # Setup trace handler. Handles normal logging output: # >>> logger.info("Info message") azure_handler = AzureLogHandler(connection_string=connection_string) logger.addHandler(azure_handler) FlaskMiddleware( app, exporter=AzureExporter(connection_string=connection_string), sampler=ProbabilitySampler(rate=1.0), )
def _setup_azure_logging(logger: logging.Logger, app: Flask, connection_string: str): """Setup logging into Azure Application Insights. :see: https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python :param logger: Logging instance to a ssign azure opencensus stream handler. :param app: Flask app instance to assing azure opencensus handler. :param connection_string: Azure Application Insight connection string. """ # Setup trace handler. Handles normal logging output: # >>> logger.info("Info message") azure_handler = AzureLogHandler( connection_string=connection_string ) logger.addHandler(azure_handler) # Setup flask middleware, so pageview metrics are stored in azure. FlaskMiddleware( app, exporter=AzureExporter(connection_string=connection_string), sampler=ProbabilitySampler(rate=1.0), )
envelope.tags['ai.cloud.role'] = PROJECT_NAME handler = AzureLogHandler( connection_string=AZURE_APP_INSIGHTS_CONN_STRING, export_interval=5.0, ) handler.add_telemetry_processor(__telemetry_processor) handler.setLevel(logging.DEBUG) app.logger.addHandler(handler) exporter = AzureExporter(connection_string=AZURE_APP_INSIGHTS_CONN_STRING) exporter.add_telemetry_processor(__telemetry_processor) FlaskMiddleware( app=app, sampler=AlwaysOnSampler(), exporter=exporter, ) csrf = CSRFProtect(app) # -- URLs/routes setup ------------------------------------------------------- app.add_url_rule('/login', 'login', login, methods=['GET', 'POST']) app.add_url_rule('/logout', 'logout', logout, methods=['GET']) app.add_url_rule('/consent', 'consent', consent, methods=['GET', 'POST']) app.add_url_rule('/register', 'register', register, methods=['GET', 'POST']) app.add_url_rule('/verify-email', 'verify-email', verify_email, methods=['GET'])
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=15d02af3-bb8b-48ab-937e-7f84588dfce0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=15d02af3-bb8b-48ab-937e-7f84588dfce0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/" ), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else:
from opencensus.stats import measure as measure_module from opencensus.stats import stats as stats_module from opencensus.stats import view as view_module from opencensus.tags import tag_map as tag_map_module from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.trace.samplers import ProbabilitySampler from opencensus.trace.tracer import Tracer from opencensus.ext.flask.flask_middleware import FlaskMiddleware app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= 'InstrumentationKey=a830027f-3b39-4371-8877-8ee0c3050e58'), sampler=ProbabilitySampler(rate=1.0), ) # TODO: Setup flask middleware # Logging logger = logging.getLogger(__name__) logger.addHandler( AzureLogHandler(connection_string= 'InstrumentationKey=a830027f-3b39-4371-8877-8ee0c3050e58')) # Metrics TODO: Setup exporter exporter = metrics_exporter.new_metrics_exporter( enable_standard_metrics=True, connection_string='InstrumentationKey=a830027f-3b39-4371-8877-8ee0c3050e58'
# Tracing #tracer = # TODO: Setup tracer tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey=d2989c85-e9da-4470-97b3-2c4186d9785f'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests #middleware = # TODO: Setup flask middleware middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey={guid}"), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else: button2 = app.config['VOTE2VALUE']
app.config.from_object(Config) db = SQLAlchemy(app) # Import here to avoid circular imports from app import routes # noqa isort:skip # Trace integrations for sqlalchemy library config_integration.trace_integrations(['sqlalchemy']) # Trace integrations for requests library config_integration.trace_integrations(['requests']) # FlaskMiddleware will track requests for the Flask application and send # request/dependency telemetry to Azure Monitor middleware = FlaskMiddleware(app) # Processor function for changing the role name of the app def callback_function(envelope): envelope.tags['ai.cloud.role'] = "To-Do App" return True # Adds the telemetry processor to the trace exporter middleware.exporter.add_telemetry_processor(callback_function) # Exporter for metrics, will send metrics data exporter = metrics_exporter.new_metrics_exporter( enable_standard_metrics=False, connection_string='InstrumentationKey=' + Config.INSTRUMENTATION_KEY) # Exporter for logs, will send logging data
import os import flask import requests exporter=trace_exporter.TraceExporter( service_name=os.getenv('SERVICE_NAME'), endpoint=os.getenv('COLLECTOR')) tracer = Tracer(sampler=AlwaysOnSampler(), exporter=exporter, propagator=B3FormatPropagator()) integration = ['requests'] config_integration.trace_integrations(integration) app = flask.Flask(__name__) middleware = FlaskMiddleware(app, exporter=exporter, sampler=AlwaysOnSampler(), propagator=B3FormatPropagator(), blacklist_paths=['_ah/health']) @app.route('/') def init(): with tracer.span(name='Initiate'): time.sleep(random.random()) with tracer.span(name='GetDataFromOutside'): response = requests.get(os.getenv('REMOTE_ENDPOINT')) with tracer.span(name='ProcessData'): time.sleep(random.random()) return 'OK' @app.route('/data') def data(): with tracer.span(name='ReturnData'): time.sleep(random.random())
PROJECT = os.environ.get('GCLOUD_PROJECT_PYTHON') # MySQL settings MYSQL_PASSWORD = os.environ.get('SYSTEST_MYSQL_PASSWORD') # PostgreSQL settings POSTGRES_PASSWORD = os.environ.get('SYSTEST_POSTGRES_PASSWORD') app = flask.Flask(__name__) # Enable tracing, send traces to Stackdriver Trace using background thread # transport. This is intentionally different from the Django system test which # is using sync transport to test both. middleware = FlaskMiddleware( app, exporter=stackdriver_exporter.StackdriverExporter( transport=async_.AsyncTransport, ), propagator=google_cloud_format.GoogleCloudFormatPropagator(), ) config_integration.trace_integrations(INTEGRATIONS) @app.route('/') def hello(): return 'hello' @app.route('/mysql') def mysql_query(): try: conn = mysql.connector.connect(host=DB_HOST, user='******',
enable_standard_metrics=True, connection_string='InstrumentationKey='+app_insught_intrumentation_key) # Tracing tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey='+app_insught_intrumentation_key), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey="+app_insught_intrumentation_key), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else: button2 = app.config['VOTE2VALUE']
#tracer = # TODO: Setup tracer tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=d1c291be-3bd7-4d5c-9eaa-618310979e86'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests #middleware = # TODO: Setup flask middleware middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=d1c291be-3bd7-4d5c-9eaa-618310979e86"), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else: button2 = app.config['VOTE2VALUE']
import os from flask import Flask # Import the Flask class from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace.samplers import ProbabilitySampler app = Flask(__name__) # Create an instance of the class for our use app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = os.getenv( 'APPINSIGHTS_INSTRUMENTATIONKEY') middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey=" + app.config['APPINSIGHTS_INSTRUMENTATIONKEY']), sampler=ProbabilitySampler(rate=1.0), )
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=75bbbb31-b712-4e5d-abc7-8eb89689ce08;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests # middleware = # TODO: Setup flask middleware middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=75bbbb31-b712-4e5d-abc7-8eb89689ce08;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/" ), sampler=ProbabilitySampler(rate=1.0)) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else:
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey=5e2837e6-5c38-4d77-9719-64e7f2d519a4'), sampler=ProbabilitySampler(1.0), ) # telemetry_client = TelemetryClient('5e2837e6-5c38-4d77-9719-64e7f2d519a4') app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string='InstrumentationKey=5e2837e6-5c38-4d77-9719-64e7f2d519a4'), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else:
# Metrics exporter = metrics_exporter.new_metrics_exporter(enable_standard_metrics=True, connection_string=CONN_STR) # Tracing tracer = Tracer( exporter=AzureExporter(connection_string=CONN_STR), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string=CONN_STR), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else: button2 = app.config['VOTE2VALUE']
Gauge('city_temp_san_fran_ca_us', 'Temperatures for San Francisco, CA, US '), 'Seattle, WA, US': Gauge('city_temp_seattle_wa_us', 'Temperatures for Seattle, WA, US'), 'New York, NY, US': Gauge('city_temp_new_york_ny_us', 'Temperatures for New York, NY, US') } if os.environ.get('ENABLE_TRACING', None) is not None: from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace import config_integration project = os.environ.get('PROJECT_ID') exporter = stackdriver_exporter.StackdriverExporter(project_id=project) middleware = FlaskMiddleware(app, exporter=exporter) config_integration.trace_integrations(["requests"]) @app.route('/api/weather', methods=['GET']) def current_weather(): ret = [] mgr = owm.weather_manager() for city, metric in city_metric.items(): obs = mgr.weather_at_place(city) w = obs.weather temp = w.temperature('fahrenheit') conditions = { 'location': city,
enable_standard_metrics=True, connection_string='InstrumentationKey=ee6147a6-6162-463a-a119-bfeaff3147f6') # Tracing tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey=ee6147a6-6162-463a-a119-bfeaff3147f6'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey=ee6147a6-6162-463a-a119-bfeaff3147f6"), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else: button2 = app.config['VOTE2VALUE']
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=3d3e7bec-d2e0-41b6-b690-7c9cb2020fc2'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=3d3e7bec-d2e0-41b6-b690-7c9cb2020fc2"), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else:
if environment.in_gae(): SQLAlchemyEngineManager.init_engines_for_server_postgres_instances() # Export traces and metrics to stackdriver if running on GAE if environment.in_gae(): monitoring.register_stackdriver_exporter() trace_exporter = stackdriver_trace.StackdriverExporter( project_id=metadata.project_id(), transport=AsyncTransport) trace_sampler = samplers.ProbabilitySampler(rate=0.05) # Default is 1 in 10k, trace 1 in 20 instead else: trace_exporter = file_exporter.FileExporter(file_name='traces') trace_sampler = samplers.AlwaysOnSampler() middleware = FlaskMiddleware( app, blacklist_paths=['metadata'], # Don't trace metadata requests sampler=trace_sampler, exporter=trace_exporter, propagator=google_cloud_format.GoogleCloudFormatPropagator()) config_integration.trace_integrations([ # TODO(#4283): The 'google_cloud_clientlibs' integration is currently not compatible with the 'proto-plus' objects # used by the 2.0.0 versions of the client libraries. Investigate best way to hydrate spans in traces for these # calls in the future. 'google_cloud_clientlibs', 'requests', 'sqlalchemy' ]) @zope.event.classhandler.handler(events.MemoryUsageThresholdExceeded) def memory_condition_handler(event: events.MemoryUsageThresholdExceeded) -> None: logging.warning("Memory usage %d is more than limit of %d, forcing gc", event.mem_usage, event.max_allowed)
"/direct/process_job": samplers.AlwaysOnSampler(), # There are a lot of scraper requests, so they can use the default rate of 1 in 10k. "/scraper/": samplers.ProbabilitySampler(), "/scrape_aggregate_reports/": samplers.ProbabilitySampler(), }, # For other requests, trace 1 in 20. default_sampler=samplers.ProbabilitySampler(rate=0.05), ) else: trace_exporter = file_exporter.FileExporter(file_name="traces") trace_sampler = samplers.AlwaysOnSampler() middleware = FlaskMiddleware( app, excludelist_paths=["metadata", "computeMetadata"], # Don't trace metadata requests sampler=trace_sampler, exporter=trace_exporter, propagator=google_cloud_format.GoogleCloudFormatPropagator(), ) config_integration.trace_integrations( [ # TODO(#4283): The 'google_cloud_clientlibs' integration is currently not compatible with the # 'proto-plus' objects used by the 2.0.0 versions of the client libraries. Investigate best way to hydrate # spans in traces for these calls in the future. "google_cloud_clientlibs", "requests", "sqlalchemy", ] )
# MySQL settings MYSQL_PASSWORD = os.environ.get('SYSTEST_MYSQL_PASSWORD') # PostgreSQL settings POSTGRES_PASSWORD = os.environ.get('SYSTEST_POSTGRES_PASSWORD') # hello_world_server location HELLO_WORLD_HOST_PORT = 'localhost:50051' app = flask.Flask(__name__) # Enable tracing, configure the trace params, send traces to Stackdriver Trace exporter = stackdriver_exporter.StackdriverExporter() sampler = samplers.ProbabilitySampler(rate=1) middleware = FlaskMiddleware(app, exporter=exporter, sampler=sampler) config_integration.trace_integrations(INTEGRATIONS) # cache of (stub_cls, hostport) -> grpc stub _stub_cache = {} @app.route('/') def hello(): return 'Hello world!' @app.route('/requests') def trace_requests(): response = requests.get('http://www.google.com') return str(response.status_code)
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=bdba70b7-8e6e-4adb-adb5-8fd02df32aea;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=bdba70b7-8e6e-4adb-adb5-8fd02df32aea;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/" ), sampler=ProbabilitySampler(rate=1.0), ) # Load configurations from environment or config file app.config.from_pyfile('config_file.cfg') if ("VOTE1VALUE" in os.environ and os.environ['VOTE1VALUE']): button1 = os.environ['VOTE1VALUE'] else: button1 = app.config['VOTE1VALUE'] if ("VOTE2VALUE" in os.environ and os.environ['VOTE2VALUE']): button2 = os.environ['VOTE2VALUE'] else:
import requests from flask import Flask from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace import config_integration from opencensus.trace.samplers import ProbabilitySampler # TODO: you need to specify the instrumentation key in a connection string # and place it in the APPLICATIONINSIGHTS_CONNECTION_STRING # environment variable. app = Flask(__name__) middleware = FlaskMiddleware( app, exporter=AzureExporter(), sampler=ProbabilitySampler(rate=1.0), ) @app.route('/') def hello(): requests.get('https://www.wikipedia.org/wiki/Rabbit') return 'Hello, World!' if __name__ == '__main__': import logging logger = logging.getLogger('werkzeug') logger.setLevel(logging.ERROR) config_integration.trace_integrations(['requests'])