Commit 81e990de authored by Alexandre Vincent's avatar Alexandre Vincent
Browse files

add x-app-id to traces

parent 51f46b12
...@@ -369,6 +369,7 @@ def check_environment(configuration): ...@@ -369,6 +369,7 @@ def check_environment(configuration):
AUTHORIZATION_HEADER_NAME = 'Authorization' AUTHORIZATION_HEADER_NAME = 'Authorization'
APP_KEY_HEADER_NAME = 'appKey' APP_KEY_HEADER_NAME = 'appKey'
APP_ID_HEADER_NAME = 'x-app-id'
CORRELATION_ID_HEADER_NAME = 'correlation-id' CORRELATION_ID_HEADER_NAME = 'correlation-id'
REQUEST_ID_HEADER_NAME = 'Request-ID' REQUEST_ID_HEADER_NAME = 'Request-ID'
PARTITION_ID_HEADER_NAME = 'data-partition-id' PARTITION_ID_HEADER_NAME = 'data-partition-id'
...@@ -103,6 +103,11 @@ class TracingMiddleware(BaseHTTPMiddleware): ...@@ -103,6 +103,11 @@ class TracingMiddleware(BaseHTTPMiddleware):
tracer.add_attribute_to_current_span(attribute_key="request.header Content-length", tracer.add_attribute_to_current_span(attribute_key="request.header Content-length",
attribute_value=request_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 @staticmethod
def _after_request(request: Request, response: Response, tracer): def _after_request(request: Request, response: Response, tracer):
......
...@@ -79,6 +79,30 @@ def test_about_call_traces_existing_correlation_id(client: TestClient): ...@@ -79,6 +79,30 @@ def test_about_call_traces_existing_correlation_id(client: TestClient):
assert 'correlation-id' in spandata.attributes.keys() assert 'correlation-id' in spandata.attributes.keys()
assert spandata.attributes['correlation-id'] == 'some correlation id' 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): def test_about_call_traces_existing_data_partition_id(client: TestClient):
# Initialize traces exporter in app, like it is in app's startup_event # Initialize traces exporter in app, like it is in app's startup_event
......
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