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

distributed tracing

parent 35b630a3
from flask import Flask, redirect, request from flask import Flask, redirect, request
import requests, os, logging, json import requests, os, logging, json
import elasticapm import elasticapm
from elasticapm.utils.disttracing import TraceParent from elasticapm.contrib.flask import ElasticAPM
# A very boring and basic hip-hop-service to demonstrate # A very boring and basic hip-hop-service to demonstrate
# observability via tracing across multiple services. # observability via tracing across multiple services.
...@@ -11,7 +11,9 @@ logging.basicConfig(level=logging.INFO) ...@@ -11,7 +11,9 @@ logging.basicConfig(level=logging.INFO)
service = os.environ.get('HIPHOP', 'hiphop') service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1')) tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__) app = Flask(__name__)
client = elasticapm.Client(service_name=service) apm = ElasticAPM(app,
service_name=os.environ.get('SERVICE', 'space'),
)
@app.route('/') @app.route('/')
def index(): def index():
...@@ -20,8 +22,6 @@ def index(): ...@@ -20,8 +22,6 @@ def index():
@app.route('/hip') @app.route('/hip')
def hip(): def hip():
logging.info(f"Request from { request.remote_addr } with headers { json.dumps(dict(request.headers)) }") 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 = "" r = ""
url = f"http://{service}-{tier + 1}/hip" url = f"http://{service}-{tier + 1}/hip"
try: try:
...@@ -31,7 +31,6 @@ def hip(): ...@@ -31,7 +31,6 @@ def hip():
r = "END" r = "END"
hip = "hip " if tier == 1 else "" hip = "hip " if tier == 1 else ""
client.end_transaction()
return f"{hip} hop-{ tier } -> { r }".strip() 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