Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pump, Cedric
lab-tracing
Commits
5f2b40c4
Commit
5f2b40c4
authored
Dec 27, 2020
by
Nane Kratzke
Browse files
Instrumenting subsequent calls
parent
e593b8fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
hiphop/service.py
View file @
5f2b40c4
from
flask
import
Flask
,
redirect
from
jaeger_client
import
Config
from
flask_opentracing
import
FlaskTracing
from
flask_opentracing
import
FlaskTracing
,
FlaskTracer
import
opentracing
import
requests
import
traceback
import
os
# A very boring and basic hip-hop-service to demonstrate
# observa
la
bility
and
tracing.
# observability
via
tracing.
service
=
os
.
environ
.
get
(
'HIPHOP'
,
'hiphop'
)
tier
=
int
(
os
.
environ
.
get
(
'TIER'
,
'1'
))
app
=
Flask
(
__name__
)
print
(
"Hello World"
)
config
=
Config
(
config
=
{
'sampler'
:
{
'type'
:
'const'
,
...
...
@@ -35,11 +33,12 @@ def index():
def
hip
():
r
=
""
try
:
current_span
=
tracing
.
get_span
(
request
)
text_carrier
=
{}
tracing
.
inject
(
span
,
opentracing
.
Format
.
TEXT_MAP
,
text_carrier
)
print
(
text_carrier
)
r
=
requests
.
get
(
f
"http://
{
service
}
-
{
tier
+
1
}
"
,
headers
=
text_carrier
,
allow_redirects
=
True
)
parent_span
=
flask_tracer
.
get_span
()
with
opentracing
.
tracer
.
start_span
(
f
"
{
service
}
-
{
tier
+
1
}
"
,
child_of
=
parent_span
)
as
span
:
url
=
f
"http://
{
service
}
-
{
tier
+
1
}
"
span
.
set_tag
(
"http.url"
,
url
)
r
=
requests
.
get
(
url
)
span
.
set_tag
(
"http.status_code"
,
r
.
status_code
)
print
(
r
)
r
=
r
.
content
.
decode
(
'utf-8'
)
except
Exception
as
ex
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment