Skip to content

Commit 08ebd25

Browse files
fix(aws-lambda): Remove messaging.batch.message_count from the Lambda span (#8229)
### Description The Lambda span set `messaging.batch.message_count` to `1` for every event that isn't a list, and to `len(event)` for a top-level list. An SQS or SNS delivery is a dict with `Records`, so a batch of 10 messages reported 1. HTTP calls and direct invocations reported a batch they don't have. This PR removes the attribute from the Lambda span. The count belongs on messaging spans, as in the OTel messaging conventions: - boto3 `ReceiveMessage` and batch-send spans already set it (#8137, #8142). - For SQS/SNS-triggered Lambdas, the `queue.process` span in #8223 sets it. The JS SDK doesn't set it on the Lambda span either. The attribute was added in 3.0 (#7941) and never shipped in 2.x, so no released behavior changes. Replaces #8219 (same commits). GitHub never ran CI on #8219. **Note for review:** this is narrower than PY-3015, which asks to keep the attribute for SQS/SNS deliveries. @alexander-alderman-webb, please confirm that's OK. #### Issues * resolves: PY-3015 <!-- junior-request-attribution:start --> via @dingsdax. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0C9X9V5NMT%3A1793904671.980379 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0C9X9V5NMT%3A1793904671.980379) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0C9X9V5NMT%3A1793904671.980379/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>
1 parent 3da95c6 commit 08ebd25

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

‎MIGRATION_GUIDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
3838
- The `UnraisableHookIntegration` is now enabled by default.
3939
- We now don't suppress chained exceptions in the ASGI and asyncio integrations by default. The related `suppress_asgi_chained_exceptions` experimental option was removed.
4040
- In the AWS Lambda and GCP integrations, the text of the message of the warning the SDK optionally emits if a function is about to time out has changed.
41+
- The AWS Lambda integration no longer sets the `messaging.batch.message_count` attribute on the function span. In 2.x span streaming mode, it was the length of the event if the event was a list, and `1` otherwise, so an SQS or SNS batch was always reported as `1`. The attribute is now only set on messaging spans, such as boto3 SQS and SNS spans.
4142
- The `http.request.header.<name>` span attributes set by server integrations are now lists of strings instead of strings.
4243
- The HTTP breadcrumbs created by the stdlib (`http.client`) and boto3 integrations now use different keys: `http.method` is now `http.request.method`, `url` (or `aws.request.url` for boto3) is now `url.full`, `http.query` is now `url.query`, and `http.fragment` is now `url.fragment`. The stdlib breadcrumb no longer contains `reason`. The query string is filtered according to `data_collection`'s `url_query_params` setting.
4344
- The `url` field of HTTP breadcrumbs created by the HTTPX, httpx2, pyreqwest, and AIOHTTP client integrations now contains the full URL, including the query string and fragment. The query string is filtered according to `data_collection`'s `url_query_params` setting.

‎sentry_sdk/integrations/aws_lambda/_handler.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ def sentry_handler(
133133

134134
if isinstance(aws_event, list) and len(aws_event) >= 1:
135135
request_data = aws_event[0]
136-
batch_size = len(aws_event)
137136
else:
138137
request_data = aws_event
139-
batch_size = 1
140138

141139
if not isinstance(request_data, dict):
142140
# If we're not dealing with a dictionary, we won't be able to get
@@ -229,7 +227,6 @@ def sentry_handler(
229227
SPANDATA.SENTRY_SEGMENT_NAME_SOURCE: SegmentNameSource.COMPONENT,
230228
SPANDATA.CLOUD_PROVIDER: CLOUD_PROVIDER,
231229
SPANDATA.CLOUD_PLATFORM: CLOUD_PLATFORM,
232-
SPANDATA.MESSAGING_BATCH_MESSAGE_COUNT: batch_size,
233230
**header_attributes,
234231
**additional_attributes,
235232
}

‎tests/integrations/aws_lambda/test_aws_lambda.py‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ def test_timeout_error_scope_modified(lambda_client, test_environment):
174174

175175

176176
@pytest.mark.parametrize(
177-
"aws_event, has_request_data, batch_size",
177+
"aws_event, has_request_data",
178178
[
179-
(b"1231", False, 1),
180-
(b"11.21", False, 1),
181-
(b'"Good dog!"', False, 1),
182-
(b"true", False, 1),
179+
(b"1231", False),
180+
(b"11.21", False),
181+
(b'"Good dog!"', False),
182+
(b"true", False),
183183
(
184184
b"""
185185
[
@@ -190,7 +190,6 @@ def test_timeout_error_scope_modified(lambda_client, test_environment):
190190
]
191191
""",
192192
False,
193-
4,
194193
),
195194
(
196195
b"""
@@ -222,9 +221,8 @@ def test_timeout_error_scope_modified(lambda_client, test_environment):
222221
]
223222
""",
224223
True,
225-
2,
226224
),
227-
(b"[]", False, 1),
225+
(b"[]", False),
228226
],
229227
ids=[
230228
"event as integer",
@@ -236,9 +234,7 @@ def test_timeout_error_scope_modified(lambda_client, test_environment):
236234
"event as empty list",
237235
],
238236
)
239-
def test_non_dict_event(
240-
lambda_client, test_environment, aws_event, has_request_data, batch_size
241-
):
237+
def test_non_dict_event(lambda_client, test_environment, aws_event, has_request_data):
242238
lambda_client.invoke(
243239
FunctionName="BasicException",
244240
Payload=aws_event,
@@ -771,7 +767,6 @@ def test_no_error(lambda_client, test_environment):
771767
assert _get_span_attr(attrs, SPANDATA.AWS_LOG_STREAM_NAMES) == [
772768
LATEST_FUNCTION_VERSION
773769
]
774-
assert _get_span_attr(attrs, SPANDATA.MESSAGING_BATCH_MESSAGE_COUNT) == 1
775770

776771

777772
def test_error(lambda_client, test_environment):
@@ -825,7 +820,6 @@ def test_error(lambda_client, test_environment):
825820
assert _get_span_attr(attrs, SPANDATA.AWS_LOG_STREAM_NAMES) == [
826821
LATEST_FUNCTION_VERSION
827822
]
828-
assert _get_span_attr(attrs, SPANDATA.MESSAGING_BATCH_MESSAGE_COUNT) == 1
829823

830824

831825
def test_trace_continuation(lambda_client, test_environment):

0 commit comments

Comments
 (0)