def __init__(self, logger, flask_app=None): self._properties = { "service_name": getenv(CONF_SERVICE_NAME), "service_version": getenv(CONF_SERVICE_VERSION), "service_cluster": getenv(CONF_SERVICE_CLUSTER), "service_model_name": getenv(CONF_SERVICE_MODEL_NAME), "service_model_version": getenv(CONF_SERVICE_MODEL_VERSION), "service_container_version": getenv(CONF_SERVICE_CONTAINER_VERSION), "service_container_name": getenv(CONF_SERVICE_CONTAINER_NAME), "task_id": "none", } self.logger = logger self.metrics = {} self.tracer = None self.appinsights_key = getenv("APPINSIGHTS_INSTRUMENTATIONKEY", None) if self.appinsights_key: try: print("Setting up Azure Monitor with Application Insights.") config_integration.trace_integrations(["logging"]) # self.logger = logging.getLogger(getenv(CONF_SERVICE_NAME)) self.logger.setLevel(logging.INFO) handler = AzureLogHandler( connection_string="InstrumentationKey=" + self.appinsights_key) self.logger.addHandler(handler) self.azure_exporter = AzureExporter( connection_string="InstrumentationKey=" + self.appinsights_key, timeout=getenv("APPINSIGHTS_TIMEOUT", 30.0), ) sampling_rate = getenv("TRACE_SAMPLING_RATE", None) if not sampling_rate: sampling_rate = 1.0 self.middleware = None if flask_app: self.middleware = FlaskMiddleware( flask_app, exporter=self.azure_exporter, sampler=ProbabilitySampler(rate=float(sampling_rate)), ) # self.tracer = Tracer( # exporter=self.azure_exporter, # sampler=ProbabilitySampler(rate=float(sampling_rate)), # ) self.tracer = Tracer(exporter=self.azure_exporter, sampler=AlwaysOnSampler()) self.metrics_exporter = metrics_exporter.new_metrics_exporter( connection_string="InstrumentationKey=" + self.appinsights_key) stats = stats_module.stats self.view_manager = stats.view_manager self.view_manager.register_exporter(self.metrics_exporter) self.stats_recorder = stats.stats_recorder except Exception as e: print("Exception in setting up the Azure Monitor:") print(e)
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
# 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:
import json from flask import Flask, render_template app = Flask(__name__) app.secret_key = '3c0716f88780d6d642330dfa3c96dbca' # md5 -s incremental-istio 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) exporter = stackdriver_exporter.StackdriverExporter() middleware = FlaskMiddleware(app, exporter=exporter) config_integration.trace_integrations(["requests"]) BASE_URL = 'http://{hostport}'.format( hostport=os.environ.get('BACKEND_HOSTPORT', 'localhost:5000')) @app.route('/', methods=['GET']) def index(): resp = requests.get(BASE_URL + '/api/weather') if resp.status_code is not 200: return render_template('index.html', cities=[], code=resp.status_code, msg=resp.text)
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=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']
# 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)
enable_standard_metrics=True, connection_string='InstrumentationKey=7c5b861a-1af8-4bbd-9488-c03ca464102c') # Tracing tracer = Tracer( exporter=AzureExporter( connection_string='InstrumentationKey=7c5b861a-1af8-4bbd-9488-c03ca464102c'), sampler=ProbabilitySampler(1.0) ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey=7c5b861a-1af8-4bbd-9488-c03ca464102c"), 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']
# Metrics exporter = metrics_exporter.new_metrics_exporter( enable_standard_metrics=True, connection_string=instrumentation_key) # Tracing tracer = Tracer( exporter=AzureExporter(connection_string=instrumentation_key), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string=instrumentation_key), sampler=ProbabilitySampler(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']
from flask_restful import reqparse, abort, Api, Resource from threading import Lock from tenacity import * from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace.samplers import ProbabilitySampler import logging # Initialize Flask app = Flask(__name__) # Setup Azure Monitor if 'APPINSIGHTS_KEY' in os.environ: middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey={0}".format(os.environ['APPINSIGHTS_KEY'])), sampler=ProbabilitySampler(rate=1.0), ) # Setup Flask Restful framework api = Api(app) parser = reqparse.RequestParser() parser.add_argument('customer') # Implement singleton to avoid global objects class ConnectionManager(object): __instance = None __connection = None __lock = Lock() def __new__(cls):
(os.environ["SENTRY_KEY"], os.environ["SENTRY_PROJECT"]), integrations=[FlaskIntegration()]) _LOG.info("Sentry logging enabled") app = Flask(__name__.split('.')[0]) RequestID(app) tracer = None if opencensus_tracing_enabled(): from opencensus.trace import config_integration from opencensus.ext.flask.flask_middleware import FlaskMiddleware tracer = get_opencensus_tracer() integration = ['sqlalchemy'] config_integration.trace_integrations(integration, tracer=tracer) jaegerExporter = get_jaeger_exporter() middleware = FlaskMiddleware(app, exporter=jaegerExporter) _LOG.info("Opencensus tracing enabled") # If invoked using Gunicorn, link our root logger to the gunicorn logger # this will mean the root logs will be captured and managed by the gunicorn logger # allowing you to set the gunicorn log directories and levels for logs # produced by this application _LOG.setLevel(logging.getLogger('gunicorn.error').getEffectiveLevel()) if os.environ.get("prometheus_multiproc_dir", False): from datacube_ows.metrics.prometheus import setup_prometheus setup_prometheus(app) _LOG.info("Prometheus metrics enabled") if os.environ.get("AWS_DEFAULT_REGION"): set_default_rio_config(aws=dict(aws_unsigned=True, region_name="auto"),
enable_standard_metrics=True, connection_string="InstrumentationKey=daa98b97-72b5-4a8d-9a0f-c75c61fe4883;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/" ) # Tracing tracer = Tracer( exporter=AzureExporter(connection_string="InstrumentationKey=daa98b97-72b5-4a8d-9a0f-c75c61fe4883;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/"), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter(connection_string="InstrumentationKey=daa98b97-72b5-4a8d-9a0f-c75c61fe4883;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: button2 = app.config['VOTE2VALUE']
# TODO: Setup tracer tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=664beceb-3223-46d7-8eb7-47f3cee4fd9d'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests # TODO: Setup flask middleware middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=664beceb-3223-46d7-8eb7-47f3cee4fd9d"), 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=3386db9e-347a-43c0-921e-c84c7c757f4e'), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=3386db9e-347a-43c0-921e-c84c7c757f4e"), 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=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:
url_prefix='/scrape_aggregate_reports') app.register_blueprint(store_single_count_blueprint, url_prefix='/single_count') app.register_blueprint(export_manager_blueprint, url_prefix='/export_manager') app.register_blueprint(backup_manager_blueprint, url_prefix='/backup_manager') app.register_blueprint(dataflow_monitor_blueprint, url_prefix='/dataflow_monitor') app.register_blueprint(validation_manager_blueprint, url_prefix='/validation_manager') app.register_blueprint(calculation_data_storage_manager_blueprint, url_prefix='/calculation_data_storage_manager') 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) else: trace_exporter = file_exporter.FileExporter(file_name='traces') # Setup tracing app.config['OPENCENSUS_TRACE_PARAMS'] = { 'BLACKLIST_HOSTNAMES': ['metadata'] # Don't trace metadata requests } middleware = FlaskMiddleware(app, exporter=trace_exporter) config_integration.trace_integrations( ['google_cloud_clientlibs', 'requests', 'sqlalchemy'])
# 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']
from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.stats import aggregation as aggregation_module 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.trace.samplers import ProbabilitySampler from opencensus.trace.tracer import Tracer app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= 'InstrumentationKey=e8de246b-54de-49fd-ab16-6cbc8753a2fd'), sampler=ProbabilitySampler(rate=1.0), ) # TODO: Setup flask middleware # Logging logger = logging.getLogger(__name__) logger.addHandler( AzureLogHandler(connection_string= 'InstrumentationKey=e8de246b-54de-49fd-ab16-6cbc8753a2fd')) # Metrics TODO: Setup exporter exporter = metrics_exporter.new_metrics_exporter( enable_standard_metrics=True, connection_string='InstrumentationKey=e8de246b-54de-49fd-ab16-6cbc8753a2fd'
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)
# Tracing tracer = Tracer( exporter=AzureExporter( connection_string= 'InstrumentationKey=fb01ac91-77e9-4179-8903-915fea961876;IngestionEndpoint=https://westus2-0.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(1.0), ) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= "InstrumentationKey=fb01ac91-77e9-4179-8903-915fea961876;IngestionEndpoint=https://westus2-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:
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, ) @app.route('/get-energy-type', methods=['GET']) def get_energy_type(): """ Returns technology code and fuel code for a specific GSRN. Takes 'gsrn' as query parameter. """ gsrn = request.args.get('gsrn') try: tech_code, fuel_code = get_tech_fuel_code(gsrn)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from flask import Flask from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace.propagation.trace_context_http_header_format \ import TraceContextPropagator app = Flask(__name__) middleware = FlaskMiddleware(app, propagator=TraceContextPropagator()) @app.route('/') def hello(): return 'Hello World!' if __name__ == '__main__': import logging logger = logging.getLogger('werkzeug') logger.setLevel(logging.ERROR) app.run(host='localhost', port=8080, threaded=True)
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'])
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())
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), )
"/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", ]) if environment.in_gcp(): # This attempts to connect to all of our databases. Any connections that fail will # be logged and not raise an error, so that a single database outage doesn't take
# 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']
'InstrumentationKey=92fd87df-63d3-49b7-a963-47d63627465f;IngestionEndpoint=https://westeurope-2.in.applicationinsights.azure.com/' ) # Tracing tracer = Tracer(exporter=AzureExporter( connection_string= 'InstrumentationKey=92fd87df-63d3-49b7-a963-47d63627465f;IngestionEndpoint=https://westeurope-2.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(1.0)) app = Flask(__name__) # Requests middleware = FlaskMiddleware( app, exporter=AzureExporter( connection_string= 'InstrumentationKey=92fd87df-63d3-49b7-a963-47d63627465f;IngestionEndpoint=https://westeurope-2.in.applicationinsights.azure.com/' ), sampler=ProbabilitySampler(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: