Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pump, Cedric
lab-tracing
Commits
a604531a
Commit
a604531a
authored
Mar 06, 2021
by
Nane Kratzke
Browse files
Aktualisieren space/requirements.txt, space/service.py Dateien
parent
add19267
Changes
2
Show whitespace changes
Inline
Side-by-side
space/requirements.txt
View file @
a604531a
...
...
@@ -3,3 +3,4 @@ requests
opentracing
jaeger-client
joblib
elastic-apm[flask]
\ No newline at end of file
space/service.py
View file @
a604531a
...
...
@@ -6,6 +6,8 @@ import traceback
import
os
import
json
from
joblib
import
Parallel
,
delayed
from
elasticapm.contrib.flask
import
ElasticAPM
apm
=
ElasticAPM
(
app
)
# A very boring and basic space-service to demonstrate
# observability via tracing.
...
...
@@ -13,13 +15,13 @@ from joblib import Parallel, delayed
service
=
os
.
environ
.
get
(
'SERVICE'
,
'space'
)
app
=
Flask
(
__name__
)
config
=
Config
(
config
=
{
'sampler'
:
{
'type'
:
'const'
,
'param'
:
1
},
'logging'
:
True
,
'reporter_batch_size'
:
1
},
service_name
=
service
)
#
config = Config(config = {
#
'sampler': { 'type': 'const', 'param': 1 },
#
'logging': True,
#
'reporter_batch_size': 1
#
}, service_name=service)
tracer
=
config
.
initialize_tracer
()
#
tracer = config.initialize_tracer()
@
app
.
route
(
'/'
)
def
index
():
...
...
@@ -33,7 +35,7 @@ def load_url(key, url):
@
app
.
route
(
'/space'
)
def
space
():
with
tracer
.
start_span
(
operation_name
=
"space"
)
as
parent_span
:
#
with tracer.start_span(operation_name="space") as parent_span:
try
:
lat
=
float
(
request
.
args
.
get
(
'lat'
,
"0.0001"
))
lon
=
float
(
request
.
args
.
get
(
'lon'
,
"0.0001"
))
...
...
@@ -47,7 +49,7 @@ def space():
"passtime"
:
f
"http://api.open-notify.org/iss-pass.json?lat=
{
lat
}
&lon=
{
lon
}
"
}
with
tracer
.
start_span
(
operation_name
=
"parallel"
,
child_of
=
parent_span
)
as
span
:
#
with tracer.start_span(operation_name="parallel", child_of=parent_span) as span:
results
=
Parallel
(
n_jobs
=
3
)(
delayed
(
load_url
)(
key
,
url
)
for
key
,
url
in
queries
.
items
())
result
=
{
key
:
content
for
key
,
content
in
results
}
...
...
Write
Preview
Markdown
is supported
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