Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def _serialized_v1_span_to_serialized_v2_span(
attributes["sentry.release"] = event["release"]
if "environment" in event:
attributes["sentry.environment"] = event["environment"]
if "server_name" in event:
attributes["server.address"] = event["server_name"]
Comment on lines +228 to +229
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server.address from span data silently overwritten by event server_name

When span.data already contains a server.address attribute (e.g. set by the WSGI integration from SERVER_NAME), this unconditional assignment overwrites it with the event-level server_name (the machine hostname), losing the more specific per-request value.

Evidence
  • attributes.update(span_data) at line 207 merges all span data into attributes, which may include a server.address key (e.g. wsgi.py:402 sets attributes["server.address"] = server_name from environ["SERVER_NAME"]).
  • The new code at line 228-229 then unconditionally does attributes["server.address"] = event["server_name"], overwriting the span-level value with the machine hostname.
  • OTel semantic convention server.address refers to the logical server address the client is connecting to (not the machine hostname), so the overwrite introduces semantically incorrect data.
  • The fix is to only set the fallback when server.address is not already present: if "server_name" in event and "server.address" not in attributes:.

Identified by Warden find-bugs · YPW-2W9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix attempt detected (commit ed3fc20)

The commit added the exact line at issue (attributes['server.address'] = event['server_name']) unconditionally without the suggested and 'server.address' not in attributes guard, so the overwrite issue persists.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

if "transaction" in event:
attributes["sentry.segment.name"] = event["transaction"]

Expand Down
7 changes: 7 additions & 0 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def test_text_generation(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -665,6 +666,7 @@ def test_text_generation_streaming(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -805,6 +807,7 @@ def test_chat_completion(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -953,6 +956,7 @@ def test_chat_completion_streaming(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -1099,6 +1103,7 @@ def test_chat_completion_api_error(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -1297,6 +1302,7 @@ def test_chat_completion_with_tools(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -1456,6 +1462,7 @@ def test_chat_completion_streaming_with_tools(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3721,6 +3721,7 @@ def test_ai_client_span_responses_api_no_pii(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "openai tx",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -3913,6 +3914,7 @@ def test_ai_client_span_responses_api(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "openai tx",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -4595,6 +4597,7 @@ async def test_ai_client_span_responses_async_api(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "openai tx",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -5165,6 +5168,7 @@ async def test_ai_client_span_streaming_responses_async_api(
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "openai tx",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down
6 changes: 6 additions & 0 deletions tests/tracing/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand All @@ -217,6 +218,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -245,6 +247,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -389,6 +392,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand All @@ -412,6 +416,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down Expand Up @@ -439,6 +444,7 @@ def my_agent():
"sentry.sdk.version": mock.ANY,
"sentry.segment.id": mock.ANY,
"sentry.segment.name": "test-transaction",
"server.address": mock.ANY,
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}
Expand Down
Loading