Skip to content

Commit

Permalink
fix: use server host and port instead of host header values
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaakola-aiven committed Jan 7, 2025
1 parent f3fbb70 commit 63474c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/schema_registry/telemetry/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ def add_span_attribute(span: Span, key: str, value: str | int) -> None:
span.set_attribute(key, value)

@staticmethod
def update_span_with_request(request: Request, span: Span) -> None:
def update_span_with_request(
request: Request,
span: Span,
config: Config = Provide[KarapaceContainer.config],
) -> None:
if span.is_recording():
span.set_attribute(C.CLIENT_ADDRESS, request.client.host or "" if request.client else "")
span.set_attribute(C.CLIENT_PORT, request.client.port or "" if request.client else "")
span.set_attribute(S.SERVER_ADDRESS, request.url.hostname or "")
span.set_attribute(S.SERVER_PORT, request.url.port or "")
span.set_attribute(S.SERVER_ADDRESS, config.host)
span.set_attribute(S.SERVER_PORT, config.port)
span.set_attribute(U.URL_SCHEME, request.url.scheme)
span.set_attribute(U.URL_PATH, request.url.path)
span.set_attribute(H.HTTP_REQUEST_METHOD, request.method)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/schema_registry/telemetry/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_update_span_with_request():
[
call("client.address", "client"),
call("client.port", 8080),
call("server.address", "server"),
call("server.address", "127.0.0.1"),
call("server.port", 8081),
call("url.scheme", "http"),
call("url.path", "/test"),
Expand Down

0 comments on commit 63474c6

Please sign in to comment.