Skip to content

Commit

Permalink
fix (tests): Using hexadecimal IDs in Server-Timing header.
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Vital <[email protected]>
  • Loading branch information
pvital committed Oct 10, 2024
1 parent b7a673d commit 25d56f9
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 101 deletions.
4 changes: 4 additions & 0 deletions tests/clients/test_pika.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from opentelemetry.trace.span import format_span_id

from instana.singletons import agent, tracer
from instana.util.ids import hex_id


class _TestPika:
Expand Down Expand Up @@ -377,6 +378,7 @@ def test_basic_publish(self, send_method, _unused) -> None:
"X-INSTANA-T": format_span_id(rabbitmq_span.t),
"X-INSTANA-S": format_span_id(rabbitmq_span.s),
"X-INSTANA-L": "1",
"Server-Timing": f"intid;desc={hex_id(rabbitmq_span.t)}",
}
),
b"Hello!",
Expand Down Expand Up @@ -418,6 +420,7 @@ def test_basic_publish_as_root_exit_span(self, send_method, _unused) -> None:
"X-INSTANA-T": format_span_id(rabbitmq_span.t),
"X-INSTANA-S": format_span_id(rabbitmq_span.s),
"X-INSTANA-L": "1",
"Server-Timing": f"intid;desc={hex_id(rabbitmq_span.t)}",
}
),
b"Hello!",
Expand Down Expand Up @@ -451,6 +454,7 @@ def test_basic_publish_with_headers(self, send_method, _unused) -> None:
"X-INSTANA-T": format_span_id(rabbitmq_span.t),
"X-INSTANA-S": format_span_id(rabbitmq_span.s),
"X-INSTANA-L": "1",
"Server-Timing": f"intid;desc={hex_id(rabbitmq_span.t)}",
}
),
b"Hello!",
Expand Down
16 changes: 8 additions & 8 deletions tests/frameworks/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_get_as_root_exit_span(self) -> None:
agent.options.allow_exit_as_root = True
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={wsgi_span.t}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(wsgi_span.t)}"

def test_client_get_301(self) -> None:
async def test():
Expand Down Expand Up @@ -182,7 +182,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_get_405(self) -> None:
async def test():
Expand Down Expand Up @@ -228,7 +228,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_get_500(self) -> None:
async def test():
Expand Down Expand Up @@ -275,7 +275,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_get_504(self) -> None:
async def test():
Expand Down Expand Up @@ -322,7 +322,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_get_with_params_to_scrub(self) -> None:
async def test():
Expand Down Expand Up @@ -371,7 +371,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_client_response_header_capture(self) -> None:
original_extra_http_headers = agent.options.extra_http_headers
Expand Down Expand Up @@ -425,7 +425,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

agent.options.extra_http_headers = original_extra_http_headers

Expand Down
12 changes: 6 additions & 6 deletions tests/frameworks/test_aiohttp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_server_get_204(self):
async def test():
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={trace_id}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(trace_id)}"

def test_server_synthetic_request(self):
async def test():
Expand Down Expand Up @@ -205,7 +205,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_server_custom_header_capture(self):
async def test():
Expand Down Expand Up @@ -265,7 +265,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

assert "X-Capture-This" in aioserver_span.data["http"]["header"]
assert aioserver_span.data["http"]["header"]["X-Capture-This"] == "this"
Expand Down Expand Up @@ -314,7 +314,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_server_get_500(self):
async def test():
Expand Down Expand Up @@ -358,7 +358,7 @@ async def test():
assert "X-INSTANA-L" in response.headers
assert response.headers["X-INSTANA-L"] == "1"
assert "Server-Timing" in response.headers
assert response.headers["Server-Timing"] == f"intid;desc={traceId}"
assert response.headers["Server-Timing"] == f"intid;desc={hex_id(traceId)}"

def test_server_get_exception(self):
async def test():
Expand Down
16 changes: 8 additions & 8 deletions tests/frameworks/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_basic_request(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "test" == test_span.data["sdk"]["name"]
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_request_with_error(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "test" == test_span.data["sdk"]["name"]
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_complex_request(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "test" == test_span.data["sdk"]["name"]
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_with_incoming_context(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "traceparent" in response.headers
Expand Down Expand Up @@ -477,7 +477,7 @@ def test_with_incoming_context_and_correlation(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "traceparent" in response.headers
Expand Down Expand Up @@ -537,7 +537,7 @@ def test_with_incoming_traceparent_tracestate(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "traceparent" in response.headers
Expand Down Expand Up @@ -594,7 +594,7 @@ def test_with_incoming_traceparent_tracestate_disable_traceparent(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

assert "traceparent" in response.headers
Expand Down Expand Up @@ -645,7 +645,7 @@ def test_with_incoming_mixed_case_context(self) -> None:
assert response.headers["X-INSTANA-L"] == "1"

assert "Server-Timing" in response.headers
server_timing_value = "intid;desc=%s" % django_span.t
server_timing_value = f"intid;desc={hex_id(django_span.t)}"
assert response.headers["Server-Timing"] == server_timing_value

def test_url_pattern_route(self) -> None:
Expand Down
20 changes: 10 additions & 10 deletions tests/frameworks/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_basic_get(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_400(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_500(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert asgi_span.ec == 1
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_path_templates(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_secret_scrubbing(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_synthetic_request(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_request_header_capture(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_response_header_capture(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_non_async_simple(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span1.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span1.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span1.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span1.t)}"

assert not asgi_span1.ec
assert asgi_span1.data["http"]["host"] == "testserver"
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_non_async_threadpool(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["host"] == "testserver"
Expand Down
2 changes: 1 addition & 1 deletion tests/frameworks/test_fastapi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_basic_get(self) -> None:

assert result.headers["X-INSTANA-T"] == hex_id(asgi_span.t)
assert result.headers["X-INSTANA-S"] == hex_id(asgi_span.s)
assert result.headers["Server-Timing"] == f"intid;desc={asgi_span.t}"
assert result.headers["Server-Timing"] == f"intid;desc={hex_id(asgi_span.t)}"

assert not asgi_span.ec
assert asgi_span.data["http"]["path"] == "/"
Expand Down
Loading

0 comments on commit 25d56f9

Please sign in to comment.