Linux ホストまたは VM 上で、hello.py という名前の Python アプリケーションを新規作成します。例えば、nano hello.py とします。
以下のコードを hello.py に追加します。
hello.py
fromflaskimportFlaskimportrandomapp=Flask(__name__)quotes=["Strive not to be a success, but rather to be of value. - Albert Einstein","Believe you can and you're halfway there. - Theodore Roosevelt","The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt"]@app.route('/')defindex():quote=random.choice(quotes)+"\n"returnquoteif__name__=='__main__':app.run(host='0.0.0.0',port=5050)
Replace <YOUR_DD_API_KEY> with your Datadog API key, <YOUR_DD_SITE> with your Datadog site, and <AGENT_ENV> with the environment your Agent is installed on (for example, development).
fromflaskimportFlaskimportrandomfromddtraceimporttracerapp=Flask(__name__)quotes=["Strive not to be a success, but rather to be of value. - Albert Einstein","Believe you can and you're halfway there. - Theodore Roosevelt","The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt"]@app.route('/')defindex():withtracer.trace("get_quote")asspan:quote=random.choice(quotes)+"\n"span.set_tag("quote",quote)returnquoteif__name__=='__main__':app.run(host='0.0.0.0',port=5050)