Commit 5f2b40c4 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

Instrumenting subsequent calls

parent e593b8fe
from flask import Flask, redirect from flask import Flask, redirect
from jaeger_client import Config from jaeger_client import Config
from flask_opentracing import FlaskTracing from flask_opentracing import FlaskTracing, FlaskTracer
import opentracing import opentracing
import requests import requests
import traceback import traceback
import os import os
# A very boring and basic hip-hop-service to demonstrate # A very boring and basic hip-hop-service to demonstrate
# observalability and tracing. # observability via tracing.
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__)
print("Hello World")
config = Config(config = { config = Config(config = {
'sampler': { 'sampler': {
'type': 'const', 'type': 'const',
...@@ -35,11 +33,12 @@ def index(): ...@@ -35,11 +33,12 @@ def index():
def hip(): def hip():
r = "" r = ""
try: try:
current_span = tracing.get_span(request) parent_span = flask_tracer.get_span()
text_carrier = {} with opentracing.tracer.start_span(f"{service}-{tier + 1}", child_of=parent_span) as span:
tracing.inject(span, opentracing.Format.TEXT_MAP, text_carrier) url = f"http://{service}-{tier + 1}"
print(text_carrier) span.set_tag("http.url", url)
r = requests.get(f"http://{service}-{tier + 1}", headers=text_carrier, allow_redirects=True) r = requests.get(url)
span.set_tag("http.status_code", r.status_code)
print(r) print(r)
r = r.content.decode('utf-8') r = r.content.decode('utf-8')
except Exception as ex: except Exception as ex:
......
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