Commit 95d7a4c3 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

Logging headers

parent 866eec95
from flask import Flask, redirect, request from flask import Flask, redirect, request
import requests, os, logging import requests, os, logging, json
from elasticapm.contrib.flask import ElasticAPM 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.
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__)
...@@ -16,12 +18,11 @@ def index(): ...@@ -16,12 +18,11 @@ def index():
@app.route('/hip') @app.route('/hip')
def hip(): def hip():
logging.info(f"Request from: { request.remote_addr }") logging.info(f"Request from { request.remote_addr } with headers { json.dumps(dict(request.headers)) }")
r = "" r = ""
url = f"http://{service}-{tier + 1}/hip" url = f"http://{service}-{tier + 1}/hip"
try: try:
r = requests.get(url) r = requests.get(url).content
r = r.content.decode('utf-8')
except Exception as ex: except Exception as ex:
logging.error(f"Fetching { url } failed ({ ex })") logging.error(f"Fetching { url } failed ({ ex })")
r = "END" r = "END"
......
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