Skip to content

Commit

Permalink
fix: rename trace_id variable to correlation_id (#408)
Browse files Browse the repository at this point in the history
I learned that we should not use the trace_id name for a correlation_id.

I scoped this change as a fix, as the correltation_id is only used
internally.
  • Loading branch information
jooola committed Jul 3, 2024
1 parent cf08842 commit 66a0f54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def request( # type: ignore[no-untyped-def]
**kwargs,
)

trace_id = response.headers.get("X-Correlation-Id")
correlation_id = response.headers.get("X-Correlation-Id")
payload = {}
try:
if len(response.content) > 0:
Expand All @@ -225,7 +225,7 @@ def request( # type: ignore[no-untyped-def]
code=response.status_code,
message=response.reason,
details={"content": response.content},
trace_id=trace_id,
correlation_id=correlation_id,
) from exc

if not response.ok:
Expand All @@ -234,7 +234,7 @@ def request( # type: ignore[no-untyped-def]
code=response.status_code,
message=response.reason,
details={"content": response.content},
trace_id=trace_id,
correlation_id=correlation_id,
)

error: dict = payload["error"]
Expand All @@ -248,7 +248,7 @@ def request( # type: ignore[no-untyped-def]
code=error["code"],
message=error["message"],
details=error["details"],
trace_id=trace_id,
correlation_id=correlation_id,
)

return payload
8 changes: 4 additions & 4 deletions hcloud/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def __init__(
message: str,
details: Any,
*,
trace_id: str | None = None,
correlation_id: str | None = None,
):
extras = [str(code)]
if trace_id is not None:
extras.append(trace_id)
if correlation_id is not None:
extras.append(correlation_id)

error = f"{message} ({', '.join(extras)})"

super().__init__(error)
self.code = code
self.message = message
self.details = details
self.trace_id = trace_id
self.correlation_id = correlation_id
4 changes: 2 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_request_fails(self, client, fail_response):
assert error.message == "invalid input in field 'broken_field': is too long"
assert error.details["fields"][0]["name"] == "broken_field"

def test_request_fails_trace_id(self, client, response):
def test_request_fails_correlation_id(self, client, response):
response.headers["X-Correlation-Id"] = "67ed842dc8bc8673"
response.status_code = 409
response._content = json.dumps(
Expand All @@ -124,7 +124,7 @@ def test_request_fails_trace_id(self, client, response):
assert error.code == "conflict"
assert error.message == "some conflict"
assert error.details is None
assert error.trace_id == "67ed842dc8bc8673"
assert error.correlation_id == "67ed842dc8bc8673"
assert str(error) == "some conflict (conflict, 67ed842dc8bc8673)"

def test_request_500(self, client, fail_response):
Expand Down

0 comments on commit 66a0f54

Please sign in to comment.