Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracer): [SVLS-5263] S3 CompleteMultipartUpload span pointers #10768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions ddtrace/_trace/utils_botocore/span_pointers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def _extract_span_pointers_for_s3_response(
request_parameters: Dict[str, Any],
response: Dict[str, Any],
) -> List[_SpanPointerDescription]:
if operation_name == "PutObject":
if operation_name in ("PutObject", "CompleteMultipartUpload"):
return _extract_span_pointers_for_s3_response_with_helper(
operation_name,
_AWSS3ObjectHashingProperties.for_put_object,
_AWSS3ObjectHashingProperties.for_put_object_or_complete_multipart_upload,
request_parameters,
response,
)
Expand All @@ -55,7 +55,12 @@ class _AWSS3ObjectHashingProperties(NamedTuple):
etag: str

@staticmethod
def for_put_object(request_parameters: Dict[str, Any], response: Dict[str, Any]) -> "_AWSS3ObjectHashingProperties":
def for_put_object_or_complete_multipart_upload(
request_parameters: Dict[str, Any], response: Dict[str, Any]
) -> "_AWSS3ObjectHashingProperties":
# Endpoint References:
# https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
# https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html
return _AWSS3ObjectHashingProperties(
bucket=request_parameters["Bucket"],
key=request_parameters["Key"],
Expand All @@ -66,6 +71,8 @@ def for_put_object(request_parameters: Dict[str, Any], response: Dict[str, Any])
def for_copy_object(
request_parameters: Dict[str, Any], response: Dict[str, Any]
) -> "_AWSS3ObjectHashingProperties":
# Endpoint References:
# https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html
return _AWSS3ObjectHashingProperties(
bucket=request_parameters["Bucket"],
key=request_parameters["Key"],
Expand All @@ -79,16 +86,13 @@ def _extract_span_pointers_for_s3_response_with_helper(
request_parameters: Dict[str, Any],
response: Dict[str, Any],
) -> List[_SpanPointerDescription]:
# Endpoint Reference:
# https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html

try:
hashing_properties = extractor(request_parameters, response)
bucket = hashing_properties.bucket
key = hashing_properties.key
etag = hashing_properties.etag

# The ETag is surrounded by double quotes for some reason.
# The ETag is surrounded by double quotes for some reason sometimes.
if etag.startswith('"') and etag.endswith('"'):
etag = etag[1:-1]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
botocore: Adds span pointers for successful S3 CompleteMultipartUpload spans.
43 changes: 43 additions & 0 deletions tests/tracer/utils_botocore/test_span_pointers.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,49 @@ class PointersCase(NamedTuple):
],
expected_warning_regex=None,
),
PointersCase(
name="s3.CompleteMultipartUpload",
endpoint_name="s3",
operation_name="CompleteMultipartUpload",
request_parameters={
"Bucket": "some-bucket",
"Key": "some-key.data",
},
response={
"ETag": "ab12ef34",
},
expected_pointers=[
_SpanPointerDescription(
pointer_kind="aws.s3.object",
pointer_direction=_SpanPointerDirection.DOWNSTREAM,
pointer_hash="e721375466d4116ab551213fdea08413",
extra_attributes={},
),
],
expected_warning_regex=None,
),
PointersCase(
name="s3.CompleteMultipartUpload with double quoted ETag",
endpoint_name="s3",
operation_name="CompleteMultipartUpload",
request_parameters={
"Bucket": "some-bucket",
"Key": "some-key.data",
},
response={
# the ETag can be surrounded by double quotes
"ETag": '"ab12ef34"',
},
expected_pointers=[
_SpanPointerDescription(
pointer_kind="aws.s3.object",
pointer_direction=_SpanPointerDirection.DOWNSTREAM,
pointer_hash="e721375466d4116ab551213fdea08413",
extra_attributes={},
),
],
expected_warning_regex=None,
),
],
ids=lambda case: case.name,
)
Expand Down
Loading