Skip to content

Instantly share code, notes, and snippets.

@basepi
Created February 5, 2020 23:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save basepi/23f9871482479feb12d404359860830f to your computer and use it in GitHub Desktop.
elastic-apm
flask
requests
blinker
import time
import requests
import elasticapm
def main():
sess = requests.Session()
for url in ["http://localhost:8080", "http://localhost:8000"]:
sess.get(url)
time.sleep(1)
if __name__ == "__main__":
client = elasticapm.Client(service_name="service 1")
elasticapm.instrument()
client.begin_transaction("main")
main()
client.end_transaction("main")
import time
import requests
from flask import Flask
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
apm = ElasticAPM(app, service_name="service 2a")
url = "http://localhost:8888/"
@app.route("/")
def svc2a():
with elasticapm.capture_span("main"):
time.sleep(2)
result = requests.get(url)
return result.content
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8080)
import time
import requests
from flask import Flask
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
apm = ElasticAPM(app, service_name="service 2b")
url = "http://localhost:8888/"
@app.route("/")
def svc2b():
with elasticapm.capture_span("main"):
time.sleep(2)
result = requests.get(url)
return result.content
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8000)
import time
from flask import Flask
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
apm = ElasticAPM(app, service_name="service 3")
@app.route("/")
def hello():
with elasticapm.capture_span("main"):
time.sleep(1) # mocks doing something
return "hello world"
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8888)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment