Skip to content

Commit 87e6623

Browse files
fix(botocore): allow non-url SQS "queue urls" [backport 1.14] (#6106)
Backport 24e98d0 from #6102 to 1.14. This change fixes #6053, introduced in #5413, by avoiding attempts to parse non-URL `QueueUrl` attributes from botocore SQS payloads as URLs. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](../docs/contributing.rst#release-branch-maintenance)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](../docs/contributing.rst#release-branch-maintenance) Co-authored-by: Emmett Butler <[email protected]>
1 parent 4399b3f commit 87e6623

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

ddtrace/ext/aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _add_api_param_span_tags(span, endpoint_name, params):
9191
elif endpoint_name == "sqs":
9292
queue_name = params.get("QueueName", "")
9393
queue_url = params.get("QueueUrl")
94-
if queue_url:
94+
if queue_url and (queue_url.startswith("sqs:") or queue_url.startswith("http")):
9595
# example queue_url: https://sqs.sa-east-1.amazonaws.com/12345678/queuename
9696
queue_name = queue_url.split("/")[-1]
9797
aws_account = queue_url.split("/")[-2]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
botocore: This fix resolves an issue where ddtrace attempted to parse as URLs SQS QueueUrl attributes that
5+
were not well-formed URLs.

tests/contrib/botocore/test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,22 @@ def test_sqs_send_message_trace_injection_with_no_message_attributes(self):
384384
assert trace_data_in_message[HTTP_HEADER_TRACE_ID] == str(span.trace_id)
385385
assert trace_data_in_message[HTTP_HEADER_PARENT_ID] == str(span.span_id)
386386

387+
@mock_sqs
388+
def test_sqs_send_message_non_url_queue(self):
389+
with self.override_config("botocore", dict(tag_all_params=True)):
390+
sqs = self.session.create_client("sqs", region_name="us-east-1", endpoint_url="http://localhost:4566")
391+
queue = sqs.create_queue(QueueName="test")
392+
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(sqs)
393+
394+
sqs.send_message(QueueUrl="test", MessageBody="world")
395+
spans = self.get_spans()
396+
assert spans
397+
span = spans[0]
398+
assert len(spans) == 1
399+
assert span.get_tag("aws.operation") == "SendMessage"
400+
assert span.resource == "sqs.sendmessage"
401+
sqs.delete_queue(QueueUrl=queue["QueueUrl"])
402+
387403
@mock_sqs
388404
def test_sqs_send_message_distributed_tracing_off(self):
389405
# DEV: Only test deprecated behavior because this inspect span tags for MessageAttributes

0 commit comments

Comments
 (0)