Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Domain Data Mgmt Services
Wellbore
Wellbore Domain Services
Commits
81e990de
Commit
81e990de
authored
Jul 12, 2021
by
Alexandre Vincent
Browse files
add x-app-id to traces
parent
51f46b12
Changes
3
Show whitespace changes
Inline
Side-by-side
app/conf.py
View file @
81e990de
...
...
@@ -369,6 +369,7 @@ def check_environment(configuration):
AUTHORIZATION_HEADER_NAME
=
'Authorization'
APP_KEY_HEADER_NAME
=
'appKey'
APP_ID_HEADER_NAME
=
'x-app-id'
CORRELATION_ID_HEADER_NAME
=
'correlation-id'
REQUEST_ID_HEADER_NAME
=
'Request-ID'
PARTITION_ID_HEADER_NAME
=
'data-partition-id'
app/middleware/traces_middleware.py
View file @
81e990de
...
...
@@ -103,6 +103,11 @@ class TracingMiddleware(BaseHTTPMiddleware):
tracer
.
add_attribute_to_current_span
(
attribute_key
=
"request.header Content-length"
,
attribute_value
=
request_content_length
)
app_id
=
request
.
headers
.
get
(
conf
.
APP_ID_HEADER_NAME
)
if
app_id
is
not
None
:
tracer
.
add_attribute_to_current_span
(
attribute_key
=
conf
.
APP_ID_HEADER_NAME
,
attribute_value
=
app_id
)
@
staticmethod
def
_after_request
(
request
:
Request
,
response
:
Response
,
tracer
):
...
...
tests/unit/middleware/traces_middleware_test.py
View file @
81e990de
...
...
@@ -79,6 +79,30 @@ def test_about_call_traces_existing_correlation_id(client: TestClient):
assert
'correlation-id'
in
spandata
.
attributes
.
keys
()
assert
spandata
.
attributes
[
'correlation-id'
]
==
'some correlation id'
def
test_about_call_traces_existing_app_id
(
client
:
TestClient
):
# Initialize traces exporter in app, like it is in app's startup_event
wdms_app
.
trace_exporter
=
ExporterInTest
()
# no header -> works fine
response
=
client
.
get
(
build_url
(
"/about"
))
assert
response
.
status_code
==
200
# one call was exported, without x-app-id
assert
len
(
wdms_app
.
trace_exporter
.
exported
)
==
1
# one call => one export
spandata
=
wdms_app
.
trace_exporter
.
exported
[
0
]
assert
'x-app-id'
not
in
spandata
.
attributes
.
keys
()
# x-app-id header -> works as well
client
.
get
(
build_url
(
"/about"
),
headers
=
{
'x-app-id'
:
'some app id'
})
# a second call was exported, with data-partition-id
assert
len
(
wdms_app
.
trace_exporter
.
exported
)
==
2
# one call => one export
spandata
=
wdms_app
.
trace_exporter
.
exported
[
1
]
assert
'x-app-id'
in
spandata
.
attributes
.
keys
()
assert
spandata
.
attributes
[
'x-app-id'
]
==
'some app id'
def
test_about_call_traces_existing_data_partition_id
(
client
:
TestClient
):
# Initialize traces exporter in app, like it is in app's startup_event
...
...
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