|
2 | 2 | from datetime import datetime |
3 | 3 | from typing import TYPE_CHECKING |
4 | 4 |
|
5 | | -from sentry_sdk.consts import SPANDATA |
| 5 | +from sentry_sdk.consts import OP, SPANDATA |
6 | 6 | from sentry_sdk.integrations.boto3._services.base import _ServiceExtension |
7 | 7 | from sentry_sdk.integrations.boto3._utils import ( |
8 | 8 | _extract_attributes, |
|
11 | 11 | from sentry_sdk.utils import capture_internal_exceptions |
12 | 12 |
|
13 | 13 | if TYPE_CHECKING: |
14 | | - from typing import Any, Sequence |
| 14 | + from typing import Any, Dict, Optional, Sequence |
15 | 15 |
|
16 | 16 | from sentry_sdk._types import Attributes |
17 | 17 | from sentry_sdk.integrations.boto3._context import AwsCallContext |
18 | 18 | from sentry_sdk.integrations.boto3._utils import ( |
19 | 19 | _AttributeSpec, |
20 | 20 | ) |
21 | 21 |
|
| 22 | +# s3 object apis get `object.*` ops, every other s3 api, e.g. `ListBuckets`, keeps the default `rpc`. |
| 23 | +# https://github.com/getsentry/sentry-conventions/blob/main/model/op/object.json |
| 24 | +_OBJECT_OPS: "Dict[str, str]" = { |
| 25 | + "GetObject": OP.OBJECT_GET, |
| 26 | + "HeadObject": OP.OBJECT_HEAD, |
| 27 | + # `GetObjectAttributes` combines `HeadObject` and `ListParts`. |
| 28 | + # https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAttributes.html |
| 29 | + "GetObjectAttributes": OP.OBJECT_HEAD, |
| 30 | + "PutObject": OP.OBJECT_PUT, |
| 31 | + "CopyObject": OP.OBJECT_COPY, |
| 32 | + "DeleteObject": OP.OBJECT_DELETE, |
| 33 | + "DeleteObjects": OP.OBJECT_DELETE, |
| 34 | + "ListObjects": OP.OBJECT_LIST, |
| 35 | + "ListObjectsV2": OP.OBJECT_LIST, |
| 36 | + "ListObjectVersions": OP.OBJECT_LIST, |
| 37 | + "UploadPart": OP.OBJECT_UPLOAD_PART, |
| 38 | + "UploadPartCopy": OP.OBJECT_UPLOAD_PART, |
| 39 | + "CreateMultipartUpload": OP.OBJECT_MULTIPART_UPLOAD_CREATE, |
| 40 | + "CompleteMultipartUpload": OP.OBJECT_MULTIPART_UPLOAD_COMPLETE, |
| 41 | + "AbortMultipartUpload": OP.OBJECT_MULTIPART_UPLOAD_ABORT, |
| 42 | +} |
| 43 | + |
22 | 44 | # maps s3 operations to the response field that contains the complete file size. |
23 | 45 | _RESPONSE_FILE_SIZE_FIELDS = { |
24 | 46 | "GetObjectAttributes": "ObjectSize", |
|
36 | 58 | class _S3Extension(_ServiceExtension): |
37 | 59 | __slots__ = () |
38 | 60 |
|
| 61 | + def get_span_op(self, ctx: "AwsCallContext") -> "Optional[str]": |
| 62 | + return _OBJECT_OPS.get(ctx.operation_name) |
| 63 | + |
39 | 64 | def get_request_attributes(self, ctx: "AwsCallContext") -> "Attributes": |
40 | 65 | attributes: "Attributes" = _extract_attributes(ctx.params, _REQUEST_ATTRIBUTES) |
41 | 66 | with capture_internal_exceptions(): |
|
0 commit comments