Commit f4db0cb2 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

distributed tracing

parent 35b630a3
from flask import Flask, redirect, request
import requests, os, logging, json
import elasticapm
from elasticapm.utils.disttracing import TraceParent
from elasticapm.contrib.flask import ElasticAPM
# A very boring and basic hip-hop-service to demonstrate
# observability via tracing across multiple services.
......@@ -11,7 +11,9 @@ logging.basicConfig(level=logging.INFO)
service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__)
client = elasticapm.Client(service_name=service)
apm = ElasticAPM(app,
service_name=os.environ.get('SERVICE', 'space'),
)
@app.route('/')
def index():
......@@ -20,8 +22,6 @@ def index():
@app.route('/hip')
def hip():
logging.info(f"Request from { request.remote_addr } with headers { json.dumps(dict(request.headers)) }")
trace_parent = TraceParent.from_headers(request.headers)
client.begin_transaction("main", trace_parent=trace_parent)
r = ""
url = f"http://{service}-{tier + 1}/hip"
try:
......@@ -31,7 +31,6 @@ def hip():
r = "END"
hip = "hip " if tier == 1 else ""
client.end_transaction()
return f"{hip} hop-{ tier } -> { r }".strip()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment