|
| 1 | +# Copyright 2019, OpenCensus Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from flask import Flask |
| 16 | +import requests |
| 17 | + |
| 18 | +from opencensus.trace import config_integration |
| 19 | +from opencensus.ext.azure.trace_exporter import AzureExporter |
| 20 | +from opencensus.ext.flask.flask_middleware import FlaskMiddleware |
| 21 | +from opencensus.trace.propagation.trace_context_http_header_format \ |
| 22 | + import TraceContextPropagator |
| 23 | + |
| 24 | +app = Flask(__name__) |
| 25 | +middleware = FlaskMiddleware( |
| 26 | + app, |
| 27 | + exporter=AzureExporter(), |
| 28 | + propagator=TraceContextPropagator(), |
| 29 | +) |
| 30 | + |
| 31 | + |
| 32 | +@app.route('/') |
| 33 | +def hello(): |
| 34 | + requests.get('https://www.wikipedia.org/wiki/Rabbit') |
| 35 | + return 'Hello, World!' |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + import logging |
| 40 | + logger = logging.getLogger('werkzeug') |
| 41 | + logger.setLevel(logging.ERROR) |
| 42 | + config_integration.trace_integrations(['requests']) |
| 43 | + app.run(host='localhost', port=8080, threaded=True) |
0 commit comments