Commit 51f46b12 authored by Alexandre Vincent's avatar Alexandre Vincent
Browse files

trace data-partition-id even in None case

parent d86f746a
...@@ -91,11 +91,9 @@ class TracingMiddleware(BaseHTTPMiddleware): ...@@ -91,11 +91,9 @@ class TracingMiddleware(BaseHTTPMiddleware):
ctx_partition_id = get_or_create_ctx().partition_id ctx_partition_id = get_or_create_ctx().partition_id
partition_id = ctx_partition_id if ctx_partition_id is not None \ partition_id = ctx_partition_id if ctx_partition_id is not None \
else request.headers.get(conf.PARTITION_ID_HEADER_NAME) else request.headers.get(conf.PARTITION_ID_HEADER_NAME)
# only put in the trace if there is data tracer.add_attribute_to_current_span(
if partition_id is not None: attribute_key=conf.PARTITION_ID_HEADER_NAME,
tracer.add_attribute_to_current_span( attribute_value=partition_id)
attribute_key=conf.PARTITION_ID_HEADER_NAME,
attribute_value=partition_id)
request_content_type = request.headers.get("Content-type") request_content_type = request.headers.get("Content-type")
tracer.add_attribute_to_current_span(attribute_key="request.header Content-type", tracer.add_attribute_to_current_span(attribute_key="request.header Content-type",
......
...@@ -88,10 +88,11 @@ def test_about_call_traces_existing_data_partition_id(client: TestClient): ...@@ -88,10 +88,11 @@ def test_about_call_traces_existing_data_partition_id(client: TestClient):
response = client.get(build_url("/about")) response = client.get(build_url("/about"))
assert response.status_code == 200 assert response.status_code == 200
# one call was exported, without data-partition-id # one call was exported, with data-partition-id
assert len(wdms_app.trace_exporter.exported) == 1 # one call => one export assert len(wdms_app.trace_exporter.exported) == 1 # one call => one export
spandata = wdms_app.trace_exporter.exported[0] spandata = wdms_app.trace_exporter.exported[0]
assert 'data-partition-id' not in spandata.attributes.keys() assert 'data-partition-id' in spandata.attributes.keys()
assert spandata.attributes['data-partition-id'] is None
# data-partition-id header -> works as well # data-partition-id header -> works as well
client.get(build_url("/about"), headers={'data-partition-id': 'some partition id'}) client.get(build_url("/about"), headers={'data-partition-id': 'some partition id'})
......
Supports Markdown
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