Skip to content

Commit

Permalink
feat(tracer): [SVLS-5263] S3 CompleteMultipartUpload pointers (#10768)
Browse files Browse the repository at this point in the history
Span Pointers for the AWS S3 CompleteMultipartUpload API call.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

---------

Co-authored-by: Zachary Groves <[email protected]>
  • Loading branch information
2 people authored and mabdinur committed Sep 25, 2024
1 parent 8d645b3 commit b14a256
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
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

0 comments on commit b14a256

Please sign in to comment.