Skip to content

Commit

Permalink
Start making snapshots for botocore tests
Browse files Browse the repository at this point in the history
Can't easily see the tags without
  • Loading branch information
bouwkast committed Aug 28, 2024
1 parent 6147197 commit 12f1e5e
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions tests/contrib/botocore/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_patch_submodules(self):
assert spans

@mock_ec2
@pytest.mark.snapshot
def test_traced_client(self):
ec2 = self.session.create_client("ec2", region_name="us-west-2")
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(ec2)
Expand Down Expand Up @@ -229,6 +230,7 @@ def test_schematized_unspecified_service_ec2_call_v1(self):
assert span.name == "aws.ec2.request"

@mock_ec2
@pytest.mark.snapshot
def test_traced_client_analytics(self):
with self.override_config("botocore", dict(analytics_enabled=True, analytics_sample_rate=0.5)):
ec2 = self.session.create_client("ec2", region_name="us-west-2")
Expand Down Expand Up @@ -279,6 +281,7 @@ def test_dynamodb_put_get(self):
assert span.resource == "botocore.parsers.parse"

@mock_s3
@pytest.mark.snapshot
def test_s3_client(self):
s3 = self.session.create_client("s3", region_name="us-west-2")
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(s3)
Expand Down Expand Up @@ -310,6 +313,7 @@ def test_s3_client(self):
assert span.resource == "s3.listobjects"

@mock_s3
@pytest.mark.snapshot
def test_s3_head_404_default(self):
"""
By default we do not attach exception information to s3 HeadObject
Expand Down Expand Up @@ -338,6 +342,7 @@ def test_s3_head_404_default(self):
assert head_object.get_tag(t) is None

@mock_s3
@pytest.mark.snapshot
def test_s3_head_404_as_errors(self):
"""
When add 404 as a error status for "s3.headobject" operation
Expand Down Expand Up @@ -401,12 +406,14 @@ def _test_s3_put(self):
return spans[1]

@mock_s3
@pytest.mark.snapshot
def test_s3_put(self):
span = self._test_s3_put()
assert span.get_tag("aws.s3.bucket_name") == "mybucket"
assert span.get_tag("bucketname") == "mybucket"

@mock_s3
@pytest.mark.snapshot
def test_s3_put_no_params(self):
with self.override_config("botocore", dict(tag_no_params=True)):
span = self._test_s3_put()
Expand All @@ -418,6 +425,7 @@ def test_s3_put_no_params(self):
assert span.get_tag("component") == "botocore"

@mock_s3
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_BOTOCORE_SERVICE="botocore"))
def test_service_name_override(self):
s3 = self.session.create_client("s3", region_name="us-west-2")
Expand Down Expand Up @@ -449,6 +457,7 @@ def test_service_name_override(self):
assert span.service == "boto-service.s3", "Expected 'boto-service.s3' but got {}".format(span.service)

@mock_s3
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_SERVICE="mysvc"))
def test_schematized_s3_client_default(self):
s3 = self.session.create_client("s3", region_name="us-west-2")
Expand All @@ -463,6 +472,7 @@ def test_schematized_s3_client_default(self):
assert span.name == "s3.command"

@mock_s3
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_SERVICE="mysvc", DD_TRACE_SPAN_ATTRIBUTE_SCHEMA="v0"))
def test_schematized_s3_client_v0(self):
s3 = self.session.create_client("s3", region_name="us-west-2")
Expand Down Expand Up @@ -553,6 +563,7 @@ def _test_sqs_client(self):
return span

@mock_sqs
@pytest.mark.snapshot
def test_sqs_client(self):
span = self._test_sqs_client()
assert span.get_tag("aws.sqs.queue_name") == "Test"
Expand All @@ -562,6 +573,7 @@ def test_sqs_client(self):
assert span.get_tag("component") == "botocore"

@mock_sqs
@pytest.mark.snapshot
def test_sqs_client_no_params(self):
with self.override_config("botocore", dict(tag_no_params=True)):
span = self._test_sqs_client()
Expand All @@ -570,6 +582,7 @@ def test_sqs_client_no_params(self):
assert span.get_tag("params.MessageBody") is None

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_non_url_queue(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)

Expand All @@ -582,6 +595,7 @@ def test_sqs_send_message_non_url_queue(self):
assert span.resource == "sqs.sendmessage"

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_distributed_tracing_off(self):
with self.override_config("botocore", dict(distributed_tracing=False)):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
Expand Down Expand Up @@ -612,6 +626,7 @@ def test_sqs_send_message_distributed_tracing_off(self):
assert trace_in_message is False

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_distributed_tracing_on(self):
with self.override_config("botocore", dict(distributed_tracing=True, propagation_enabled=True)):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
Expand Down Expand Up @@ -652,6 +667,7 @@ def test_distributed_tracing_sns_to_sqs_works(self):
# DEV: We want to mock time to ensure we only create a single bucket
self._test_distributed_tracing_sns_to_sqs(False)

@pytest.mark.snapshot
@mock.patch.object(sys.modules["ddtrace.contrib.internal.botocore.services.sqs"], "_encode_data")
def test_distributed_tracing_sns_to_sqs_raw_delivery(self, mock_encode):
"""
Expand All @@ -669,6 +685,7 @@ def _moto_compatible_encode(trace_data):

@mock_sns
@mock_sqs
@pytest.mark.snapshot
def _test_distributed_tracing_sns_to_sqs(self, raw_message_delivery):
with self.override_config("botocore", dict(distributed_tracing=True, propagation_enabled=True)):
with mock.patch("time.time") as mt:
Expand Down Expand Up @@ -730,6 +747,7 @@ def _test_distributed_tracing_sns_to_sqs(self, raw_message_delivery):
assert consume_span.trace_id == publish_span.trace_id

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_trace_injection_with_max_message_attributes(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
message_attributes = {
Expand Down Expand Up @@ -773,6 +791,7 @@ def test_sqs_send_message_trace_injection_with_max_message_attributes(self):
assert trace_in_message is False

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_batch_trace_injection_with_no_message_attributes(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
entries = [
Expand Down Expand Up @@ -808,6 +827,7 @@ def test_sqs_send_message_batch_trace_injection_with_no_message_attributes(self)
assert trace_data_in_message[HTTP_HEADER_PARENT_ID] == str(span.span_id)

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_batch_trace_injection_with_message_attributes(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
entries = [
Expand Down Expand Up @@ -855,6 +875,7 @@ def test_sqs_send_message_batch_trace_injection_with_message_attributes(self):
assert trace_data_in_message[HTTP_HEADER_PARENT_ID] == str(span.span_id)

@mock_sqs
@pytest.mark.snapshot
def test_sqs_send_message_batch_trace_injection_with_max_message_attributes(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)
entries = [
Expand Down Expand Up @@ -901,6 +922,7 @@ def test_sqs_send_message_batch_trace_injection_with_max_message_attributes(self
assert trace_in_message is False

@mock_sqs
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_SERVICE="mysvc"))
def test_schematized_sqs_client_default(self):
Pin.get_from(self.sqs_client).clone(tracer=self.tracer).onto(self.sqs_client)
Expand Down Expand Up @@ -1046,11 +1068,9 @@ def test_stepfunctions_send_start_execution_trace_injection(self):
roleArn="arn:aws:iam::012345678901:role/DummyRole",
)
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(sf)
start_execution_dict = {
"stateMachineArn": "arn:aws:states:us-west-2:000000000000:stateMachine:lincoln",
"input": '{"baz": 1}',
}
sf.start_execution(**start_execution_dict)
sf.start_execution(
stateMachineArn="arn:aws:states:us-west-2:000000000000:stateMachine:lincoln", input='{"baz":1}'
)
# I've tried to find a way to make Moto show me the input to the execution, but can't get that to work.
spans = self.get_spans()
assert spans
Expand Down Expand Up @@ -1123,6 +1143,7 @@ def _test_kinesis_client(self):
return span

@mock_kinesis
@pytest.mark.snapshot
def test_kinesis_client_all_params_tagged(self):
with self.override_config("botocore", dict(tag_no_params=False)):
span = self._test_kinesis_client()
Expand All @@ -1131,12 +1152,14 @@ def test_kinesis_client_all_params_tagged(self):
assert span.get_tag("streamname") == "test"

@mock_kinesis
@pytest.mark.snapshot
def test_kinesis_client(self):
span = self._test_kinesis_client()
assert span.get_tag("aws.kinesis.stream_name") == "test"
assert span.get_tag("streamname") == "test"

@mock_kinesis
@pytest.mark.snapshot
def test_kinesis_client_no_params(self):
with self.override_config("botocore", dict(tag_no_params=True)):
span = self._test_kinesis_client()
Expand All @@ -1145,6 +1168,7 @@ def test_kinesis_client_no_params(self):
assert span.get_tag("params.Records") is None

@mock_kinesis
@pytest.mark.snapshot
def test_kinesis_client_all_params(self):
with self.override_config("botocore", dict(tag_no_params=True)):
span = self._test_kinesis_client()
Expand All @@ -1153,6 +1177,7 @@ def test_kinesis_client_all_params(self):
assert span.get_tag("params.MessageBody") is None

@mock_kinesis
@pytest.mark.snapshot
def test_kinesis_distributed_tracing_on(self):
with self.override_config("botocore", dict(distributed_tracing=True, propagation_enabled=True)):
# dict -> json string
Expand All @@ -1173,6 +1198,7 @@ def test_kinesis_distributed_tracing_on(self):
assert consume_span.trace_id == produce_span.trace_id

@mock_kinesis
@pytest.mark.snapshot
def test_unpatch(self):
kinesis = self.session.create_client("kinesis", region_name="us-east-1")
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(kinesis)
Expand All @@ -1184,6 +1210,7 @@ def test_unpatch(self):
assert not spans, spans

@mock_sqs
@pytest.mark.snapshot
def test_double_patch(self):
Pin(service=self.TEST_SERVICE, tracer=self.tracer).onto(self.sqs_client)

Expand Down Expand Up @@ -1218,6 +1245,7 @@ def _moto_compatible_encode(trace_data):

@mock_sns
@mock_sqs
@pytest.mark.snapshot
def _test_data_streams_sns_to_sqs(self, use_raw_delivery):
# DEV: We want to mock time to ensure we only create a single bucket
with mock.patch("time.time") as mt, mock.patch(
Expand Down Expand Up @@ -1310,6 +1338,7 @@ def _test_data_streams_sns_to_sqs(self, use_raw_delivery):
)

@mock_sqs
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_DATA_STREAMS_ENABLED="True"))
def test_data_streams_sqs(self):
# DEV: We want to mock time to ensure we only create a single bucket
Expand Down Expand Up @@ -1369,6 +1398,7 @@ def test_data_streams_sqs(self):
)

@mock_sqs
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_DATA_STREAMS_ENABLED="True"))
def test_data_streams_sqs_batch(self):
# DEV: We want to mock time to ensure we only create a single bucket
Expand Down Expand Up @@ -1447,6 +1477,7 @@ def test_data_streams_sqs_header_information(self):
assert "_datadog" in response["Messages"][0]["MessageAttributes"]

@mock_sqs
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_DATA_STREAMS_ENABLED="True"))
def test_data_streams_sqs_no_header(self):
# DEV: We want to mock time to ensure we only create a single bucket
Expand Down Expand Up @@ -1491,6 +1522,7 @@ def test_data_streams_sqs_no_header(self):
assert first[("direction:in,topic:Test,type:sqs", 3569019635468821892, 0)].edge_latency.count >= 1
assert first[("direction:in,topic:Test,type:sqs", 3569019635468821892, 0)].payload_size.count == 1

@pytest.mark.snapshot
@mock_lambda
def test_lambda_client(self):
# DEV: No lambda params tagged so we only check no ClientContext
Expand All @@ -1515,6 +1547,7 @@ def test_lambda_client(self):
assert span.get_tag("params.ClientContext") is None

@mock_lambda
@pytest.mark.snapshot
def test_lambda_invoke_distributed_tracing_off(self):
with self.override_config("botocore", dict(distributed_tracing=False)):
lamb = self.session.create_client("lambda", region_name="us-west-2", endpoint_url="http://localhost:4566")
Expand Down Expand Up @@ -1556,6 +1589,7 @@ def test_lambda_invoke_distributed_tracing_off(self):
lamb.delete_function(FunctionName="ironmaiden")

@mock_lambda
@pytest.mark.snapshot
def test_lambda_invoke_bad_context_client(self):
lamb = self.session.create_client("lambda", region_name="us-west-2", endpoint_url="http://localhost:4566")
lamb.create_function(
Expand Down Expand Up @@ -1592,6 +1626,7 @@ def test_lambda_invoke_bad_context_client(self):
lamb.delete_function(FunctionName="black-sabbath")

@mock_lambda
@pytest.mark.snapshot
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_SERVICE="mysvc"))
def test_schematized_lambda_client_default(self):
# DEV: No lambda params tagged so we only check no ClientContext
Expand Down

0 comments on commit 12f1e5e

Please sign in to comment.