|
| 1 | +import copy |
1 | 2 | from http.server import BaseHTTPRequestHandler, HTTPServer |
2 | 3 | from threading import Thread |
3 | 4 | from urllib.parse import parse_qs, urlparse |
4 | 5 |
|
5 | 6 | import boto3 |
| 7 | +import pytest |
6 | 8 | from botocore.auth import SIGNED_HEADERS_BLACKLIST |
7 | 9 | from botocore.config import Config |
| 10 | +from botocore.stub import Stubber |
8 | 11 |
|
9 | 12 | import sentry_sdk |
10 | 13 | from sentry_sdk.integrations.boto3 import Boto3Integration |
|
13 | 16 | _get_aws_sigv4_signed_headers_from_authorization_header, |
14 | 17 | _get_aws_sigv4_signed_headers_from_url_query_string, |
15 | 18 | ) |
| 19 | +from tests.integrations.boto3.helpers import capture_spans_by_op |
16 | 20 |
|
17 | 21 | # botocore 1.43.115+ never signs `baggage`. |
18 | 22 | BOTOCORE_SIGNS_BAGGAGE = "baggage" not in SIGNED_HEADERS_BLACKLIST |
@@ -207,3 +211,65 @@ def test_presigned_urls_do_not_require_sentry_headers(sentry_init): |
207 | 211 | # presigned URL query must not contain `sentry-trace` or `baggage`. |
208 | 212 | assert "sentry-trace" not in url |
209 | 213 | assert "baggage" not in url |
| 214 | + |
| 215 | + |
| 216 | +@pytest.mark.parametrize( |
| 217 | + "service,method,params,response", |
| 218 | + [ |
| 219 | + pytest.param( |
| 220 | + "sqs", |
| 221 | + "send_message", |
| 222 | + { |
| 223 | + "QueueUrl": "https://sqs.eu-north-1.amazonaws.com/123456789012/orders", |
| 224 | + "MessageBody": "hi", |
| 225 | + }, |
| 226 | + {"MessageId": "1"}, |
| 227 | + id="sqs-send", |
| 228 | + ), |
| 229 | + pytest.param( |
| 230 | + "sqs", |
| 231 | + "receive_message", |
| 232 | + {"QueueUrl": "https://sqs.eu-north-1.amazonaws.com/123456789012/orders"}, |
| 233 | + {}, |
| 234 | + id="sqs-receive", |
| 235 | + ), |
| 236 | + pytest.param( |
| 237 | + "sns", |
| 238 | + "publish", |
| 239 | + {"TopicArn": "arn:aws:sns:eu-north-1:123456789012:alerts", "Message": "hi"}, |
| 240 | + {"MessageId": "1"}, |
| 241 | + id="sns-publish", |
| 242 | + ), |
| 243 | + pytest.param( |
| 244 | + "lambda", |
| 245 | + "invoke", |
| 246 | + {"FunctionName": "billing"}, |
| 247 | + {"StatusCode": 200}, |
| 248 | + id="lambda-invoke", |
| 249 | + ), |
| 250 | + ], |
| 251 | +) |
| 252 | +def test_propagate_traces_disabled( |
| 253 | + sentry_init, capture_items, service, method, params, response |
| 254 | +): |
| 255 | + """`propagate_traces=False` sends the caller's params unchanged.""" |
| 256 | + sentry_init( |
| 257 | + traces_sample_rate=1.0, |
| 258 | + integrations=[Boto3Integration(propagate_traces=False)], |
| 259 | + ) |
| 260 | + client = boto3.client( # type: ignore[attr-defined] |
| 261 | + service, |
| 262 | + region_name="eu-north-1", |
| 263 | + aws_access_key_id="-", |
| 264 | + aws_secret_access_key="-", |
| 265 | + ) |
| 266 | + |
| 267 | + with Stubber(client) as stubber: |
| 268 | + # the stubber fails the call when the sent params differ from these. |
| 269 | + stubber.add_response(method, response, copy.deepcopy(params)) |
| 270 | + spans = capture_spans_by_op( |
| 271 | + lambda: getattr(client, method)(**params), capture_items |
| 272 | + ) |
| 273 | + |
| 274 | + # the call is still instrumented. |
| 275 | + assert sum(map(len, spans.values())) == 1 |
0 commit comments